Absinthe: Schema.json is not stable

Created on 17 Jul 2019  路  8Comments  路  Source: absinthe-graphql/absinthe

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.

Most helpful comment

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

All 8 comments

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.

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).

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.

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

Would this lib be useful to you?

https://hex.pm/packages/absinthe_sorting_codec

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

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.

This is great @benwilson512 !!

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kenips picture kenips  路  4Comments

boxxxie picture boxxxie  路  5Comments

UnderFenex picture UnderFenex  路  3Comments

bruce picture bruce  路  4Comments

rawkode picture rawkode  路  4Comments