gql2dts
A tool to parse graphql schema to typescript defs.
Installation
npm install gql2dts
Usage
fs.writeFileSync'/path/to/gql.d.ts', dts
Options
using option argument, you can set your code style.
now, there is a graphql file like:
enum Gender{ male female unknown}type User{ id: ID! name: String! gender: Gender}type Query{ user(id:ID!): User users: [User!]!}
enumType
tell parser program how to parse graphql enum type, default 'type'.
when enum
when type
objectType
tell parser how to parse graphql object type, default 'interface'.
when interface
:
when type
namespaceName
set namespace name of ts defs, default 'gql'
outputType
eh, this is only a string before namespace
//when 'declare'declare //when 'export'//when 'none'
argument2interface
to parse argument to interface ?
when true
and when false
customscalarTypes
set types for graphql scalar types, such as:
nullableType
when get nullable type, how to parse it?
// {object: type=>type+' | null' }// {object: type=>type }