Shopify / shopify-app-js

MIT License
284 stars 112 forks source link

How to use TypedDocumentNode (or DocumentNode) in Shopify Admin GraphQL #753

Open ErikTheBerik opened 7 months ago

ErikTheBerik commented 7 months ago

Overview

I'm not sure if this is where I should post this or if this is already possible. But I've tried all day and I couldn't make this work. I want to have intellisense with graphql like here: "https://the-guild.dev/blog/typed-document-node".

I am using the shopify GraphqlClient from "@shopify/shopify-api/lib/clients/admin/graphql/client" and I want to run a graphql query with DocumentNode or TypedDocumentNode so I can get some intellisense. So can I do this?

In terms of having typed graphql with shopify I've only found this "https://shopify.dev/docs/api/shopify-app-remix/v2/guide-graphql-types" which uses "@shopify/api-codegen-preset" but I'd like to store my graphql queries in a .graphql file and use codegen to "compile" them (like in typed-document-node).

paulomarg commented 6 months ago

Hey, thanks for raising this. We currently don't support TypedDocumentNodes as inputs to the queries - the way our preset package works is that it will map the query string to the types, and the client will automatically load them. The main gain we have here is that we don't need to parse the query into a node at all, which means there's no impact on performance.

The downside of this is that it only works if the query is string defined as const, so that the typing sticks, but it also has no impact on production.

We can maybe look into supporting nodes as a parameter to better cover your case, but unfortunately, that is not something we'll be able to do soon as there are other things that will be a higher priority.

Hope this helps!

github-actions[bot] commented 4 months ago

We're labeling this issue as stale because there hasn't been any activity on it for 60 days. While the issue will stay open and we hope to resolve it, this helps us prioritize community requests.

You can add a comment to remove the label if it's still relevant, and we can re-evaluate it.