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

No error message when types aren't generated because of anonymous GraphQL queries #7

Closed
JagdCake opened this issue Jan 30, 2020 · 4 comments

Comments

@JagdCake
Copy link

I'm working on a TypeScript starter using gatsby-starter-default as a base. I followed the steps in this blog post to get TypeScript support, however on the last step — generating the types using this plugin — the types weren't being generated.

Running npm run develop displayed success messages:

success [gatsby-plugin-codegen] saved localSchemaFile: ./schema.json
success [gatsby-plugin-codegen] saved apollo config:
success [gatsby-plugin-codegen] types for typescript generated

Both the schema and config files showed up, but the __generated__ directories didn't.

I tried node_modules/apollo/bin/run client:codegen -c apollo.config.js --target=typescript --outputFlat gql-types.d.ts and I got an error: Apollo does not support anonymous operations, which led me to this comment. Naming the queries fixed the problem.

@daugsbi
Copy link
Owner

daugsbi commented Jan 30, 2020

Yes, all queries need a unique name (compare with apollographql/apollo-tooling#670).

I've tried to reproduce the incorrect success message. When I do not name one query it shows me the following
query_naming_apollo-codegen

Do you have any additional information or a repository to share?

@JagdCake
Copy link
Author

JagdCake commented Jan 30, 2020

git clone --branch gql-types https://github.com/JagdCake/gatsby-typescript-tailwind-starter.git. The query in src/components/seo.tsx is anonymous and when I run npm run develop there is no error, git status shows only the apollo config and schema.json.

@daugsbi
Copy link
Owner

daugsbi commented Jan 30, 2020

Thanks for the reproduction 👍
As a temporary workaround set the plugin option watch to false.

I need to check if it's possible to keep the file watchers of apollo and still be compatible with the newest version of gatsby-cli (>=2.8.28).

Please keep the issue open

@daugsbi
Copy link
Owner

daugsbi commented Mar 16, 2020

I've changed the default option watch to false. For people still wanted to use the watch mode the best solution is to set it the following way:
watch: process.env.NODE_ENV === "development" ? true : false

As a result you get the error message during build time instead of development.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants