Open chrisbonifacio opened 2 weeks ago
@chrisbonifacio I was able to get rid of the error by adding the authorization here: const testSchema = generatedSqlSchema.authorization((allow) => allow.authenticated());
but the query literally returns nothing. There is definitely data. I can query it just fine from AppSync and the Amplify console. Using the front end code above.
Hi @blipps199 ! thanks for the update. Can you check the network request that is being made from your application and share what the graphql query looks like? I'm curious to see the headers, input variables, the selection set (fields to be returned in the response), and how they compare to the AppSync console query.
@chrisbonifacio After doing a bit more digging I can query and get data back... but not from a list query. Only from get queries where I have to filter using a specific id for the record. I haven't tried a mutation yet but that will be soon.
@chrisbonifacio Here is the payload.
{"query":"query ($demographic_data_id: Int, $sortDirection: ModelSortDirection, $filter: ModelDemographic_dataFilterInput, $limit: Int, $nextToken: String) {\n listDemographic_data(\n demographic_data_id: $demographic_data_id\n sortDirection: $sortDirection\n filter: $filter\n limit: $limit\n nextToken: $nextToken\n ) {\n items {\n demographic_data_id\n user_id\n country\n state\n tribe\n height\n weight\n sex\n ethnic_group\n physical_activity_level\n smoking_history\n occupational_exposure\n previous_disease\n respiratory_medication_use\n pregnant\n }\n nextToken\n __typename\n }\n}\n","variables":{}}
When I tried to run this query through AppSync it told me sortDirection is not supported for List operations without a Sort key defined.
Once I removed that I was able to run the query. Wondering if this is what the issue is.
@chrisbonifacio Could this be from postgres not having a sortkey field?
@blipps199 I'm not sure but this sounds like a potential duplicate of this other issue I was able to reproduce:
https://github.com/aws-amplify/amplify-category-api/issues/2946
In the meantime, until we fix this bug, you should be able to use client.graphql
to perform a list
query with a custom graphql string.
If you want to generate graphql statements, you can use the following CLI command:
https://docs.amplify.aws/react/reference/cli-commands/#npx-ampx-generate-graphql-client-code
Thanks @chrisbonifacio. I was able to take my generated queries file, dupe it so I can make edits, removed sortDirection
, imported the query, and use client.graphql
to run the query. Its not nearly as clean but it works I suppose. Would you have any idea when this bug fix would be on the roadmap? I would really love to use client.models.model_name.list
.
Amplify CLI Version
N/A
Question
Keep in mind I replaced some sensitive info with placeholders.
Here is the schema(schema.ql.ts) auto generated using this
npx ampx generate schema-from-database --connection-uri-secret SQL_CONNECTION_STRING --out amplify/data/schema.sql.ts
.Here is my data/resource.ts
Here is my front end code:
I know this might be overkill but I want to provide as much as I can.
I think this might have been what you were looking for. I just posted the queries file. I used this command to generate it
npx ampx generate graphql-client-code --format graphql-codegen --statement-target typescript --out ./src/graphql/
. Not really sure how this file is then referenced...API.ts