For the complete documentation index, see llms.txt. This page is also available as Markdown.

Scalars

Scalars

In Zeus you can encode and decode scalars.

Decode

The decode function is called every time a scalar returns from backend before passing the result from Chain, Subscription functions

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,
  },
});

So the data.drawCard.info will be of type Date as provided by decoder ReturnType

Encode Scalars

You can also encode scalars before sending them to backend:

Encoders require value to be encoded to string and don't work with variables yet.

Place decoders and encoders in one place for reuse

Last updated

Was this helpful?