graphql / graphql/graphql-js

Allow schemaPrinter to be customized / extended.

Open
#2,020 12 comments 8 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
20.3k
Forks
2.1k
Avg merge
44m
Merged PRs (30d)
6

Description

Some libraries are having to copy the schemaPrinter code to do custom stuff to the output, (`@apollo/federation`, `type-graphql`). These libraries require outputting type and field level directives since this isn't supported in this library. Is there any support to do so, or can the schemPrinter just export the other functions so we don't have to copy every function or, even better, create a SchemaPrinter class so everything can be over-ridden, then `printSchema` options can set the printer for BC:

```javascript

type Options = {
commentDescriptions?: boolean,
printer?: SchemaPrinter
};

const defaultPrinter = new SchemaPrinter();

export function printSchema(schema: GraphQLSchema, options?: Options): string {
const printer = options.printer || defaultPrinter;

return printer.print(
schema,
n => !isSpecifiedDirective(n),
isDefinedType,
options,
);
}

export function printIntrospectionSchema(
schema: GraphQLSchema,
options?: Options,
): string {
const printer = options.printer || defaultPrinter;

return printer.print(
schema,
isSpecifiedDirective,
isIntrospectionType,
options,
);
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.