-
Notifications
You must be signed in to change notification settings - Fork 2.8k
export metadata without nulls, empty arrays & default values #3393
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
export metadata without nulls, empty arrays & default values #3393
Conversation
|
Deploy preview for hasura-docs ready! Built with commit 0ce0daa |
|
Review app for commit f2f582a deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com |
|
Review app for commit ebef155 deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com |
ebef155 to
4abd874
Compare
|
Review app for commit 4abd874 deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com |
4abd874 to
6fde5a8
Compare
|
Review app for commit 6fde5a8 deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com |
|
Review app for commit 08471ee deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com |
|
Review app for commit 70cf6c0 deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com |
|
Review app for commit 34c35fb deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com |
Resolve Conflicts: server/graphql-engine.cabal server/src-lib/Hasura/RQL/DDL/Metadata.hs
0500b8b to
4990d70
Compare
|
Review app for commit 4990d70 deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com |
lexi-lambda
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pretty much LGTM, just left a couple small comments.
| -- Functions enable encoding Metadata types and their dependants to ordered JSON | ||
|
|
||
| replaceMetadataToOrdJSON :: ReplaceMetadata -> AO.Value | ||
| replaceMetadataToOrdJSON ( ReplaceMetadata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you maybe add a short comment here about what invariants we maintain about order and why? It isn’t immediately clear to me just from reading the code what matters and what doesn’t.
My understanding is that we’re doing this so that metadata export is deterministic, so if you export the same thing twice, you get the same results. That makes complete sense, but it raises questions like: do we guarantee any consistency about ordering across versions of graphql-engine? If so, which invariants? And if not, it would be helpful to explicitly say so just so that people reading/modifying the code don’t worry about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deterministic export of metadata is already achieved via #3230. This PR intends to remove fields with []/null/defaults in exported metadata. And, the order of keys in an object is "hardcoded" using Data.Aeson.Ordered module since there's no way to determine the order of keys in Data.Aeson.
The CLI based developer experience needs the exported metadata should be precise and clean. The developer should be able to edit the exported YAML file and apply them. In an offline discussion between me, @coco98 and @arvi3411301 we decided the order of the keys in ReplaceMetadata, TableMeta etc. and the same followed here.
do we guarantee any consistency about ordering across versions of graphql-engine?
We do guarantee the order of keys in the exported metadata. I'll add the necessary description as comments.
I think there are 2 kinds of "order" we could consider.
- The order of items in an array. (solved in deterministic ordering of objects in exported metadata (close #3125) #3230)
- The order of keys in an object. (In this PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, thanks, that helps! I’ve tweaked the comment slightly to explicitly mention the fact that the ordering should be maintained across versions; feel free to change it if you think it should be worded differently.
Your note that the encoding should be roundtrippable got me wondering, though: do you think it would make sense to add some quickcheck tests to test that property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a quick check to test the property makes sense. I'll add them in next commit.
Edit 1:- To add a quick check, we need to defined generator Gen a for all ReplaceMetadata dependent types. A lot of code to write. Is there a way to generate Gen a with a simple template haskell or type class deriving?. I'm looking at the Hedgehog property testing package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To add a quick check, we need to defined generator
Gen afor allReplaceMetadatadependent types. A lot of code to write. Is there a way to generateGen awith a simple template haskell or type class deriving?. I'm looking at theHedgehogproperty testing package.
Good question. Neither QuickCheck nor hedgehog provide anything like that out of the box, since they (somewhat reasonably) point out that the choice of generator for each type is important for getting value out of the tests. That said, I think in many cases, you really do just want to use a generator that distributes over each field of a record type, for example.
The QuickCheck documentation links to two packages that can do that sort of thing: testing-feat and generic-random; I also found the generic-arbitrary package. In the hedgehog realm, there’s hedgehog-generic, but I’m skeptical of that package’s utility: hedgehog doesn’t have an Aribitrary class, so a generic generator is “deeply” generic. I can’t imagine that being what you want very often.
I don’t actually have a ton of experience using property-based testing for anything non-trivial, so I’m not sure what the right thing to do is here. Maybe @paf31 has some thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a lot of useful input here, but I think it would be nice to avoid adding many Arbitrary instances in the src-lib area of the code, especially when they'll probably end up being specific to this sort test. Instead, we can use genericArbitrary or some other method of getting values of type Gen a, entirely within the test suite, and then use the Testable a => Testable (Gen a) instance to pass the composed generator itself to quickCheck.
I'm not sure to what extent that is common knowledge or not, but it seemed worth mentioning.
Review request by @lexi-lambda
|
Review app for commit b1f6681 deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com |
|
Review app for commit e147c3b deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com |
e147c3b to
3847bca
Compare
|
Review app for commit 3847bca deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com |
Resolve Conflicts: server/src-lib/Hasura/Prelude.hs
|
Review app for commit 3271fd0 deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com |
lexi-lambda
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the extra effort getting the tests working!
|
Review app for commit ee99bbc deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com |
|
@rakeshkky Do you know why the CLI tests seem to think the working tree is dirty? |
|
Review app for commit 1672ed5 deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com |
19eb81f
|
Review app https://hge-ci-pull-3393.herokuapp.com is deleted |
|
Review app for commit 19eb81f deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com |
|
Review app for commit 0ce0daa deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com |
|
Review app https://hge-ci-pull-3393.herokuapp.com is deleted |
…3393) * export metadata without nulls, empty arrays * property tests for 'ReplaceMetadata' using QuickCheck -> Derive Arbitrary class for 'ReplaceMetadata' dependant types * reduce property test cases number to 30 QuickCheck generates the `ReplaceMetadata` value really large for higher number test cases. Encoded JSON for such values is large and consumes more memory. Thus, CI is giving up while running property tests. * circle-ci: Add property tests as saperate job * add no command mode to tests * add yaml.v2 to go mod * remove indirect comment for yaml.v2 dependency
Description
The response of
export_metadataquery API is simplified by omitting fields with an empty array, nulls and default values.Affected components
Related Issues
N/A
Solution and Design
Data.Aeson.Orderedto enable encoding JSON with orderHasura.RQL.DDL.MetadatatoHasura.RQL.DDL.Metadata.Types.Server checklist
Catalog upgrade
Does this PR change Hasura Catalog version?
Metadata
Does this PR add a new Metadata feature?
GraphQL
Breaking changes
Steps to test and verify
Limitations, known bugs & workarounds