Basics
DocsSelectorsBasics

Selectors | Zeus GraphQL TypeScript generator

Generate Reusable Selection Sets

In TypeScript Zeus can help you make type-safe Zeus selection sets to reuse across queries.

import { Selector, Chain } from './zeus';

const chain = Chain('https://faker.graphqleditor.com/a-team/olympus/graphql');

const cardSelector = Selector('Card')({
  name: true,
  description: true,
  Attack: true,
  skills: true,
  Defense: true,
  cardImage: {
    key: true,
    bucket: true,
  },
});

const queryWithSelectionSet = await chain('query')({
  drawCard: cardSelector,
});

Inferring the response type

Sometimes you might want to infer the response type. In that case, it is best to use selectors:

import { Selector, InputType, GraphQLTypes } from './zeus';

export const drawCardQuery = Selector("Query"){
  drawCard: {
    Attack: true,
    Children: true,
    id: true,
  },
});

type InferredResponseType = InputType<GraphQLTypes['Query'], typeof drawCardQuery>;