Skip to content

Latest commit

 

History

History
40 lines (30 loc) · 804 Bytes

use-as-a-library.md

File metadata and controls

40 lines (30 loc) · 804 Bytes
link title order category
library
Use as a library
5
Basics

Use as a library

Generate Code

This will be rarely used, but here you are! Generate Typescript and Javascript from GraphQL definitions

import { TreeToTS } from 'graphql-zeus';
import { Parser } from 'graphql-js-tree';

const schemaFileContents = `
type Query{
    hello: String!
}
schema{
    query: Query
}
`;

const typeScriptDefinition = TreeToTS.resolveTree(Parser.parse(schemaFileContents));

Dynamically Fetch Schema

This is useful when you need your schema fetched from your GraphQL endpoint in-code

import { Utils } from 'graphql-zeus';

Utils.getFromUrl('https://faker.graphqleditor.com/a-team/olympus/graphql').then((schemaContent) => {
  // Use schema content here
});