@apollo/client@4.3.0-alpha.2
📦 apollo-clientView on GitHub →
✨ 7 features🔧 6 symbols
Summary
This release introduces comprehensive support for custom scalars within Apollo Client, allowing users to define parsing and serialization logic for non-standard scalar types in both cache operations and network requests.
Migration Steps
- If using custom scalars, declare the scalar shape by merging into the `ApolloCache.Scalars` interface in your TypeScript declaration files (e.g., `apollo.d.ts`).
- Configure custom scalars in `InMemoryCache` using the `scalars` option, providing `parse`, `serialize`, and optional `is` functions for each scalar type name.
✨ New Features
- Adds `Scalar.fromGraphQLScalarType` helper to create a `Scalar` instance from an existing graphql.js `GraphQLScalarType`.
- Adds the plumbing and types implementation for declaring custom scalars and configuring custom scalars in `InMemoryCache` via declaration merging on `ApolloCache.Scalars` interface.
- Adds the `scalars` option to `InMemoryCache` configuration to define custom scalar parsing/serialization logic.
- Adds a `scalar` option to `InMemoryCache` field policies to specify which custom scalar should be used for parsing/serializing a specific field value.
- Automatically serialize variables that include custom scalar values during cache operations and network requests.
- Introduces the `inputObjects` option in `InMemoryCache` to specify where nested scalar fields are located within input types for serialization.
- Adds the `getScalar` abstract method to `ApolloCache` for subclasses to implement custom scalar behavior.