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

[api-codegen-preset] Types for anonymous operations are not generated / anonymous operations are ignored #1997

Open
jakubnoga opened this issue Jan 21, 2025 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@jakubnoga
Copy link

Overview/summary

In retrospective this seems like a reasonable behavior, but might be overlooked by other people as well and cost them some time and nerves. I think it's at least worth mentioning in the docs that anonymous operations are counted as documents but omitted / ignored in generation phase.
Having only anonymous queries in the project will not trigger any errors but will result in empty output *.generated.d.ts

Consider such an example straight from Shopify docs (https://shopify.dev/docs/api/admin-graphql/2024-10/queries/customers?language=Node.js):

const client = new shopify.clients.Graphql({session});
const data = await client.query({
  data: `query {
    customers(first: 5, query: "country:canada") {
      edges {
        node {
          id
        }
      }
    }
  }`,
});

apart from annotating with magic #graphql tag it also needs a name. So to get graphql-codegen going one will have to change above code to something like:

const client = new shopify.clients.Graphql({session});
const data = await client.query({
  data: `
  #graphql
  query customers {
    customers(first: 5, query: "country:canada") {
      edges {
        node {
          id
        }
      }
    }
  }`,
});

There's literally only a single mention of this fact in the graphql-codegen docs and it's in React / Vue chapter (I only found it because I knew what I was looking for): https://the-guild.dev/graphql/codegen/docs/guides/react-vue#writing-graphql-queries

Image

Respective "Vanilla TypeScript" chapter does not contain such a warning.

@lizkenyon
Copy link
Contributor

Hi there 👋

Thanks for the feedback. I believe the best place for us to update the docs is probably here.

If you have any other suggestions, that would have helped you discover them faster please let me know.

@lizkenyon lizkenyon added the documentation Improvements or additions to documentation label Jan 21, 2025
@jakubnoga
Copy link
Author

Hi 👋

this also looks like a good place to me, this is where I learned about the graphql-codegen and it will be a nice addition to otherwise complete tutorial.

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

No branches or pull requests

2 participants