Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate types #10

Open
pyramation opened this issue Oct 28, 2020 · 0 comments
Open

generate types #10

pyramation opened this issue Oct 28, 2020 · 0 comments

Comments

@pyramation
Copy link
Collaborator

pyramation commented Oct 28, 2020

    "@graphql-codegen/core": "^1.17.8",
    "@graphql-codegen/typescript": "^1.17.11",
    "get-graphql-schema": "^2.1.2"

in scripts

    "codegen": "cross-env NODE_ENV=development babel-node codegen",
    "schema:local": "get-graphql-schema http://my.dashboard.localhost:5555/graphql > schema.graphql"

./codegen.js:

import { codegen } from '@graphql-codegen/core';
import { join } from 'path';
import { buildSchema } from 'graphql';
import { readFileSync, writeFileSync } from 'fs';
import * as typescriptPlugin from '@graphql-codegen/typescript';
import { printSchema, parse } from 'graphql';

const schema = buildSchema(readFileSync('./schema.graphql', 'utf-8'));
const outputFile = 'output.ts';
const config = {
  // used by a plugin internally, although the 'typescript' plugin currently
  // returns the string output, rather than writing to a file
  filename: outputFile,
  schema: parse(printSchema(schema)),
  plugins: [
    // Each plugin should be an object
    {
      typescript: {} // Here you can pass configuration to the plugin
    }
  ],
  pluginMap: {
    typescript: typescriptPlugin
  }
};

(async () => {
  const output = await codegen(config);
  writeFileSync(join(__dirname, outputFile), output);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant