Skip to content

Commit

Permalink
feat: create @requires integration that functions like a normal resol…
Browse files Browse the repository at this point in the history
…ver (#3292)

* feat: create @requires integration that functions like a normal resolver

The "explicit_requires" flag current generates the @requires resolver inside the execution context. It also doesn't use the normal resolver resolution process and adds a custom implementation that is always called, even if the field isn't requested.

The new "computed_requires" flag looks for @requires directives and mutates the schema to add dynamic field arguments and directives that are used internally by gqlgen.

These additional directives (@entityReference and @populateFromRepresentations) are runtime directives that "computed_requires" adds implementations for that enable us to fetch the correct data from the representations array and populated it into the dynamic argument for the @requires field.

* Add mechanism for supporting statically provided directive implementations.

* Get @populateFromRepresentations working

* Add tests for computedrequires

* Update documentation

* Ensure everyone that should be is using version 2

* Fix linter issues
  • Loading branch information
clayne11 committed Sep 18, 2024
1 parent e81a387 commit b020c09
Show file tree
Hide file tree
Showing 49 changed files with 13,533 additions and 1,221 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ issues:
- path: codegen/testserver/.*/resolver\.go
linters:
- gocritic
# The interfaces are autogenerated and don't conform to the paramTypeCombine rule
- path: _examples/federation/products/graph/entity.resolvers.go
linters:
- gocritic
# Disable revive.use-any for backwards compatibility
- path: graphql/map.go
text: "use-any: since GO 1.18 'interface{}' can be replaced by 'any'"
Expand Down
1 change: 1 addition & 0 deletions _examples/federation/accounts/gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exec:

federation:
filename: graph/federation.go
version: 2
package: graph

# Where should any generated models go?
Expand Down
1 change: 1 addition & 0 deletions _examples/federation/accounts/graph/entity.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

278 changes: 258 additions & 20 deletions _examples/federation/accounts/graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions _examples/federation/products/gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exec:

federation:
filename: graph/federation.go
version: 2
package: graph

# Where should any generated models go?
Expand Down Expand Up @@ -66,3 +67,5 @@ models:
- github.com/99designs/gqlgen/graphql.Int
- github.com/99designs/gqlgen/graphql.Int64
- github.com/99designs/gqlgen/graphql.Int32

omit_complexity: true
Loading

0 comments on commit b020c09

Please sign in to comment.