On this page

@graphql-codegen/client-preset

Changelog for @graphql-codegen/client-preset: every release with its changes and the pull requests behind them.

6.2.0

Minor Changes

  • #10946 a6a3348 Thanks @eddeee888! - Add skipIndexFile preset config option to client-preset to allow disabling generation of the index.ts barrel file that re-exports the other generated files. Defaults to false (unchanged behavior); set to true to skip generating index.ts, for example when your project avoids barrel files for tree-shaking or lint rule reasons.

Patch Changes

  • b545f6b Thanks @eddeee888! - Add /* eslint-disable */ to the generated index.ts barrel file, matching the other files generated by client-preset (graphql.ts, gql.ts, fragment-masking.ts), which already had it.

6.1.3

Patch Changes

  • #10918 6a3b734 Thanks @eddeee888! - Fix union and conditional directives resulting in no field types

  • Updated dependencies [6a3b734]:

    • @graphql-codegen/visitor-plugin-common@7.2.5
    • @graphql-codegen/typescript-operations@6.1.6

6.1.2

Patch Changes

  • #10916 d95d378 Thanks @eddeee888! - Revert Partial handling when conditional fragment and fragment masking are used

    This is causing all masked fields to be optional due to how function type override works.

  • Updated dependencies [d95d378]:

    • @graphql-codegen/visitor-plugin-common@7.2.4

6.1.1

Patch Changes

  • #10904 2dd1531 Thanks @eddeee888! - Fix fragment masking generation when conditional directive is used

  • Updated dependencies [2dd1531, 5a9f96c]:

    • @graphql-codegen/visitor-plugin-common@7.2.3
    • @graphql-codegen/typescript-operations@6.1.3

6.1.0

Minor Changes

Patch Changes

  • Updated dependencies [959915f, 959915f, 959915f, 959915f, 959915f, 959915f, 959915f]:
    • @graphql-codegen/add@7.1.0
    • @graphql-codegen/gql-tag-operations@6.1.0
    • @graphql-codegen/plugin-helpers@7.1.0
    • @graphql-codegen/typed-document-node@7.1.0
    • @graphql-codegen/typescript@6.1.0
    • @graphql-codegen/typescript-operations@6.1.0
    • @graphql-codegen/visitor-plugin-common@7.2.0

6.0.1

Patch Changes

6.0.0

Major Changes

  • #10496 afaace6 Thanks @eddeee888! - Fix nullable field optionality in operations

    Previously, a nullable Result field is generated as optional (marked by ? TypeScript modifier) by default. This is not correct, because generally at runtime such field can only be null, and not undefined (both missing from the object OR undefined). The only exceptions are when fields are deferred (using @defer directive) or marked as conditional (using @skip or @include).

    Now, a nullable Result field cannot be optional unless the exceptions are met. This also limits avoidOptionals to only target Variables input, since some users may want to force explicit null when providing operation variables.

  • #10496 afaace6 Thanks @eddeee888! - Conditionally generate input types and output enums into target file

  • #10496 afaace6 Thanks @eddeee888! - BREAKING CHANGE: make unknown instead of any the default custom scalar type

  • #10496 afaace6 Thanks @eddeee888! - BREAKING CHANGE: Update deps to latest, some only support ESM

    Node 20 support is dropped in this release. Node 22 comes with require() support for ESM, which means it’s easier to integrate ES modules into applications. Therefore, it is safe to start using ESM-only packages.

    If you are a user, please upgrade to Node 22. If you are a lib maintainer and see ESM vs CJS issues when running Jest tests, try using Vitest.

  • #10496 afaace6 Thanks @eddeee888! - BREAKING CHANGE: Drop Node 20 support

  • #10496 afaace6 Thanks @eddeee888! - BREAKING CHANGE: typescript plugin no longer generates Exact utility type. Instead, typescript-operations generates said utility type for every file it creates. This is because it is used only for Variables, so we only need to generate it once for every generated operation file.

  • #10496 afaace6 Thanks @eddeee888! - BREAKING CHANGE: Operation plugin and Client Preset no longer generates optional __typename for result type

    __typenam should not be in the request unless:

    • explicitly requested by the user
    • automatically injected into the request by clients, such as Apollo Clients.

    Note: Apollo Client users can still use nonOptionalTypename: true and skipTypeNameForRoot: true to ensure generated types match the runtime behaviour.

  • #10496 afaace6 Thanks @eddeee888! - BREAKING CHANGES: The default hashing algorithm is now sha256 instead of sha1. Generated sha256 format also follows the standard outlined in https://github.com/graphql/graphql-over-http/blob/52d56fb36d51c17e08a920510a23bdc2f6a720be/spec/Appendix%20A%20—%20Persisted%20Documents.md#sha256-hex-document-identifier

  • #10496 afaace6 Thanks @eddeee888! - Integrate new typescript-operations into client-preset

  • #10496 afaace6 Thanks @eddeee888! - BREAKING CHANGE: config.avoidOptionals now only supports object, inputValue, defaultValue

