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

schema-ast reorders parts of schema on each generation #4919

Closed
Eddman opened this issue Oct 16, 2020 · 6 comments
Closed

schema-ast reorders parts of schema on each generation #4919

Eddman opened this issue Oct 16, 2020 · 6 comments
Assignees
Labels
plugins waiting-for-release Fixed/resolved, and waiting for the next stable release

Comments

@Eddman
Copy link

Eddman commented Oct 16, 2020

Describe the bug
Our introspection query returns items in random order as the generation is asynchronous and rendered when calculated.
On the schema-ast side it just renders in that random order. That way our schema on the client side constantly changes.

With graphql@14 it was not an issue. With graphql@15 schema-ast does not do any post-processing and reshuffles generated schema.

To Reproduce
Steps to reproduce the behavior:

  1. My GraphQL schema:
N/A
  1. My GraphQL operations:
N/A
  1. My codegen.yml config file:
schema: https://.../graphql
overwrite: true
generates:
  ./src/schema.graphql:
    plugins:
      - schema-ast
    config:
      includeDirectives: true
      commentDescriptions: true

    # FIXME: remove this hook once https://github.com/dotansimha/graphql-code-generator/issues/4393 has been resolved.
    hooks:
      afterOneFileWrite:
        - sed -i -e ':a' -e 'N' -e '$!ba' -e 's/[ ]*""""""\n//g'

Expected behavior
Schema is ordered and does not change.

Environment:

  • OS: Linux
  • @graphql-codegen/schema-ast: ~1.17.8
  • NodeJS: v12.16.2

Additional context

@dotansimha
Copy link
Owner

That way our schema on the client side constantly changes.

The schema doesn't actually change, right? just the order of the items, based on the changes from the introspection.

Our introspection query

How do you save the introspection file?

@Eddman
Copy link
Author

Eddman commented Oct 20, 2020

The schema doesn't actually change, right? just the order of the items, based on the changes from the introspection.

Yes, only the order of generated items is changed.

How do you save the introspection file?

As you can see in our config: We download it from our endpoint over HTTPS and store it in ./src/schema.graphql using schema-ast. The HTTPS endpoint runs in more replicas behind a loadbalancer in cloud so even result of 2 calls generates differences in order of ./src/schema.graphql.

@dotansimha
Copy link
Owner

I see. Maybe we can use lexicographicSortSchema from graphlql-js to fix that, I'll take a look.

@dotansimha dotansimha added core Related to codegen core/cli enhancement plugins and removed bug plugins core Related to codegen core/cli labels Nov 4, 2020
@dotansimha dotansimha self-assigned this Nov 4, 2020
@dotansimha
Copy link
Owner

dotansimha commented Nov 4, 2020

@Eddman I implemented this in: #5034
You can try it with the alpha of that PR (@graphql-codegen/[email protected]). You need to add sort: true to your config.

@dotansimha dotansimha added the waiting-for-release Fixed/resolved, and waiting for the next stable release label Nov 4, 2020
@dotansimha
Copy link
Owner

Available in @graphql-codegen/[email protected].

@Eddman
Copy link
Author

Eddman commented Nov 5, 2020

@dotansimha Tested and can confirm it works as expected. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugins waiting-for-release Fixed/resolved, and waiting for the next stable release
Projects
None yet
Development

No branches or pull requests

2 participants