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
and I return an instance of this, with "A" set and "B" nil
What did you expect?
I expect to get a GQL entity as follows:
{
a: "value"
}
What I actually get:
{
a: "value",
b: null
}
I would expect optional parameters that have nil values to not be returned at all -- they are optional.
This means that it's impossible to represent "this thing doesn't exist" and you cannot implement a discriminated union (other than the very clunky interface-based method.)
Minimal graphql.schema and models to reproduce
type Foo {
a: String
b: String
}
query {
getFoo: Foo
}
type Foo struct {
A *string
B *string
}
func (r *queryResolver) GetFoo(ctx context.Context) (*model.Foo, error) {
str := "foo"
return &model.Foo{A: &str}, nil
}
versions
go run github.com/99designs/gqlgen version?
v0.17.2
This discussion was converted from issue #2083 on April 08, 2022 17:52.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
What happened?
I have:
and this maps to go struct:
and I return an instance of this, with "A" set and "B" nil
What did you expect?
I expect to get a GQL entity as follows:
What I actually get:
I would expect optional parameters that have nil values to not be returned at all -- they are optional.
This means that it's impossible to represent "this thing doesn't exist" and you cannot implement a discriminated union (other than the very clunky interface-based method.)
Minimal graphql.schema and models to reproduce
versions
go run github.com/99designs/gqlgen version
?v0.17.2
go version
?go version go1.16.11 linux/amd64
Beta Was this translation helpful? Give feedback.
All reactions