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

Consistent order of definitions in Schema::as_schema_language output #1134

Closed
nikis05 opened this issue Dec 21, 2022 · 5 comments · Fixed by #1237 or #1239
Closed

Consistent order of definitions in Schema::as_schema_language output #1134

nikis05 opened this issue Dec 21, 2022 · 5 comments · Fixed by #1237 or #1239
Assignees
Labels
area::introspection Related to GraphQL introspection enhancement Improvement of existing features or bugfix k::api Related to API (application interface)
Milestone

Comments

@nikis05
Copy link

nikis05 commented Dec 21, 2022

Definitions in SDL created by Schema::as_schema_language appear to be sorted semi randomly. We are using this method to print SDL to a file, and this behaviour makes changes to the schema harder to review, and to navigate the file in general.

Proposed solution

Sort definitions in the following order:

  1. Query type
  2. Mutation type, if any
  3. Subscription type, if any
  4. All other types, sorted alphabetically

Additional context

Currently, the order persists between compilations as long as there are no changes to schema, but a change to one item commonly results in multiple unrelated items changing their position.

@nikis05 nikis05 added the enhancement Improvement of existing features or bugfix label Dec 21, 2022
@scriptonist
Copy link

I can take a look at this and submit a patch if there are no objections.

@cloudsftp
Copy link

Could you kindly provide some code to reproduce this @nikis05 ?

I would like to start contributing to this amazing project and there seems to be no progress on this issue.

michael-groble added a commit to michael-groble/graphql-parser that referenced this issue Sep 3, 2023
adds pre-defined sorting options for a document to support printing a document in stable order.
possible start to graphql-rust/juniper#1134
@michael-groble
Copy link
Contributor

So this branch is an initial take at how to support this.

It adds the functionality to graphql-parser instead of here. All it does is sort the definitions so it could easily be moved here if the ordering is intended to be "juniper-specific".

Two sort orders are implemented, name-then-type (similar to the ordering in the github public schema) or type-then-name (examples of both types were added to the tests).

I believe the request is slightly different from the name-then-type option currently implemented. I think what is being requested is that we first look for the types referenced in the schema, print those three types first, then sort the remaining.

Would love to get a little feedback on the following before flushing this out completely:

  • whether to provide base ordering capabilities in graphql-parser or not. alternatives are:
    • control insertion order in GraphQLParserTranslator.translate_schema
    • control output order by sorting the generated document as this code does
  • spec out the sort order support in a little more detail
    • add a new ordering for putting the three "special" types first
    • value of keeping the type-then-name one or not
    • opinions on sort order for extensions and items with directives (the branch takes a stab at that)
    • whether sorting within any types are needed

@LegNeato
Copy link
Member

LegNeato commented Sep 13, 2023

I think output ordering is more flexible, no? It also makes it so lib users who aren't outputting to a file don't need to pay the overhead of sorting. What is easier in the code?

I think sort order should have some higher-level config. We don't need to do all variants, but whatever default we do will be "wrong" for a large portion of the population. I think there are probably only a few major options and it would be good to support the obvious ones.

Thoughts @tyranron ?

@tyranron
Copy link
Member

@michael-groble thank you for taking time on this and providing the possible solution.

I took your "type-then-name" approach and implementation in #1237 to ship it in the upcoming 0.16 release as a quick and working solution for this problem.

I suggest you to make a PR with your solution into graphql-parse library. And once it's released, we can switch to the one there.

@tyranron tyranron added k::api Related to API (application interface) and removed help wanted easy good-first-issue labels Jan 12, 2024
@tyranron tyranron self-assigned this Jan 12, 2024
@tyranron tyranron added this to the 0.16.0 milestone Jan 12, 2024
tyranron added a commit that referenced this issue Jan 15, 2024
- rename `RootNode::as_schema_language()` method as `RootNode::as_sdl()`
- rename `RootNode::as_parser_document()` method as `RootNode::as_document()`
- merge `graphql-parser` and `schema-language` Cargo features

Co-authored-by: Michael Groble <[email protected]>
@tyranron tyranron added the area::introspection Related to GraphQL introspection label Jan 17, 2024
@tyranron tyranron linked a pull request Jan 17, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area::introspection Related to GraphQL introspection enhancement Improvement of existing features or bugfix k::api Related to API (application interface)
Projects
None yet
6 participants