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

allow graphql types and fields to be gated behind feature flags #69

Merged
merged 5 commits into from
Mar 16, 2024

Conversation

ccbrown
Copy link
Owner

@ccbrown ccbrown commented Mar 10, 2024

What it Does

This adds an API for specifying a set of required features for types and object and interface fields.

The set of enabled features is given as a parameter to GraphQL validation and execution.

Types and fields that require features which are not enabled effectively do not exist – queries containing them will not validate and they will not appear in introspection.

At schema compilation time, a set of rules is used to ensure that all possible combinations of enabled feature flags result in a perfectly valid schema:

  • Fields on interface implementations must require a subset of the features required by the corresponding interface field.
  • Objects and interfaces must always contain at least one field whose feature requirements are a subset of their own.
  • Field types must never require features that aren't required by the field itself.
  • Field argument types must never require features that aren't required by the field itself.

This functionality is closely related to the proposal in the GraphQL RFC for Opt-in features and discussion happening in graphql/graphql-spec#943.

Limitations:

This PR doesn't support:

  • Union members which require features not required by the union.
  • Feature flagged input object fields.
  • Feature flagged field arguments.
  • Feature flagged enum values.

These may be added in a future PR.

Steps to Test

go test -v ./...

Copy link

codecov bot commented Mar 10, 2024

Codecov Report

Attention: Patch coverage is 76.13636% with 21 lines in your changes are missing coverage. Please review.

Project coverage is 79.85%. Comparing base (c289cff) to head (9b98469).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #69      +/-   ##
==========================================
+ Coverage   79.61%   79.85%   +0.24%     
==========================================
  Files          62       63       +1     
  Lines        5042     5088      +46     
==========================================
+ Hits         4014     4063      +49     
+ Misses        681      680       -1     
+ Partials      347      345       -2     
Files Coverage Δ
api.go 84.67% <100.00%> (+5.16%) ⬆️
cmd/gql-client-gen/main.go 64.56% <100.00%> (ø)
config.go 83.75% <ø> (ø)
graphql/executor/executor.go 71.14% <100.00%> (+0.24%) ⬆️
graphql/schema/enum_type.go 73.07% <100.00%> (+1.07%) ⬆️
graphql/schema/feature_set.go 100.00% <100.00%> (ø)
graphql/schema/introspection/introspection.go 93.19% <100.00%> (-0.04%) ⬇️
graphql/schema/list_type.go 79.06% <100.00%> (+0.49%) ⬆️
graphql/schema/nonnull_type.go 91.30% <100.00%> (+0.39%) ⬆️
graphql/schema/scalar_type.go 100.00% <100.00%> (ø)
... and 20 more

... and 1 file with indirect coverage changes

@ccbrown ccbrown changed the title allow graphql fields to be gated behind feature flags allow graphql types and fields to be gated behind feature flags Mar 10, 2024
@ccbrown ccbrown marked this pull request as ready for review March 16, 2024 02:32
@ccbrown ccbrown merged commit 66fc90e into main Mar 16, 2024
2 checks passed
@ccbrown ccbrown deleted the graphql-features branch March 16, 2024 02:32
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 this pull request may close these issues.

None yet

1 participant