Patch Changes

5.3.0

Minor Changes

  • #10659 e65d303 Thanks @ikusakov2! - Add support for externalDocuments

    externalDocuments declares GraphQL documents that will be read but will not have type files generated for them. These documents are available to plugins for type resolution (e.g. fragment types), but no output files will be generated based on them. Accepts the same formats as documents.

    This config option is useful for monorepos where each project may want to generate types for its own documents, but some may need to read shared fragments from across projects.

Patch Changes

  • #10103 9a66574 Thanks @renovate! - dependencies updates:
  • Updated dependencies [9a66574, 9a66574, 9a66574, 9a66574, 9a66574, 9a66574, 9a66574, e65d303]:
    • @graphql-codegen/add@6.0.1
    • @graphql-codegen/gql-tag-operations@5.2.0
    • @graphql-codegen/plugin-helpers@6.3.0
    • @graphql-codegen/typed-document-node@6.1.8
    • @graphql-codegen/typescript@5.0.10
    • @graphql-codegen/typescript-operations@5.1.0
    • @graphql-codegen/visitor-plugin-common@6.3.0

5.2.4

Patch Changes

5.2.3

Patch Changes

  • Updated dependencies [6038634]:
    • @graphql-codegen/visitor-plugin-common@6.2.3
    • @graphql-codegen/typescript-operations@5.0.8
    • @graphql-codegen/gql-tag-operations@5.1.3
    • @graphql-codegen/typed-document-node@6.1.6
    • @graphql-codegen/typescript@5.0.8

5.2.2

Patch Changes

  • Updated dependencies [f588d91]:
    • @graphql-codegen/visitor-plugin-common@6.2.2
    • @graphql-codegen/gql-tag-operations@5.1.2
    • @graphql-codegen/typescript-operations@5.0.7
    • @graphql-codegen/typed-document-node@6.1.5
    • @graphql-codegen/typescript@5.0.7

5.2.1

Patch Changes

  • Updated dependencies [b995ed1]:
    • @graphql-codegen/visitor-plugin-common@6.2.1
    • @graphql-codegen/gql-tag-operations@5.1.1
    • @graphql-codegen/typescript-operations@5.0.6
    • @graphql-codegen/typed-document-node@6.1.4
    • @graphql-codegen/typescript@5.0.6

5.2.0

Minor Changes

Patch Changes

  • Updated dependencies [f821e8a, 9e70bcb]:
    • @graphql-codegen/visitor-plugin-common@6.2.0
    • @graphql-codegen/gql-tag-operations@5.1.0
    • @graphql-codegen/plugin-helpers@6.1.0
    • @graphql-codegen/typescript-operations@5.0.5
    • @graphql-codegen/typed-document-node@6.1.3
    • @graphql-codegen/typescript@5.0.5

5.1.3

Patch Changes

  • #10499 51a1a72 Thanks @eddeee888! - Fix nested fragment not getting correct meta field in Client Preset

  • Updated dependencies [51a1a72]:

    • @graphql-codegen/visitor-plugin-common@6.1.2
    • @graphql-codegen/gql-tag-operations@5.0.5
    • @graphql-codegen/typescript-operations@5.0.4
    • @graphql-codegen/typed-document-node@6.1.2
    • @graphql-codegen/typescript@5.0.4

5.1.2

Patch Changes

  • Updated dependencies [6715330]:
    • @graphql-codegen/visitor-plugin-common@6.1.1
    • @graphql-codegen/gql-tag-operations@5.0.4
    • @graphql-codegen/typescript-operations@5.0.3
    • @graphql-codegen/typed-document-node@6.1.1
    • @graphql-codegen/typescript@5.0.3

5.1.1

Patch Changes

  • Updated dependencies [1debf51]:
    • @graphql-codegen/gql-tag-operations@5.0.3

5.1.0

Minor Changes

5.0.3

Patch Changes

  • Updated dependencies [8258f1f]:
    • @graphql-codegen/visitor-plugin-common@6.1.0
    • @graphql-codegen/gql-tag-operations@5.0.2
    • @graphql-codegen/typescript-operations@5.0.2
    • @graphql-codegen/typed-document-node@6.0.2
    • @graphql-codegen/typescript@5.0.2

5.0.2

Patch Changes

  • Updated dependencies [accdab6]:
    • @graphql-codegen/visitor-plugin-common@6.0.1
    • @graphql-codegen/gql-tag-operations@5.0.1
    • @graphql-codegen/typescript-operations@5.0.1
    • @graphql-codegen/typed-document-node@6.0.1
    • @graphql-codegen/typescript@5.0.1

5.0.1

Patch Changes

5.0.0

Major Changes

Patch Changes

4.8.3

Patch Changes

  • #10362 3188b8c Thanks @Brookke! - Make generated type compatible with noImplicitOverride=true

  • #10373 c3295f9 Thanks @eddeee888! - Fix client preset not working with exactOptionalPropertyTypes=true when documentMode=string

  • Updated dependencies [3188b8c, c3295f9]:

    • @graphql-codegen/typed-document-node@5.1.2

4.8.2

Patch Changes

  • #10120 98392fc Thanks @yangirov! - The @graphql-codegen/client-preset package now supports the enumValues option.

  • Updated dependencies [e324382]:

    • @graphql-codegen/plugin-helpers@5.1.1

4.8.1

Patch Changes

4.8.0

Minor Changes

Patch Changes

  • Updated dependencies [f6909d1, f3cf4df]:
    • @graphql-codegen/visitor-plugin-common@5.8.0
    • @graphql-codegen/typescript-operations@4.6.0
    • @graphql-codegen/gql-tag-operations@4.0.17
    • @graphql-codegen/typed-document-node@5.1.1
    • @graphql-codegen/typescript@4.1.6

4.7.0

Minor Changes

Patch Changes

  • Updated dependencies [bfe3c75]:
    • @graphql-codegen/typed-document-node@5.1.0

4.6.4

Patch Changes

  • #10302 d8566c0 Thanks @eddeee888! - Fix Apollo unmask directive incorrectly generating fragmentRefs

  • Updated dependencies [d8566c0]:

    • @graphql-codegen/visitor-plugin-common@5.7.1
    • @graphql-codegen/typescript-operations@4.5.1
    • @graphql-codegen/gql-tag-operations@4.0.16
    • @graphql-codegen/typed-document-node@5.0.15
    • @graphql-codegen/typescript@4.1.5

4.6.3

Patch Changes

  • #10298 3efc472 Thanks @dotansimha! - Fix a bug where fragment spreads with @client directives is not being removed from the generated persisted documents

  • Updated dependencies [6d7c1d7]:

    • @graphql-codegen/visitor-plugin-common@5.7.0
    • @graphql-codegen/typescript-operations@4.5.0
    • @graphql-codegen/gql-tag-operations@4.0.15
    • @graphql-codegen/typed-document-node@5.0.14
    • @graphql-codegen/typescript@4.1.4

4.6.2

Patch Changes

4.6.1

Patch Changes

  • Updated dependencies [ec07018]:
    • @graphql-codegen/gql-tag-operations@4.0.14

4.6.0

Minor Changes

Patch Changes

  • Updated dependencies [60dd72f]:
    • @graphql-codegen/visitor-plugin-common@5.6.1
    • @graphql-codegen/gql-tag-operations@4.0.13
    • @graphql-codegen/typescript-operations@4.4.1
    • @graphql-codegen/typed-document-node@5.0.13
    • @graphql-codegen/typescript@4.1.3

4.5.1

Patch Changes

  • #9981 05aa6b4 Thanks @azu! - The client preset now allows the use of the enumsAsConst config option

  • Updated dependencies [1617e3c, fa64fbf]:

    • @graphql-codegen/visitor-plugin-common@5.6.0
    • @graphql-codegen/typescript-operations@4.4.0
    • @graphql-codegen/gql-tag-operations@4.0.12
    • @graphql-codegen/typed-document-node@5.0.12
    • @graphql-codegen/typescript@4.1.2

