Getting Started
Getting Started
Use the Zeus CLI to generate types and GraphQL clients based on your schema, which you can then import into your projects to autocomplete, query and use GraphQL responses in a type-safe way.
Quick Start
Installation
You can also install locally to a project and then use as a npm or yarn script command or with npx
or yarn
directly eg:
TypeScript
Zeus is Typescript native, you can refer to imported types directly from the generated output of the CLI:
Demo Endpoint
All the demo code here was made using the demo GraphQL endpoint of Olympus Cards built with GraphQL Editor. Feel free to check out the GraphiQL interface too.
Query With Zeus Chain Client
You can now use the Zeus Chain
client from the generated output to make type-safe queries and mutations to your endpoint and receive type-safe responses.
When querying a GraphQL field which takes an argument such as the cardById
above, the fields are defined in terms of a tuple. For example for cardById: [ {...arguments} , {...response_selection_set} ]
the equivalent in gql syntax would be:
For fields which have no argument, those receive only the response selection set object values.
Note: Chain
will also accept a second argument of fetch-like options to configure the client with properties such as credentials
, mode
, headers
etc...
Note: There is also an exported Zeus Gql
convenience function, it is a Chain client pre-configured with the endpoint specified in the CLI.
Listen on a WebSocket - GraphQL Subscriptions
Use the Zeus Subscription
client creator in your generated output to create WebSocket connections to your GraphQL socket.
Usage with NodeJS
Generate clients for use with Node.js:
Usage with React Native
As usual:
Other CLI Options
Specify the output folder with the second argument:
Output Typescript Only with the --typescript
flag:
Load your schema from a URL with a URL in the first argument:
Download and save GraphQL schema to a local path with the --graphql=savePath
flag:
Generate and save a JSON schema to a local path with the --jsonSchema=savePath
flag:
Add a header value with the --header=value
flag:
Get help with the Zeus CLI by using:
Tip:
Add a script entry in your package.json
file for quickly calling Zeus generation:
Last updated