Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/docs-codegen-anonymous-operations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@shopify/api-codegen-preset': patch
---

Document that anonymous GraphQL operations are silently ignored during type
generation. Only named queries and mutations produce types; a project
containing only anonymous operations generates an empty `*.generated.d.ts`
without an error. (README-only change.)
23 changes: 22 additions & 1 deletion packages/api-clients/api-codegen-preset/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,28 @@ pnpm graphql-codegen --project=UIExtensions
> [!NOTE]
> Codegen will fail if it can't find any documents to parse.
> To fix that, either create a query or set the [`ignoreNoDocuments` option](https://the-guild.dev/graphql/codegen/docs/config-reference/codegen-config#configuration-options) to `true`.
> Queries and mutations must have a name for the parsing to work.

> [!IMPORTANT]
> Your queries and mutations **must be named** for types to be generated.
> Anonymous operations (e.g. `query { ... }` with no operation name) are
> counted as documents, so they won't trigger the "no documents" error above,
> but they are silently skipped during generation. A project containing only
> anonymous operations therefore produces an empty `*.generated.d.ts` file with
> no warning. Give every operation a name to have its types generated:
>
> ```ts
> // Not generated — anonymous operation:
> `#graphql
> query {
> products(first: 5) { edges { node { id } } }
> }`;
>
> // Generated — named operation:
> `#graphql
> query getProducts {
> products(first: 5) { edges { node { id } } }
> }`;
> ```

Once the script parses your operations, you can mark any operations for parsing by adding the `#graphql` tag to the string.
For example:
Expand Down
Loading