4.5.0

Minor Changes

Patch Changes

  • #10182 effd875 Thanks @eddeee888! - Revert slimmer client preset output

  • Updated dependencies [55a1e9e, a235051, c7af639]:

    • @graphql-codegen/visitor-plugin-common@5.5.0
    • @graphql-codegen/plugin-helpers@5.1.0
    • @graphql-codegen/typed-document-node@5.0.11
    • @graphql-codegen/gql-tag-operations@4.0.11
    • @graphql-codegen/typescript-operations@4.3.1
    • @graphql-codegen/typescript@4.1.1

4.4.0

Minor Changes

  • #10073 8471a18 Thanks @n1ru4l! - Reduce noise of generated code by only generating code relevant to GraphQL operations.

Patch Changes

  • #10075 67e7556 Thanks @n1ru4l! - Add note about enabling bundle size reduction for the generated graphql tag file.

  • Updated dependencies [67e7556, 3f4f546]:

    • @graphql-codegen/gql-tag-operations@4.0.10
    • @graphql-codegen/visitor-plugin-common@5.4.0
    • @graphql-codegen/typescript-operations@4.3.0
    • @graphql-codegen/typescript@4.1.0
    • @graphql-codegen/typed-document-node@5.0.10

4.3.3

Patch Changes

4.3.2

Patch Changes

  • Updated dependencies [79fee3c]:
    • @graphql-codegen/visitor-plugin-common@5.3.1
    • @graphql-codegen/gql-tag-operations@4.0.9
    • @graphql-codegen/typescript-operations@4.2.3
    • @graphql-codegen/typed-document-node@5.0.9
    • @graphql-codegen/typescript@4.0.9

4.3.1

Patch Changes

  • Updated dependencies [808ada5, 14ce39e]:
    • @graphql-codegen/visitor-plugin-common@5.3.0
    • @graphql-codegen/gql-tag-operations@4.0.8
    • @graphql-codegen/typescript-operations@4.2.2
    • @graphql-codegen/typed-document-node@5.0.8
    • @graphql-codegen/typescript@4.0.8

4.3.0

Minor Changes

  • #10001 1be6e65 Thanks @n1ru4l! - Support discriminating null and undefined within the useFragment function.

    function MyComponent(props: FragmentType<typeof MyFragment> | null) {
      const data = useFragment(MyFragment, props)
      // data is `MyFragment | null`
    }
    
    function MyComponent(props: FragmentType<typeof MyFragment> | undefined) {
      const data = useFragment(MyFragment, props)
      // data is `MyFragment | undefined`
    }

    Before, the returned type from useFragment was always TType | null | undefined.

  • #9804 5e594ef Thanks @rachel-church! - Preserving Array<T> or ReadonlyArray<T> in useFragment() return type.

Patch Changes

  • #9996 99f449c Thanks @nahn20! - Added configuration to allow for custom hash functions for persisted documents in the client preset

    Example

    import { type CodegenConfig } from '@graphql-codegen/cli'
    
    const config: CodegenConfig = {
      schema: 'schema.graphql',
      documents: ['src/**/*.tsx'],
      generates: {
        './src/gql/': {
          preset: 'client',
          presetConfig: {
            persistedDocuments: {
              hashAlgorithm: operation => {
                const shasum = crypto.createHash('sha512')
                shasum.update(operation)
                return shasum.digest('hex')
              }
            }
          }
        }
      }
    }
  • Updated dependencies [5501c62]:

    • @graphql-codegen/add@5.0.3

4.2.6

Patch Changes

  • Updated dependencies [dfc5310, 156cc2b, dfc5310, b49457b]:
    • @graphql-codegen/plugin-helpers@5.0.4
    • @graphql-codegen/visitor-plugin-common@5.2.0
    • @graphql-codegen/gql-tag-operations@4.0.7
    • @graphql-codegen/typescript-operations@4.2.1
    • @graphql-codegen/typed-document-node@5.0.7
    • @graphql-codegen/typescript@4.0.7

4.2.5

Patch Changes

4.2.4

