Scalars
Scalars
Decode
scalar JSON
scalar Datetime
type Card{
info: JSON!
createdAt: Datetime
}
type Query:{
drawCard: Card!
}import { Chain } from './zeus';
// Create a Chain client instance with the endpoint
const chain = Chain('https://faker.graphqleditor.com/a-team/olympus/graphql');
// Query the endpoint with Typescript autocomplete for arguments and response fields
const data = await chain('query', {
scalars: {
JSON: {
encode: (e: unknown) => JSON.stringify(e),
decode: (e: unknown) => JSON.parse(e as string),
},
Datetime: {
decode: (e: unknown) => new Date(e as string),
encode: (e: unknown) => (e as Date).toISOString(),
},
},
})({
drawCard: {
info: true,
},
});Encode Scalars
Place decoders and encoders in one place for reuse
Last updated
Was this helpful?