Docs

Get Started

Programmatic usage of CLI#

@gqty/cli has also a complete programmatic API, which allows you to generate the client with custom scripts.

inspectWriteGenerate#

Basically calling CLI functionality programmatically.

All the fields are optional, and it will always read from the Configuration if any field is not specified.

import { inspectWriteGenerate } from '@gqty/cli'; await inspectWriteGenerate({ destination: './src/gqty/index.ts', generateOptions: { preImport: '', scalarTypes: { DateTime: 'string', }, react: true, enumsAsStrings: false, subscriptions: false, }, headers: { authorization: process.env.TOKEN, }, });

writeGenerate#

If you have direct access to the GraphQLSchema from graphql-js, you can give it to this function and it will do the rest.

All the GenerateOptions are optional, and it will always read from the Configuration if any field is not specified.

import { writeGenerate } from '@gqty/cli'; // You get the `schema` from somewhere... await writeGenerate( // Required schema, // Destination, Required './src/gqty/index.ts', // GenerateOptions, optional { preImport: '', scalarTypes: { DateTime: 'string', }, react: true, enumsAsStrings: false, subscriptions: false, }, // What to do if a gqty client file already exists, Optional (existingFile) => { // existingFile == string } );

generate#

If you have direct access to the GraphQLSchema from graphql-js, you can give it to this function and it generates the code and simply return it.

All the GenerateOptions are optional, and it will always read from the Configuration if any field is not specified.

import { generate } from '@gqty/cli'; // You get the `schema` from somewhere... const { clientCode, schemaCode, generatedSchema, scalarsEnumsHash } = await generate( // Required schema, // GenerateOptions, optional { preImport: '', scalarTypes: { DateTime: 'string', }, react: true, enumsAsStrings: false, subscriptions: false, } );

getRemoteSchema#

Inspect a remote GraphQL API

If the headers are not specified, it will look for Configuration.

import { getRemoteSchema } from '@gqty/cli'; const schema = await getRemoteSchema( // Endpoint, required 'http://localhost:3000/api/graphql', // Optional { headers: { authorization: process.env.TOKEN, }, } ); // schema == import("graphql").GraphQLSchema