github apollographql/apollo-client @apollo/client-graphql-codegen@2.2.0

latest release: @apollo/client@4.3.0
2 hours ago

Add support for generating configuration objects for custom scalars in Apollo Client.

// codegen.ts
import type { CustomScalarsPluginConfig } from "@apollo/client-graphql-codegen/custom-scalars";

const config: CodegenConfig = {
  // ...
  generates: {
    "./path/to/custom-scalars.ts": {
      plugins: ["@apollo/client-graphql-codegen/custom-scalars"],
      config: {
        // ...
      } satisfies CustomScalarsPluginConfig,
    },
  },
};

This will generate both an inputObjects object and a scalarTypePolicies object in the generated file that can be used to configure custom scalars in InMemoryCache.

import { inputObjects, scalarTypePolicies } from "./path/to/custom-scalars";

const cache = new InMemoryCache({
  inputObjects,
});

cache.policies.addTypePolicies(scalarTypePolicies);

For more information on using custom scalars, read the Custom Scalars guide.

Minor Changes

  • #13310 8ab63fc Thanks @jerelmiller! - Introduce a new GraphQL Codegen plugin to generate the input object configuration needed to configure custom scalars for each field.
// codegen.ts
import type { CustomScalarsPluginConfig } from "@apollo/client-graphql-codegen/custom-scalars";

const config: CodegenConfig = {
  // ...
  generates: {
    "./path/to/custom-scalars.ts": {
      plugins: ["@apollo/client-graphql-codegen/custom-scalars"],
      config: {
        // ...
      } satisfies CustomScalarsPluginConfig,
    },
  },
};

This will generate an inputObjects object in the generated file that can be used to configure the inputObjects option for InMemoryCache.

import { inputObjects } from "./path/to/custom-scalars";

const cache = new InMemoryCache({
  inputObjects,
});
  • #13318 01f255b Thanks @jerelmiller! - The @apollo/client-graphql-codegen/custom-scalars GraphQL Codegen plugin now generates the type policy configuration needed to configure custom scalars for each field.

    // codegen.ts
    import type { CustomScalarsPluginConfig } from "@apollo/client-graphql-codegen/custom-scalars";
    
    const config: CodegenConfig = {
      // ...
      generates: {
        "./path/to/custom-scalars.ts": {
          plugins: ["@apollo/client-graphql-codegen/custom-scalars"],
          config: {
            // ...
          } satisfies CustomScalarsPluginConfig,
        },
      },
    };

    This will generate a scalarTypePolicies object in the generated file that can be used to configure type policies.

    import { scalarTypePolicies } from "./path/to/custom-scalars";
    
    const cache = new InMemoryCache();
    
    cache.policies.addTypePolicies(scalarTypePolicies);
  • #13426 a9beaff Thanks @jerelmiller! - Version bump only to rc.

  • #13447 24133fe Thanks @jerelmiller! - The @apollo/client-graphql-codegen/custom-scalars plugin now emits GraphQL list syntax in inputObjects and scalarTypePolicies (for example "[DateTime]").

Don't miss a new apollo-client release

NewReleases is sending notifications on new releases.