Patch Changes

  • Updated dependencies [920b443, ed9c205]:
    • @graphql-codegen/visitor-plugin-common@5.1.0
    • @graphql-codegen/typescript-operations@4.2.0
    • @graphql-codegen/gql-tag-operations@4.0.6
    • @graphql-codegen/typed-document-node@5.0.6
    • @graphql-codegen/typescript@4.0.6

4.2.3

Patch Changes

  • Updated dependencies [53f270a]:
    • @graphql-codegen/visitor-plugin-common@5.0.0
    • @graphql-codegen/gql-tag-operations@4.0.5
    • @graphql-codegen/typescript-operations@4.1.3
    • @graphql-codegen/typed-document-node@5.0.5
    • @graphql-codegen/typescript@4.0.5

4.2.2

Patch Changes

  • #9813 4e69568 Thanks @saihaj! - bumping for a release

  • Updated dependencies [4e69568]:

    • @graphql-codegen/visitor-plugin-common@4.1.2
    • @graphql-codegen/typescript-operations@4.1.2
    • @graphql-codegen/add@5.0.2
    • @graphql-codegen/gql-tag-operations@4.0.4
    • @graphql-codegen/typed-document-node@5.0.4
    • @graphql-codegen/typescript@4.0.4
    • @graphql-codegen/plugin-helpers@5.0.3

4.2.1

Patch Changes

  • #9557 48ddaeae1 Thanks @konomae! - Add eslint-disable comment to fragment-masking.ts

  • Updated dependencies [7718a8113]:

    • @graphql-codegen/visitor-plugin-common@4.1.1
    • @graphql-codegen/gql-tag-operations@4.0.3
    • @graphql-codegen/typescript-operations@4.1.1
    • @graphql-codegen/typed-document-node@5.0.3
    • @graphql-codegen/typescript@4.0.3

4.2.0

Minor Changes

  • #9811 d8364e045 Thanks @saihaj! - The client preset now allows the use of the futureProofEnums config option

Patch Changes

4.1.0

Minor Changes

  • #9562 5beee9794 Thanks @n1ru4l! - Add the addTypenameSelectionDocumentTransform for automatically adding __typename selections to all objct type selection sets.

    This is useful for GraphQL Clients such as Apollo Client or urql that need typename information for their cache to function.

    Example Usage

    import { addTypenameSelectionDocumentTransform } from '@graphql-codegen/client-preset';
    import { CodegenConfig } from "@graphql-codegen/cli";
    
    const config: CodegenConfig = {
      schema: "YOUR_GRAPHQL_ENDPOINT",
      documents: ["./**/*.{ts,tsx}"],
      ignoreNoDocuments: true,
      generates: {
        "./gql/": {
          preset: "client",
          plugins: [],
          presetConfig: {
            persistedDocuments: true,
          },
          documentTransforms: [addTypenameSelectionDocumentTransform],
        },
      },
    };
    
    export default config;

Patch Changes

  • Updated dependencies [bb1e0e96e]:
    • @graphql-codegen/plugin-helpers@5.0.1

4.0.1

Patch Changes

  • #9497 2276708d0 Thanks @eddeee888! - Revert default ID scalar input type to string

    We changed the ID Scalar input type from string to string | number in the latest major version of typescript plugin. This causes issues for server plugins (e.g. typescript-resolvers) that depends on typescript plugin. This is because the scalar type needs to be manually inverted on setup which is confusing.

  • Updated dependencies [2276708d0]:

    • @graphql-codegen/visitor-plugin-common@4.0.1
    • @graphql-codegen/typescript-operations@4.0.1
    • @graphql-codegen/typescript@4.0.1
    • @graphql-codegen/gql-tag-operations@4.0.1
    • @graphql-codegen/typed-document-node@5.0.1

4.0.0

Major Changes

  • bb66c2a31 Thanks @n1ru4l! - Require Node.js >= 16. Drop support for Node.js 14

