import { GraphQLScalarType } from "https://deno.land/x/kilatgraphql@16.6.0-1/mod.ts";
Scalar Type Definition
The leaf values of any request and input values to arguments are Scalars (or Enums) and are defined with a name and a series of functions used to parse input from ast or variables and to ensure validity.
If a type's serialize function returns null
or does not return a value
(i.e. it returns undefined
) then an error will be raised and a null
value will be returned in the response. It is always better to validate
Example:
const OddType = new GraphQLScalarType({
name: 'Odd',
serialize(value) {
if (!Number.isFinite(value)) {
throw new Error(
`Scalar "Odd" cannot represent "${value}" since it is not a finite number.`,
);
}
if (value % 2 === 0) {
throw new Error(`Scalar "Odd" cannot represent "${value}" since it is even.`);
}
return value;
}
});
Constructors
new
GraphQLScalarType(config: Readonly<GraphQLScalarTypeConfig<TInternal, TExternal>>)Type Parameters
optional
TExternal = TInternalProperties
astNode: Maybe<ScalarTypeDefinitionNode>
extensionASTNodes: ReadonlyArray<ScalarTypeExtensionNode>
extensions: Readonly<GraphQLScalarTypeExtensions>
parseLiteral: GraphQLScalarLiteralParser<TInternal>
parseValue: GraphQLScalarValueParser<TInternal>
serialize: GraphQLScalarSerializer<TExternal>