graphql-go / graphql-go/graphql

I want receive a empty string on mutation

Open
#183 16 comments 6 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
10.1k
Forks
845
PR merge metrics
No merged PRs in 30d

Description

Hi guys,

I have a follow mutation structure:

```go
var userType = graphql.NewObject(graphql.ObjectConfig{
Name: "User",
Fields: graphql.Fields{
"id": &graphql.Field{Type: graphql.String},
"name": &graphql.Field{Type: graphql.String},
"gender": &graphql.Field{Type: graphql.String},
},
})

func mutation() *graphql.Object {
return graphql.NewObject(graphql.ObjectConfig{
Name: "mutation",
Fields: graphql.Fields{
"update": &graphql.Field{
Type: userType,
Description: "Mutation to update a user",
Args: graphql.FieldConfigArgument{
"id": &graphql.ArgumentConfig{
Type: graphql.NewNonNull(graphql.String),
},
"name": &graphql.ArgumentConfig{
Type: graphql.String,
DefaultValue: "",
},
"gender": &graphql.ArgumentConfig{
Type: graphql.String,
DefaultValue: "",
},
},
Resolve: SomeResolver,
},
},
})
}
```

I want to make a query with empty string, like this:
`mutation { update(id:"abc", name: "New name", gender: "") {id}}`

Is it possible?

The following function in file `value.go` does the validation:
```
// Returns true if a value is null, undefined, or NaN.
func isNullish(value interface{}) bool {
if value, ok := value.(string); ok {
return value == ""
}
if value, ok := value.(int); ok {
return math.IsNaN(float64(value))
}
if value, ok := value.(float32); ok {
return math.IsNaN(float64(value))
}
if value, ok := value.(float64); ok {
return math.IsNaN(value)
}
return value == nil
}
```

Thanks

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.