@gql2ts/from-schema
TypeScript icon, indicating that this package has built-in type declarations

2.0.0-4 • Public • Published

@gql2ts/from-schema

This package is used to generate a namespace for a GraphQL Schema with all possible interfaces/types included.

Objective

Pass a GraphQL type schema and query to generate a TypeScript interface:

Input:

type Query {
  thing: String!
  anotherThing: Boolean!
}
query GetThing {
  thing
}

Output:

interface GetThing {
  thing: string;
}

Basic Usage

import { generateNamespace } from '@gql2ts/from-schema';
import { schema } from 'my-graphql-stuff';
import * as fs from 'fs';

const myNamespace = generateNamespace('MyGraphQL', schema);
fs.writeFile('mySchema.d.ts', myNamespace);

Advanced Usage

import { generateNamespace, ISchemaToInterfaceOptions } from '@gql2ts/from-schema';
import { schema } from 'my-graphql-stuff';
import { IFromQueryOptions } from '@gql2ts/types';
import * as fs from 'fs';

const options: Partial<ISchemaToInterfaceOptions> = {
  ignoredTypes: ['BadGraphType']
};

const overrides: Partial<IFromQueryOptions> = {
  generateInterfaceName: name => `IGraphQL${name}`
};

const myNamespace = generateNamespace('MyGraphQL', schema, options, overrides);
fs.writeFile('mySchema.d.ts', myNamespace);

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.0.0-41,547latest
2.0.0-00next
1.9.0-alpha.5ddac7490canary

Version History

VersionDownloads (Last 7 Days)Published
2.0.0-41,547
2.0.0-00
1.11.0-alpha.95b0b3b30
1.11.0-alpha.4807d0000
1.11.0-alpha.b353a5690
1.11.0-alpha.905b1daf0
1.11.0-alpha.aea052fd0
1.11.0-alpha.79abe8540
1.11.0-alpha.8b444a630
1.11.0-alpha.12ee5e9b0
1.10.1684
1.10.00
1.9.0149
1.9.0-alpha.ad6013c20
1.8.20
1.8.2-00
1.8.10
1.9.0-alpha.5ddac7490
1.8.010
1.8.0-alpha.8bb7d8dc1
1.7.20
1.7.2-40
1.7.2-y.00
1.7.2-20
1.7.2-10
1.7.2-00
1.7.10
1.7.00
1.7.0-alpha.b2b267900
1.6.00
1.6.0-20
1.6.0-11
1.6.0-00
1.5.11
1.5.00
1.4.40
1.5.0-alpha.51c55d430
1.5.0-alpha.4a17a22c0
1.5.0-alpha.90415fad0
1.5.0-alpha.371bfa010
1.5.0-alpha.c53bbd6a0
1.5.0-alpha.cec794141
1.4.32
1.4.20
1.4.10
1.4.00
1.4.0-alpha.3a5400ae0
1.4.0-alpha.753be9380
1.3.00
1.3.0-alpha.c9e04a1e0
1.2.21
1.2.10
1.2.00
1.1.30
1.1.20
1.1.10
1.1.00
1.0.30
1.0.2-alpha.50a852221
1.0.20
1.0.10
1.0.01
1.0.0-alpha.70
1.0.0-alpha.31
1.0.0-alpha.21
1.0.0-alpha.10
1.0.0-alpha.00
0.6.0-alpha.cca3df5d0
0.6.0-alpha.52a568e60
0.6.0-alpha.93b48d620
0.6.0-alpha.a12f0f660
0.6.0-alpha.113744b90
0.6.0-alpha.0a7dd3530
0.6.0-alpha.7c8d6c0a0

Package Sidebar

Install

npm i @gql2ts/from-schema

Weekly Downloads

2,401

Version

2.0.0-4

License

ISC

Unpacked Size

22.7 kB

Total Files

5

Last publish

Collaborators

  • brandon.herman
  • brettjurgens