UNPKG

@apollo/client

Version:

A fully-featured caching GraphQL client.

57 lines (56 loc) 2.12 kB
import type { GraphQLScalarType } from "graphql"; export declare namespace Scalar { interface Options<TSerialized, TParsed> { /** * A function that transforms the JSON serialized value into its parsed value. * * @example * * ```ts * new Scalar<string, Date>({ * parse: (dateString) => new Date(dateString), * }); * ``` */ parse(serializedValue: TSerialized): NoInfer<TParsed>; /** * A function that transforms the parsed value into its JSON serialized value. * * @example * * ```ts * new Scalar<string, Date>({ * serialize: (date) => date.toISOString(), * }); * ``` */ serialize(parsedValue: TParsed): NoInfer<TSerialized>; /** * A [predicate function](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates) that determines whether the value * is the parsed value. Return `true` when the value is the parsed value. * * @defaultValue * Function that returns `true` when the value is a non-null object type. * * @example * * ```ts * new Scalar<string, Date>({ * is: (value) => value instanceof Date, * }); * ``` */ is?(value: TSerialized | TParsed): boolean; } } export declare class Scalar<TSerialized, TParsed> { private options; static fromGraphQLScalarType<TSerialized, TParsed>(scalarType: GraphQLScalarType<TParsed, TSerialized>, options?: Pick<Scalar.Options<NoInfer<TSerialized>, NoInfer<TParsed>>, "is">): Scalar<TSerialized, TParsed>; constructor(options: Scalar.Options<TSerialized, TParsed>); parse(value: TSerialized): TParsed; serialize(value: TParsed): TSerialized; coerceToParsed(value: TSerialized | TParsed): TParsed; coerceToSerialized(value: TSerialized | TParsed): TSerialized; is(value: TSerialized | TParsed): value is TParsed; } //# sourceMappingURL=Scalar.d.cts.map