dotansimha / dotansimha/graphql-code-generator

In programmatic usage docs, "each plugin should be an object" needs clarification

Open
#5,452 0 comments 6 reactions 0 assignees View on GitHub
core docs
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

```
import { buildSchema } from 'graphql';
import * as fs from 'fs';
import * as typescriptPlugin from '@graphql-codegen/typescript';
import { printSchema, parse, GraphQLSchema } from 'graphql';

const schema: GraphQLSchema = buildSchema(`type A {}`);
const outputFile = 'relative/pathTo/filename.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,
},
};
```

I did this and it took some time to realize what I was doing wrong:

```
plugins: [ // Each plugin should be an object
{
typescript: {}, // Here you can pass configuration to the plugin
foo: {},
},
],
```

An example with two plugins should be in the docs.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.