Graphql: Feature: Sort printed autoSchemaFile

Created on 24 Jun 2020  路  2Comments  路  Source: nestjs/graphql

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

When using the autoSchemaFile option the printed schema is not sorted. Additionally, when using forward references between modules the order of the generated schema is indeterminate since the order of instantiation is indeterminate. This causes the schema to possibly change every time the server (re)loads.

Expected behavior

I should be able to provide an option to the GraphQLModule to ensure that the printed schema is sorted.

Minimal reproduction of the problem with instructions

I have attempted to solve this issue with transformSchema:

import { GraphQLSchema, lexicographicSortSchema } from 'graphql';

...

GraphQLModule.forRoot({
    ...
    transformSchema: (schema: GraphQLSchema) => lexicographicSortSchema(schema),
});

This correctly and consistently orders the schema for introspection, etc. However transformSchema is not applied to the autoSchemaFile generation:

https://github.com/nestjs/graphql/blob/e13b51d9f97590b33d8b700ef3816f92a368d8f9/lib/graphql-schema.builder.ts#L74-L81

I am willing to submit a PR to resolve this issue, either by:

  • Applying transformSchema to the autoSchemaFile generation
  • Adding a boolean option to GraphQLModule to sort the schema (both for introspection, etc. and for autoSchemaFile)
  • Another direction you suggest

Thanks for Nest and for your guidance here! 馃憤

Environment


Nest version: 7.0.13

For Tooling issues:
- Node version: v14.3.0
- Platform:  Mac

enhancement

Most helpful comment

Applying transformSchema to the autoSchemaFile generation
Adding a boolean option to GraphQLModule to sort the schema (both for introspection, etc. and for autoSchemaFile)

I think both would be very useful! PRs are more than welcome :)

All 2 comments

Applying transformSchema to the autoSchemaFile generation
Adding a boolean option to GraphQLModule to sort the schema (both for introspection, etc. and for autoSchemaFile)

I think both would be very useful! PRs are more than welcome :)

@kamilmysliwiec I've pushed #996 to apply transformSchema when writing an autoSchemaFile. I can send a PR for a sort option later.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

galkin picture galkin  路  4Comments

cschroeter picture cschroeter  路  3Comments

vnenkpet picture vnenkpet  路  3Comments

liudonghua123 picture liudonghua123  路  3Comments

harm-less picture harm-less  路  4Comments