这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@rakeshkky
Copy link
Member

@rakeshkky rakeshkky commented Nov 21, 2019

Description

The response of export_metadata query API is simplified by omitting fields with an empty array, nulls and default values.

Affected components

  • Server
  • Console
  • CLI
  • Docs
  • Community Content
  • Build System
  • Tests
  • Other (list it)

Related Issues

N/A

Solution and Design

  • A brand new module Data.Aeson.Ordered to enable encoding JSON with order
  • Separate functions to encode the metadata types to ordered JSON.
  • Move types from Hasura.RQL.DDL.Metadata to Hasura.RQL.DDL.Metadata.Types.

Server checklist

Catalog upgrade

Does this PR change Hasura Catalog version?

  • No
  • Yes

Metadata

Does this PR add a new Metadata feature?

  • No
  • Yes

GraphQL

  • No new GraphQL schema is generated
  • New GraphQL schema is being generated:

Breaking changes

  • No Breaking changes
  • There are breaking changes:

Steps to test and verify

Limitations, known bugs & workarounds

@netlify
Copy link

netlify bot commented Nov 21, 2019

Deploy preview for hasura-docs ready!

Built with commit 0ce0daa

https://deploy-preview-3393--hasura-docs.netlify.com

@hasura-bot
Copy link
Contributor

Review app for commit f2f582a deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3393-f2f582a6

@hasura-bot
Copy link
Contributor

Review app for commit ebef155 deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3393-ebef1556

@rakeshkky rakeshkky force-pushed the serdy-no-nulls-defaults branch from ebef155 to 4abd874 Compare November 25, 2019 08:16
@hasura-bot
Copy link
Contributor

Review app for commit 4abd874 deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3393-4abd8743

@rakeshkky rakeshkky force-pushed the serdy-no-nulls-defaults branch from 4abd874 to 6fde5a8 Compare November 25, 2019 08:34
@hasura-bot
Copy link
Contributor

Review app for commit 6fde5a8 deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3393-6fde5a81

@hasura-bot
Copy link
Contributor

Review app for commit 08471ee deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3393-08471ee9

@hasura-bot
Copy link
Contributor

Review app for commit 70cf6c0 deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3393-70cf6c0d

@hasura-bot
Copy link
Contributor

Review app for commit 34c35fb deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3393-34c35fb4

@rakeshkky rakeshkky changed the title export metadata without nulls, empty arrays export metadata without nulls, empty arrays & default values Dec 2, 2019
@rakeshkky rakeshkky force-pushed the serdy-no-nulls-defaults branch from 0500b8b to 4990d70 Compare December 2, 2019 13:34
@hasura-bot
Copy link
Contributor

Review app for commit 4990d70 deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3393-4990d70d

@rakeshkky rakeshkky marked this pull request as ready for review December 2, 2019 14:26
Copy link
Contributor

@lexi-lambda lexi-lambda left a 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
Copy link
Contributor

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.

Copy link
Member Author

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.

  1. The order of items in an array. (solved in deterministic ordering of objects in exported metadata (close #3125) #3230)
  2. The order of keys in an object. (In this PR)

Copy link
Contributor

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?

Copy link
Member Author

@rakeshkky rakeshkky Dec 4, 2019

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.

Copy link
Contributor

@lexi-lambda lexi-lambda Dec 4, 2019

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

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?

Copy link
Contributor

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
@hasura-bot
Copy link
Contributor

Review app for commit b1f6681 deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3393-b1f66816

@hasura-bot
Copy link
Contributor

Review app for commit e147c3b deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3393-e147c3bc

@rakeshkky rakeshkky force-pushed the serdy-no-nulls-defaults branch from e147c3b to 3847bca Compare December 11, 2019 08:00
@hasura-bot
Copy link
Contributor

Review app for commit 3847bca deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3393-3847bcae

@hasura-bot
Copy link
Contributor

Review app for commit 3271fd0 deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3393-3271fd0a

lexi-lambda
lexi-lambda previously approved these changes Dec 11, 2019
Copy link
Contributor

@lexi-lambda lexi-lambda left a 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!

@hasura-bot
Copy link
Contributor

Review app for commit ee99bbc deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3393-ee99bbc2

shahidhk
shahidhk previously approved these changes Dec 12, 2019
@lexi-lambda
Copy link
Contributor

@rakeshkky Do you know why the CLI tests seem to think the working tree is dirty?

@hasura-bot
Copy link
Contributor

Review app for commit 1672ed5 deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3393-1672ed5b

@arvi3411301 arvi3411301 dismissed stale reviews from shahidhk and lexi-lambda via 19eb81f December 13, 2019 11:23
@rakeshkky rakeshkky closed this Dec 13, 2019
@rakeshkky rakeshkky reopened this Dec 13, 2019
@hasura-bot
Copy link
Contributor

Review app https://hge-ci-pull-3393.herokuapp.com is deleted

@hasura-bot
Copy link
Contributor

Review app for commit 19eb81f deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3393-19eb81fb

@hasura-bot
Copy link
Contributor

Review app for commit 0ce0daa deployed to Heroku: https://hge-ci-pull-3393.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3393-0ce0daa0

@lexi-lambda lexi-lambda merged commit 421a182 into hasura:master Dec 14, 2019
@hasura-bot
Copy link
Contributor

Review app https://hge-ci-pull-3393.herokuapp.com is deleted

polRk pushed a commit to polRk/graphql-engine that referenced this pull request Feb 12, 2020
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c/cli Related to CLI c/server Related to server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants