amplify-codegen
amplify-codegen copied to clipboard
Cannot use 'in' operator to search for 'name' in amplify codegen [UPDATE]
Before opening, please confirm:
- [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- [X] I have searched for duplicate or closed issues.
- [X] I have read the guide for submitting bug reports.
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
How did you install the Amplify CLI?
npm
If applicable, what version of Node.js are you using?
16.19.0
Amplify CLI Version
12.10.1 / 10.8.1
What operating system are you using?
Mac
Amplify Codegen Command
codegen
Describe the bug
Hello, everyone.
I checked this issue that was opened recently but even with the suggested fix for me it did not work.
I tried to upgrade the CLI to the 12.10.1 but still got the same error.
Cannot use 'in' operator to search for 'name' in amplify codegen
I tried also to downgrade to the 10.8.1
, the error changed to:
Could not parse graphql operations in src/graphql/customQueries.ts
Failed on : amplify codegen
Then, since the second error was more explicit with the word parse
I started to look what could be possibly the cause, and I noticed that my customQueries.ts
had a multiline comment at the top of the file. I removed the comment and codegen worked.
So it seems that the parser was having a bad time parsing the file because I suspect that the /* */
was expecting a graphql statement and instead it was just a comment.
I hope to help someone who will encountered the same issue. If i inspected correctly the code correctly the parsing is done by graphql so It is not an issue releated to codegen itself.
Expected behavior
Maybe it should be said explicitly that the file should have no comments at all.
Reproduction steps
- create a file with custom queries inside the
/graphql
folder - write some
/*multiline*/
comment at the start of the file - write some graphql queries.
- run amplify codegen to generate the types.
- the error should appear.
- remove the multiline comment at the top of the file
- errors should disappear and codegen should run succefully
GraphQL schema(s)
# Put schemas below this line
Log output
# Put your logs below this line
Additional information
No response
To confirm, you have added src/graphql/customQueries.ts
as an excludes
pattern to your .graphqlconfig.yml
file?
Hi @dpilch yes, the issue persisted even when adding the file as an excludes pattern
I wasn't able to reproduce this. Can you share your .graphqlconfig.yml
and GraphQL schema?
If you do not want to share your schema publicly you can use amplify diagnose --send-report
and share the identifier here.
https://docs.amplify.aws/javascript/tools/cli/reference/diagnose/
@dpilch I can't share the schema publicly, but here's the identifier 80c220235b1ef700abc26a8a23d3bd2f
Below the .graphqlconfig.yml
projects:
todolistdemo:
schemaPath: src/graphql/schema.json
includes:
- src/graphql/**/*.ts
excludes:
- ./amplify/**
extensions:
amplify:
codeGenTarget: typescript
generatedFileName: src/API.ts
typenameIntrospection: false
docsFilePath: src/graphql
maxDepth: 9
extensions:
amplify:
version: 3
I wasn't able to reproduce with any multiline comment, but I could reproduce if the comment included backticks (`some text`
). In fact, any usage of backticks would result in the error.
Did your comment include backticks?
@dpilch I've checked the commit, the comment definitely had a pair of backticks inside. So that was the issue then.