graphql-to-typescript
Takes a glob of GraphQL files and writes a typescript module that exports the graphql type definitions as a string array and converts the graphql types to interfaces.
Last updated 3 years ago by threevl .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install graphql-to-typescript 
SYNC missed versions from official npm registry.

GraphQL To Typescript

Takes a glob of GraphQL files and writes a typescript module that exports the graphql type definitions as a string array and converts the graphql types to interfaces.

Usage: graphql-to-typescript \[options\] \<graphqlFileGlob\> \<outputFile\>

  Options:

    -h, --help  output usage information

Converts graphql files such as:

schema {
  query: RootQuery
}
type RootQuery {
  user(id: Int!): User
}
type User {
  id: Int!
  name: String
}

Into the typescript file:

export const typeDefs = ["schema {\n  query: RootQuery\n}\ntype RootQuery {\n  user(id: Int!): User\n}\ntype User {\n  id: Int!\n  name: String\n}\n"];

export interface RootQuery {
  user: User | null;
}

export interface UserRootQueryArgs {
  id: number;
}

export interface User {
  id: number;
  name: string | null;
}

This allows you to import the interfaces and the schema elsewhere in your typescript project and use them in your resolvers.

Current Tags

  • 0.1.2                                ...           latest (3 years ago)

3 Versions

  • 0.1.2                                ...           3 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 3
Last Month 0
Dependencies (6)
Dev Dependencies (11)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |