99designs / gqlgen

go generate based graphql server library
https://gqlgen.com
MIT License
9.9k stars 1.15k forks source link

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

Closed clayne11 closed 2 weeks ago

clayne11 commented 2 weeks ago

The explicit_requires flag currently 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.

The new implementation still isn't typesafe and generates the required fields into a map[string]any. This is the same as the existing explicit_requires implementation.

We will follow up with type safety in a future PR. To support type safety we need to generate types and marshaling logic for GraphQL operations (vs just schemas like we do today) which is a large lift.

I have:

coveralls commented 2 weeks ago

Coverage Status

coverage: 58.813% (-0.7%) from 59.525% when pulling 0508cef666c05a7e13993f2479965de2000f1ced on uber:curtis.layne/requires-no-types into e81a38771e163114ec0fd8ebad65efe6d1c94677 on 99designs:master.