Skip to content

Make the result of fragment-matcher deterministic #7367

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

Closed
filipcro opened this issue Jan 14, 2022 · 3 comments
Closed

Make the result of fragment-matcher deterministic #7367

filipcro opened this issue Jan 14, 2022 · 3 comments
Assignees
Labels
core Related to codegen core/cli kind/enhancement New feature or request plugins

Comments

@filipcro
Copy link

Is your feature request related to a problem? Please describe.

Hi. We have a repo where multiple developers are working on the same project. In the same repo result of fragment-matcher is saved to .json and committed. The thing that happens is that every time somebody generates this file, values in possible type arrays are sorted differently. I.e.

    "ConfirmEmailResponse": [
       "SuccessPayload",
-      "EmailDoesNotExists",
-      "InvalidToken"
+      "InvalidToken",
+      "EmailDoesNotExists"
    ],

Describe the solution you'd like

Have an option to sort values in possible type arrays alphabetical.

This shouldn't be hard to do. We just need to add .sort() in this file. I can create MR if you approve of this, but I need to know will this be optional feature, and how would opt in look like in config file.

@charlypoly
Copy link
Contributor

Hi @filipcro,

This could definitely be a new optional configuration option to the fragment-matcher plugin. ⚡

Let me know when your PR is ready and I'll review it.

@charlypoly charlypoly self-assigned this Mar 10, 2022
@charlypoly charlypoly added kind/enhancement New feature or request plugins labels Mar 10, 2022
@charlypoly charlypoly added the core Related to codegen core/cli label Nov 3, 2022
tgandrews added a commit to tgandrews/graphql-code-generator that referenced this issue Dec 8, 2024
This exposes a new plugin option `deterministic` that when enabled will
ensure that the fragment matcher will always return the same result for
the same schema, no matter the order it is in the schema.

It does this by sorting the results so that they are always in the same
order.

The default is `false` to maintain backwards compatibility.

This fixes dotansimha#7367
@tgandrews
Copy link
Contributor

@charlypoly This has been done in #10214 are you still up for reviewing it 🙏

@eddeee888
Copy link
Collaborator

Hello @tgandrews , I can take a look soon 🙂 Thanks!

@eddeee888 eddeee888 assigned eddeee888 and unassigned charlypoly Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to codegen core/cli kind/enhancement New feature or request plugins
Projects
None yet
Development

No branches or pull requests

4 participants