Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@gql2ts/from-query

Package Overview
Dependencies
Maintainers
2
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gql2ts/from-query

generate typescript interfaces from a graphql schema and query

  • 2.0.0-4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

@gql2ts/from-query

This package is used to generate types/interfaces from a GraphQL Schema and a query.

Objective

Pass a GraphQL type schema to generate a TypeScript interface:

Input:

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

Output:

interface IQuery {
  thing: string;
  anotherThing: boolean;
}

Basic Usage

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

const typescriptDefinitions = fromQuery(schema, query);

const allDefinitions = typescriptDefinitions.map(({ result }) => result).join('\n');

fs.writeFile('definition.d.ts', allDefinitions);

Advanced Usage

import fromQuery from '@gql2ts/from-query';
import { schema, query } from 'my-graphql-stuff';
// see `IOptions` in `types.ts` for options
import * as options from './customFormatters';
import * as fs from 'fs';

const myCustomTypes = {
  Date: 'string',
  Map: 'object',
}

const typescriptDefinitions = fromQuery(schema, query, myCustomTypes, options);

const allDefinitions = typescriptDefinitions.map(({ result }) => result).join('\n');

fs.writeFile('definition.d.ts', allDefinitions);

Keywords

FAQs

Package last updated on 13 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc