question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow schemaPrinter to be customized / extended.

See original GitHub issue

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:


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,
    );
}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
spawniacommented, Nov 7, 2021

How about we add a config option:

printDirectives: (definition: GraphQLType|GraphQLField|GraphQLEnumValue|GraphQLInputField|GraphQLArgument) => string

Whenever a definition that can hold directives is encountered, the given function would be called with it and is free to print any directives.

4reactions
mpiroccommented, Jan 1, 2020

@IvanGoncharov What if printSchema only printed directives that were not visited during schema construction? Using your example:

type Foo {
  foo: String
}

type Bar @copyFields(fromType: "Foo") {
  bar: String
}
// 1
printSchema(makeExecutableSchema({
    typeDefs,
    schemaDirectives: {
        copyFields: CopyFieldsVisitor
    }
}))

// 2
printSchema(makeExecutableSchema({
    typeDefs,
    schemaDirectives: {
    }
}))

The first snippet would print:

type Foo {
  foo: String
}

type Bar {
  foo: String
  bar: String
}

The second would print:

type Foo {
  foo: String
}

type Bar @copyFields(fromType: "Foo") {
  bar: String
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

SchemaPrinter.Options (graphql-java 9.5 API) - javadoc.io
This will allow you to include the graphql 'extended' scalar types that come with graphql-java such as GraphQLBigDecimal or GraphQLBigInteger. SchemaPrinter ...
Read more >
leangen/graphql-spqr - Gitter
I'm trying to create a GraphQL Gateway, which will accept these Dtos and ... Expected Schema extend type NotificationDto { recipients: [UserDto] }...
Read more >
How to get the generated scheme file .graphqls using SPQR?
Is there a way to generate the scheme file from an existing code with SPQR annotations integrated? To provide some code let's use...
Read more >
Class: GraphQL::Schema — GraphQL Ruby API Documentation
Extend this class to define GraphQL enums in your schema. ... You can provide a custom value with the value: keyword. Examples:
Read more >
Custom scalars - Apollo GraphQL Docs
To enable this, you can define custom scalar types. Defining a custom scalar. To define a custom scalar, add it to your schema...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found