Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix isNullish to not consider an empty string as Null. #108

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -1270,8 +1270,7 @@ func (gl *List) Error() error {
* Note: the enforcement of non-nullability occurs within the executor.
*/
type NonNull struct {
PrivateName string `json:"name"` // added to conform with introspection for NonNull.Name = nil
OfType Type `json:"ofType"`
OfType Type `json:"ofType"`

err error
}
Expand Down
2 changes: 1 addition & 1 deletion executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestExecutesArbitraryCode(t *testing.T) {
"b": "Boring",
"c": []interface{}{
"Contrived",
nil,
"",
"Confusing",
},
"deeper": []interface{}{
Expand Down
48 changes: 48 additions & 0 deletions graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,51 @@ func TestThreadsContextFromParamsThrough(t *testing.T) {
}

}

func TestEmptyStringIsNotNull(t *testing.T) {
checkForEmptyString := func(p graphql.ResolveParams) (interface{}, error) {
arg := p.Args["arg"]
if arg == nil || arg.(string) != "" {
t.Errorf("Expected empty string for input arg, got %#v", arg)
}
return "yay", nil
}
returnEmptyString := func(p graphql.ResolveParams) (interface{}, error) {
return "", nil
}

schema, err := graphql.NewSchema(graphql.SchemaConfig{
Query: graphql.NewObject(graphql.ObjectConfig{
Name: "Query",
Fields: graphql.Fields{
"checkEmptyArg": &graphql.Field{
Type: graphql.String,
Args: graphql.FieldConfigArgument{
"arg": &graphql.ArgumentConfig{Type: graphql.String},
},
Resolve: checkForEmptyString,
},
"checkEmptyResult": &graphql.Field{
Type: graphql.String,
Resolve: returnEmptyString,
},
},
}),
})
if err != nil {
t.Fatalf("wrong result, unexpected errors: %v", err.Error())
}
query := `{ checkEmptyArg(arg:"") checkEmptyResult }`

result := graphql.Do(graphql.Params{
Schema: schema,
RequestString: query,
})
if len(result.Errors) > 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
expected := map[string]interface{}{"checkEmptyArg": "yay", "checkEmptyResult": ""}
if !reflect.DeepEqual(result.Data, expected) {
t.Errorf("wrong result, query: %v, graphql result diff: %v", query, testutil.Diff(expected, result))
}
}
Loading