Minor Changes

  • #9196 3848a2b73 Thanks @beerose! - Add @defer directive support

    When a query includes a deferred fragment field, the server will return a partial response with the non-deferred fields first, followed by the remaining fields once they have been resolved.

    Once start using the @defer directive in your queries, the generated code will automatically include support for the directive.

    // src/index.tsx
    import { graphql } from './gql'
    
    const OrdersFragment = graphql(`
      fragment OrdersFragment on User {
        orders {
          id
          total
        }
      }
    `)
    const GetUserQuery = graphql(`
      query GetUser($id: ID!) {
        user(id: $id) {
          id
          name
          ...OrdersFragment @defer
        }
      }
    `)

    The generated type for GetUserQuery will have information that the fragment is incremental, meaning it may not be available right away.

    // gql/graphql.ts
    export type GetUserQuery = { __typename?: 'Query'; id: string; name: string } & ({
      __typename?: 'Query'
    } & {
      ' $fragmentRefs'?: { OrdersFragment: Incremental<OrdersFragment> }
    })

    Apart from generating code that includes support for the @defer directive, the Codegen also exports a utility function called isFragmentReady. You can use it to conditionally render components based on whether the data for a deferred fragment is available:

    const OrdersList = (props: { data: FragmentType<typeof OrdersFragment> }) => {
      const data = useFragment(OrdersFragment, props.data);
      return (
        // render orders list
      )
    };
    
    function App() {
      const { data } = useQuery(GetUserQuery);
      return (
        {data && (
          <>
            {isFragmentReady(GetUserQuery, OrdersFragment, data)
    					&& <OrdersList data={data} />}
          </>
        )}
      );
    }
    export default App;
  • #9353 d7e335b58 Thanks @charpeni! - Implement the ability the specify the hash algorithm used for persisted documents via persistedDocuments.hashAlgorithm

Patch Changes

3.0.1

Patch Changes

  • Updated dependencies [386cf9044, 402cb8ac0]:
    • @graphql-codegen/visitor-plugin-common@3.1.1
    • @graphql-codegen/gql-tag-operations@3.0.1
    • @graphql-codegen/typescript-operations@3.0.4
    • @graphql-codegen/typed-document-node@4.0.1
    • @graphql-codegen/typescript@3.0.4

3.0.0

Major Changes

  • #9137 2256c8b5d Thanks @beerose! - Add TypedDocumentNode string alternative that doesn’t require GraphQL AST on the client. This change requires @graphql-typed-document-node/core in version 3.2.0 or higher.

Patch Changes

2.1.1

Patch Changes

2.1.0

Minor Changes

  • #8893 a118c307a Thanks @n1ru4l! - It is no longer mandatory to declare an empty plugins array when using a preset

  • #8723 a3309e63e Thanks @kazekyo! - Introduce a new feature called DocumentTransform.

    DocumentTransform is a functionality that allows you to modify documents before they are processed by plugins. You can use functions passed to the documentTransforms option to make changes to GraphQL documents.

    To use this feature, you can write documentTransforms as follows:

    import type { CodegenConfig } from '@graphql-codegen/cli'
    
    const config: CodegenConfig = {
      schema: 'https://localhost:4000/graphql',
      documents: ['src/**/*.tsx'],
      generates: {
        './src/gql/': {
          preset: 'client',
          documentTransforms: [
            {
              transform: ({ documents }) => {
                // Make some changes to the documents
                return documents
              }
            }
          ]
        }
      }
    }
    export default config

    For instance, to remove a @localOnlyDirective directive from documents, you can write the following code:

    import type { CodegenConfig } from '@graphql-codegen/cli'
    import { visit } from 'graphql'
    
    const config: CodegenConfig = {
      schema: 'https://localhost:4000/graphql',
      documents: ['src/**/*.tsx'],
      generates: {
        './src/gql/': {
          preset: 'client',
          documentTransforms: [
            {
              transform: ({ documents }) => {
                return documents.map(documentFile => {
                  documentFile.document = visit(documentFile.document, {
                    Directive: {
                      leave(node) {
                        if (node.name.value === 'localOnlyDirective') return null
                      }
                    }
                  })
                  return documentFile
                })
              }
            }
          ]
        }
      }
    }
    export default config

    DocumentTransform can also be specified by file name. You can create a custom file for a specific transformation and pass it to documentTransforms.

    Let’s create the document transform as a file:

    module.exports = {
      transform: ({ documents }) => {
        // Make some changes to the documents
        return documents
      }
    }

    Then, you can specify the file name as follows:

    import type { CodegenConfig } from '@graphql-codegen/cli'
    
    const config: CodegenConfig = {
      schema: 'https://localhost:4000/graphql',
      documents: ['src/**/*.tsx'],
      generates: {
        './src/gql/': {
          preset: 'client',
          documentTransforms: ['./my-document-transform.js']
        }
      }
    }
    export default config

Patch Changes

2.0.0

Major Changes

Patch Changes

1.3.0

Minor Changes

  • #8757 4f290aa72 Thanks @n1ru4l! - Add support for persisted documents.

    You can now generate and embed a persisted documents hash for the executable documents.

    /** codegen.ts */
    import { CodegenConfig } from '@graphql-codegen/cli'
    
    const config: CodegenConfig = {
      schema: 'https://graphql.org/graphql/',
      documents: ['src/**/*.tsx'],
      ignoreNoDocuments: true, // for better experience with the watcher
      generates: {
        './src/gql/': {
          preset: 'client',
          plugins: [],
          presetConfig: {
            persistedDocuments: true
          }
        }
      }
    }
    
    export default config

    This will generate ./src/gql/persisted-documents.json (dictionary of hashes with their operation string).

    In addition to that each generated document node will have a __meta__.hash property.

    import { gql } from './gql.js'
    
    const allFilmsWithVariablesQueryDocument = graphql(/* GraphQL */ `
      query allFilmsWithVariablesQuery($first: Int!) {
        allFilms(first: $first) {
          edges {
            node {
              ...FilmItem
            }
          }
        }
      }
    `)
    
    console.log((allFilmsWithVariablesQueryDocument as any)['__meta__']['hash'])
  • #8757 4f290aa72 Thanks @n1ru4l! - Add support for embedding metadata in the document AST.

    It is now possible to embed metadata (e.g. for your GraphQL client within the emitted code).

    /** codegen.ts */
    import { CodegenConfig } from '@graphql-codegen/cli'
    
    const config: CodegenConfig = {
      schema: 'https://graphql.org/graphql/',
      documents: ['src/**/*.tsx'],
      ignoreNoDocuments: true, // for better experience with the watcher
      generates: {
        './src/gql/': {
          preset: 'client',
          plugins: [],
          presetConfig: {
            onExecutableDocumentNode(documentNode) {
              return {
                operation: documentNode.definitions[0].operation,
                name: documentNode.definitions[0].name.value
              }
            }
          }
        }
      }
    }
    
    export default config

    You can then access the metadata via the __meta__ property on the document node.

    import { gql } from './gql.js'
    
    const allFilmsWithVariablesQueryDocument = graphql(/* GraphQL */ `
      query allFilmsWithVariablesQuery($first: Int!) {
        allFilms(first: $first) {
          edges {
            node {
              ...FilmItem
            }
          }
        }
      }
    `)
    
    console.log((allFilmsWithVariablesQueryDocument as any)['__meta__'])

Patch Changes

  • #8757 4f290aa72 Thanks @n1ru4l! - dependencies updates:
  • Updated dependencies [a98198524]:
    • @graphql-codegen/visitor-plugin-common@2.13.8
    • @graphql-codegen/gql-tag-operations@1.6.2
    • @graphql-codegen/typescript-operations@2.5.13
    • @graphql-codegen/typed-document-node@2.3.13
    • @graphql-codegen/typescript@2.8.8

1.2.6

Patch Changes

  • #8796 902451601 Thanks @shmax! - remove extra asterisk and add missing semicolon in generated output

  • Updated dependencies [902451601]:

    • @graphql-codegen/gql-tag-operations@1.6.1

1.2.5

Patch Changes

  • Updated dependencies [eb454d06c, 2a33fc774]:
    • @graphql-codegen/visitor-plugin-common@2.13.7
    • @graphql-codegen/gql-tag-operations@1.6.0
    • @graphql-codegen/typescript-operations@2.5.12
    • @graphql-codegen/typed-document-node@2.3.12
    • @graphql-codegen/typescript@2.8.7

1.2.4

Patch Changes

1.2.3

Patch Changes

  • 46f75304a Thanks @saihaj! - fix the version of @graphql-codegen/plugin-helpers@3.1.1

  • Updated dependencies [307a5d350, 46f75304a]:

    • @graphql-codegen/plugin-helpers@3.1.1
    • @graphql-codegen/add@3.2.3
    • @graphql-codegen/visitor-plugin-common@2.13.5
    • @graphql-codegen/gql-tag-operations@1.5.11
    • @graphql-codegen/typescript-operations@2.5.10
    • @graphql-codegen/typed-document-node@2.3.10
    • @graphql-codegen/typescript@2.8.5

1.2.2

Patch Changes

  • #8702 0eb0dde8a Thanks @ithinkdancan! - add config for nonOptionalTypename

  • Updated dependencies [a6c2097f4, a6c2097f4, a6c2097f4, f79a00e8a, c802a0c0b]:

    • @graphql-codegen/plugin-helpers@3.0.0
    • @graphql-codegen/typed-document-node@2.3.9
    • @graphql-codegen/visitor-plugin-common@2.13.4
    • @graphql-codegen/add@3.2.2
    • @graphql-codegen/gql-tag-operations@1.5.10
    • @graphql-codegen/typescript-operations@2.5.9
    • @graphql-codegen/typescript@2.8.4

1.2.1

Patch Changes

  • Updated dependencies [62f655452]:
    • @graphql-codegen/visitor-plugin-common@2.13.3
    • @graphql-codegen/typescript-operations@2.5.8
    • @graphql-codegen/gql-tag-operations@1.5.9
    • @graphql-codegen/typed-document-node@2.3.8
    • @graphql-codegen/typescript@2.8.3

1.2.0

Minor Changes

1.1.5

Patch Changes

  • Updated dependencies [00ddc9368]:
    • @graphql-codegen/gql-tag-operations@1.5.8

1.1.4

Patch Changes

  • Updated dependencies [ef4c2c9c2]:
    • @graphql-codegen/visitor-plugin-common@2.13.2
    • @graphql-codegen/typescript@2.8.2
    • @graphql-codegen/gql-tag-operations@1.5.7
    • @graphql-codegen/typescript-operations@2.5.7
    • @graphql-codegen/typed-document-node@2.3.7

1.1.3

Patch Changes

  • Updated dependencies [63dc8f205]:
    • @graphql-codegen/visitor-plugin-common@2.13.1
    • @graphql-codegen/plugin-helpers@2.7.2
    • @graphql-codegen/gql-tag-operations@1.5.6
    • @graphql-codegen/typescript-operations@2.5.6
    • @graphql-codegen/typed-document-node@2.3.6
    • @graphql-codegen/typescript@2.8.1

1.1.2

Patch Changes

1.1.1

Patch Changes

1.1.0

Minor Changes

Patch Changes

  • #8500 71aae7a92 Thanks @charlypoly! - Add warning and errors to prevent unwanted configuration

  • Updated dependencies [a46b8d99c]:

    • @graphql-codegen/visitor-plugin-common@2.13.0
    • @graphql-codegen/gql-tag-operations@1.5.5
    • @graphql-codegen/typescript-operations@2.5.5
    • @graphql-codegen/typed-document-node@2.3.5
    • @graphql-codegen/typescript@2.7.5

1.0.7

Patch Changes

1.0.6

Patch Changes

  • Updated dependencies [1bd7f771c]:
    • @graphql-codegen/visitor-plugin-common@2.12.2
    • @graphql-codegen/gql-tag-operations@1.5.4
    • @graphql-codegen/typescript-operations@2.5.4
    • @graphql-codegen/typed-document-node@2.3.4
    • @graphql-codegen/typescript@2.7.4

1.0.5

Patch Changes

1.0.4

Patch Changes

  • #8455 d19573d88 Thanks @charlypoly! - The client preset now allows the use of the following config:
    • scalars
    • defaultScalarType
    • strictScalars
    • namingConvention
    • useTypeImports
    • skipTypename
    • arrayInputCoercion

1.0.3

Patch Changes

  • #8443 e2d115146 Thanks @charlypoly! - fix(gql-tag-operations): issues with “no documents” scenario

  • Updated dependencies [e2d115146]:

    • @graphql-codegen/gql-tag-operations@1.5.3

1.0.2

Patch Changes

1.0.1

Patch Changes

  • #8302 876844e76 Thanks @charlypoly! - @graphql-codegen/gql-tag-operations and @graphql-codegen/gql-tag-operations-preset

    Introduce a gqlTagName configuration option


    @graphql-codegen/client-preset

    New preset for GraphQL Code Generator v3, more information on the RFC: https://github.com/dotansimha/graphql-code-generator/issues/8296


    @graphql-codegen/cli

    Update init wizard with 3.0 recommendations (codegen.ts, client preset)

  • Updated dependencies [876844e76]:

    • @graphql-codegen/gql-tag-operations@1.5.0