aws-amplify / aws-amplify/amplify-codegen
Escaping double quotes in the @sql directive statement
- Dominant language
- TypeScript
- Stars
- 59
- Forks
- 64
- PR merge metrics
- No merged PRs in 30d
Description
### How did you install the Amplify CLI?
npm
### If applicable, what version of Node.js are you using?
v20.8.0
### Amplify CLI Version
12.10.3
### What operating system are you using?
WSL2
### Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
Followed this guide to manually create GraphQL api through CDK
https://docs.amplify.aws/javascript/build-a-backend/graphqlapi/connect-api-to-existing-database/
### Describe the bug
I ran ```npx @aws-amplify/cli api generate-schema --engine-type postgres ``` command to auto-generate GraphQL schema in ```schema.sql.graphql```
This generated below mentioned type
```graphql
type DBrand
@refersTo(name: "")
@model
@auth(rules: [{ allow: public }]) {
brandId: ID!
@refersTo(name: "brand_id")
@default(value: "gen_random_uuid()")
@primaryKey
brandCode: String @refersTo(name: "brand_code")
brandName: String! @refersTo(name: "brand_name")
brandCategory: String @refersTo(name: "brand_category")
}
```
I added below mentioned custom query in the same file ```schema.sql.graphql```
```graphql
type Query {
getDBrandByUsername(userName: String!): [DBrand]
@sql(reference: "getBrandByUsername")
@auth(rules: [{ allow: public }])
}
```
When I call the query using graphQl client in front-end, it throws the following error
```
"Cannot return null for non-nullable type: 'ID' within parent 'DBrand' (/getDBrandByUsername[0]/brandId)"
```
However, when I renamed the fields(removed @refersTo mapping) to original DB filed names, it works.
Here is the additional change I made to test this
Added a new type DBrand2
```graphql
type DBrand2 @model @auth(rules: [{ allow: public }]) {
brand_id: ID! @default(value: "gen_random_uuid()") @primaryKey
brand_code: String
brand_name: String!
brand_category: String
}
```
Added duplicate of the original query but returning DBrand2 type instead
```graphql
type Query {
getDBrand2ByUsername(userName: String!): [DBrand2]
@sql(reference: "getBrandByUsername")
@auth(rules: [{ allow: public }])
getDBrandByUsername(userName: String!): [DBrand]
@sql(reference: "getBrandByUsername")
@auth(rules: [{ allow: public }])
}
```
### Expected behavior
Custom query results should be transformed to type generated by generate-schema command
### Reproduction steps
1. Generate graphql schema using ```npx @aws-amplify/cli api generate-schema --engine-type postgres ``` command for table that doesn't follow camel case attribute names
2. Write a custom query that returns result of generated type(should have @refersTo with renamed attribute name)
3. Call the custom query from UI using graphQL client
### Project Identifier
_No response_
### Log output
```
# Put your logs below this line
```
### Additional information
_No response_
### Before submitting, please confirm:
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.
Contributor guide
Assessment
This issue has not been assessed yet.