You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#2884 landed recently to add support for nested selection sets in @requires directives. This implementation isn't great, however. There are three significant gaps:
The resolved fields are rendered as a map[string]interface{}. We know the types for this model, however, from the schema. We should be generating a typesafe model for these fields.
I would expect a separate resolver function to be generated for each @requires field since they should be treated like independently derived fields, at least in my opinion.
There's no way to access any errors that occurred when fetching the upstream fields. This is important because an upstream error can mean something very different from null. For example, if I’m trying to compute driverName and do @requires(fields: "driver { name }" and driver comes back null due to an error the correct response might be to throw an error and return null, but if the driver is truly null I might return “No driver assigned”.
This would meet all of the requirements from above:
I have type safety for my inputs.
The fields I'm @requires-ing are treated independently.
I can distinguish upstream errors from null values.
versions
Running on master of gqlgen
Changes to the Federation specification
This will also require an extension to the Federation specification to actually forward the errors to the gqlgen server. This could look something like this on the wire:
{
"query": "query ($representations: [_Any!]!) {\n _entities(representations: $representations) {\n ... on GeoLocation {\n latitude\n longitude\n }\n }\n}",
"variables": {
"representations": [
{
"__typename": "GeoLocation",
"name": "Foo",
"bar": "First"
},
{
"__typename": "GeoLocation",
"name": "Blah",
"bar": null
},
{
"__typename": "GeoLocation",
"name": null,
"bar": null
}
]
},
"extensions": {
"representations": [
{
"errors": []
},
{
"errors": [
{
"message": "Couldn't fetch bar due to an error",
"path": [
"bar"
]
}
]
},
{
"errors": [
{
"errors": [
// no error for "bar" since it was actually null, not null due to an error
{
"message": "Couldn't fetch foo due to an error",
"path": [
"foo"
]
}
]
}
]
}
]
}
}
We add representations an array in extensions that mirrors the representations array. Each entry in the array maps by index to the entry in the representations array.
The text was updated successfully, but these errors were encountered:
What happened?
#2884 landed recently to add support for nested selection sets in
@requires
directives. This implementation isn't great, however. There are three significant gaps:map[string]interface{}
. We know the types for this model, however, from the schema. We should be generating a typesafe model for these fields.@requires
field since they should be treated like independently derived fields, at least in my opinion.null
. For example, if I’m trying to computedriverName
and do@requires(fields: "driver { name }"
anddriver
comes backnull
due to an error the correct response might be to throw an error and returnnull
, but if thedriver
is trulynull
I might return “No driver assigned”.Example
From the tests:
Current generated code:
What did you expect?
In an ideal world, I would like to see something like the following be generated:
This would meet all of the requirements from above:
versions
Running on
master
ofgqlgen
Changes to the Federation specification
This will also require an extension to the Federation specification to actually forward the errors to the
gqlgen
server. This could look something like this on the wire:We add
representations
an array in extensions that mirrors therepresentations
array. Each entry in the array maps by index to the entry in therepresentations
array.The text was updated successfully, but these errors were encountered: