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.json is not stable #759

Closed
jfrolich opened this issue Jul 17, 2019 · 8 comments
Closed

Schema.json is not stable #759

jfrolich opened this issue Jul 17, 2019 · 8 comments

Comments

@jfrolich
Copy link
Contributor

The schema.json is not stable at the moment. Even if I order the object keys in the json file, it's not stable with the same schema. This means that arrays are not generated in the same order. Would be nice to have this for git checkins and docker cache busting.

@benwilson512
Copy link
Contributor

Yeah that's an understandably annoying problem. Fundamentally it comes down to the JSON library though since that's really where the order is lost, which is of course perfectly legal from the JSON spec.

@jfrolich
Copy link
Contributor Author

Hi @benwilson512, that's what I thought at first as well, but the list order is not the same for the same schema (and lists are ordered in JSON).

@jfrolich
Copy link
Contributor Author

Reproduce by:

cat schema.json | jq --sort-keys > schema-ordered.json

If you do that for two generated schema.json files and diff them they are not the same.

@jfrolich
Copy link
Contributor Author

I think it will be resolved by sorting the list of types (by for instance type name)

@maartenvanvliet
Copy link
Contributor

Would this lib be useful to you?

https://hex.pm/packages/absinthe_sorting_codec

@jfrolich
Copy link
Contributor Author

Ah great! Seems like somebody had the exact same problem, and solved it with a custom encoder. Thanks!

@jfrolich
Copy link
Contributor Author

This worked great. @benwilson512: You might want to consider adopting these few lines of code to stabilize the lists in the &Absinthe.Schema.introspect/1 function (or further down in the internals). This also makes the data structure stable. So introspected_schema_invocation_1 == introspected_query_invocation_2.

@fforres
Copy link

fforres commented Aug 15, 2019

This is great @benwilson512 !!

Thanks a lot for the work!
Can't wait for #769 🤘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants