Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use 'in' operator to search for 'name' in amplify codegen [UPDATE] #787

Open
4 tasks done
giuliobracci opened this issue Feb 14, 2024 · 6 comments
Open
4 tasks done
Labels
feature-request New feature or request

Comments

@giuliobracci
Copy link

giuliobracci commented Feb 14, 2024

Before opening, please confirm:

  • I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • 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

  1. create a file with custom queries inside the /graphql folder
  2. write some /*multiline*/ comment at the start of the file
  3. write some graphql queries.
  4. run amplify codegen to generate the types.
  5. the error should appear.
  6. remove the multiline comment at the top of the file
  7. 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

@dpilch
Copy link
Contributor

dpilch commented Feb 27, 2024

To confirm, you have added src/graphql/customQueries.ts as an excludes pattern to your .graphqlconfig.yml file?

@giuliobracci
Copy link
Author

Hi @dpilch yes, the issue persisted even when adding the file as an excludes pattern

@dpilch
Copy link
Contributor

dpilch commented Feb 27, 2024

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/

@giuliobracci
Copy link
Author

@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

@dpilch
Copy link
Contributor

dpilch commented Feb 27, 2024

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?

@giuliobracci
Copy link
Author

@dpilch I've checked the commit, the comment definitely had a pair of backticks inside. So that was the issue then.

@dpilch dpilch added feature-request New feature or request and removed pending-response labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants