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

chore(deps): update dependency @graphql-codegen/client-preset to v4 #423

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Oct 7, 2023

Mend Renovate

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
@graphql-codegen/client-preset (source) 1.2.5 -> 4.2.6 age adoption passing confidence

Release Notes

dotansimha/graphql-code-generator (@​graphql-codegen/client-preset)

v4.2.6

Compare Source

Patch Changes

v4.2.5

Compare Source

Patch Changes

v4.2.4

Compare Source

Patch Changes

v4.2.3

Compare Source

Patch Changes

v4.2.2

Compare Source

Patch Changes

v4.2.1

Compare Source

Patch Changes

v4.2.0

Compare Source

Minor Changes
Patch Changes

v4.1.0

Compare Source

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

v4.0.1

Compare Source

Patch Changes

v4.0.0

Compare Source

Major Changes
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

v3.0.1

Compare Source

Patch Changes

v3.0.0

Compare Source

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

v2.1.1

Compare Source

Patch Changes

v2.1.0

Compare Source

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 '@&#8203;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 '@&#8203;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 '@&#8203;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

v2.0.0

Compare Source

Major Changes
Patch Changes

v1.3.0

Compare Source

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 '@&#8203;graphql-codegen/cli';
    
    const config: CodegenConfig = {
      schema: 'https://swapi-graphql.netlify.app/.netlify/functions/index',
      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 '@&#8203;graphql-codegen/cli';
    
    const config: CodegenConfig = {
      schema: 'https://swapi-graphql.netlify.app/.netlify/functions/index',
      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

v1.2.6

Compare Source

Patch Changes

Configuration

📅 Schedule: Branch creation - "every weekend" (UTC), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR has been generated by Mend Renovate. View repository job log here.

@renovate renovate bot force-pushed the renovate/graphql-codegen-client-preset-4.x branch from 40b0079 to 3722f5b Compare February 6, 2024 16:40
@renovate renovate bot force-pushed the renovate/graphql-codegen-client-preset-4.x branch 2 times, most recently from a9f6c00 to 4d96b63 Compare February 22, 2024 21:53
@renovate renovate bot force-pushed the renovate/graphql-codegen-client-preset-4.x branch from 4d96b63 to 9e7aa3b Compare March 27, 2024 13:36
@renovate renovate bot force-pushed the renovate/graphql-codegen-client-preset-4.x branch from 9e7aa3b to 257f8ad Compare May 17, 2024 11:44
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

Successfully merging this pull request may close these issues.

None yet

0 participants