func TestNonNull_NullsTheFirstNullableObjectAfterAFieldReturnsNullInALongChainOfFieldsThatAreNonNull(t *testing.T) { doc := ` query Q { nest { nonNullNest { nonNullPromiseNest { nonNullNest { nonNullPromiseNest { nonNullSync } } } } } promiseNest { nonNullNest { nonNullPromiseNest { nonNullNest { nonNullPromiseNest { nonNullSync } } } } } anotherNest: nest { nonNullNest { nonNullPromiseNest { nonNullNest { nonNullPromiseNest { nonNullPromise } } } } } anotherPromiseNest: promiseNest { nonNullNest { nonNullPromiseNest { nonNullNest { nonNullPromiseNest { nonNullPromise } } } } } } ` expected := &graphql.Result{ Data: map[string]interface{}{ "nest": nil, "promiseNest": nil, "anotherNest": nil, "anotherPromiseNest": nil, }, Errors: []gqlerrors.FormattedError{ gqlerrors.FormattedError{ Message: `Cannot return null for non-nullable field DataType.nonNullSync.`, Locations: []location.SourceLocation{ location.SourceLocation{Line: 8, Column: 19}, }, }, gqlerrors.FormattedError{ Message: `Cannot return null for non-nullable field DataType.nonNullSync.`, Locations: []location.SourceLocation{ location.SourceLocation{Line: 19, Column: 19}, }, }, gqlerrors.FormattedError{ Message: `Cannot return null for non-nullable field DataType.nonNullPromise.`, Locations: []location.SourceLocation{ location.SourceLocation{Line: 30, Column: 19}, }, }, gqlerrors.FormattedError{ Message: `Cannot return null for non-nullable field DataType.nonNullPromise.`, Locations: []location.SourceLocation{ location.SourceLocation{Line: 41, Column: 19}, }, }, }, } // parse query ast := testutil.TestParse(t, doc) // execute ep := graphql.ExecuteParams{ Schema: nonNullTestSchema, AST: ast, Root: nullingData, } result := testutil.TestExecute(t, ep) if len(result.Errors) != len(expected.Errors) { t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors)) } if !reflect.DeepEqual(expected.Data, result.Data) { t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected.Data, result.Data)) } sort.Sort(gqlerrors.FormattedErrors(expected.Errors)) sort.Sort(gqlerrors.FormattedErrors(result.Errors)) if !reflect.DeepEqual(expected.Errors, result.Errors) { t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected.Errors, result.Errors)) } }
func TestNonNull_NullsAComplexTreeOfNullableFieldsThatThrow(t *testing.T) { doc := ` query Q { nest { sync promise nest { sync promise } promiseNest { sync promise } } promiseNest { sync promise nest { sync promise } promiseNest { sync promise } } } ` expected := &graphql.Result{ Data: map[string]interface{}{ "nest": map[string]interface{}{ "sync": nil, "promise": nil, "nest": map[string]interface{}{ "sync": nil, "promise": nil, }, "promiseNest": map[string]interface{}{ "sync": nil, "promise": nil, }, }, "promiseNest": map[string]interface{}{ "sync": nil, "promise": nil, "nest": map[string]interface{}{ "sync": nil, "promise": nil, }, "promiseNest": map[string]interface{}{ "sync": nil, "promise": nil, }, }, }, Errors: []gqlerrors.FormattedError{ gqlerrors.FormattedError{ Message: syncError, Locations: []location.SourceLocation{ location.SourceLocation{Line: 4, Column: 11}, }, }, gqlerrors.FormattedError{ Message: syncError, Locations: []location.SourceLocation{ location.SourceLocation{Line: 7, Column: 13}, }, }, gqlerrors.FormattedError{ Message: syncError, Locations: []location.SourceLocation{ location.SourceLocation{Line: 11, Column: 13}, }, }, gqlerrors.FormattedError{ Message: syncError, Locations: []location.SourceLocation{ location.SourceLocation{Line: 16, Column: 11}, }, }, gqlerrors.FormattedError{ Message: syncError, Locations: []location.SourceLocation{ location.SourceLocation{Line: 19, Column: 13}, }, }, gqlerrors.FormattedError{ Message: syncError, Locations: []location.SourceLocation{ location.SourceLocation{Line: 23, Column: 13}, }, }, gqlerrors.FormattedError{ Message: promiseError, Locations: []location.SourceLocation{ location.SourceLocation{Line: 5, Column: 11}, }, }, gqlerrors.FormattedError{ Message: promiseError, Locations: []location.SourceLocation{ location.SourceLocation{Line: 8, Column: 13}, }, }, gqlerrors.FormattedError{ Message: promiseError, Locations: []location.SourceLocation{ location.SourceLocation{Line: 12, Column: 13}, }, }, gqlerrors.FormattedError{ Message: promiseError, Locations: []location.SourceLocation{ location.SourceLocation{Line: 17, Column: 11}, }, }, gqlerrors.FormattedError{ Message: promiseError, Locations: []location.SourceLocation{ location.SourceLocation{Line: 20, Column: 13}, }, }, gqlerrors.FormattedError{ Message: promiseError, Locations: []location.SourceLocation{ location.SourceLocation{Line: 24, Column: 13}, }, }, }, } // parse query ast := testutil.TestParse(t, doc) // execute ep := graphql.ExecuteParams{ Schema: nonNullTestSchema, AST: ast, Root: throwingData, } result := testutil.TestExecute(t, ep) if len(result.Errors) != len(expected.Errors) { t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors)) } if !reflect.DeepEqual(expected.Data, result.Data) { t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected.Data, result.Data)) } sort.Sort(gqlerrors.FormattedErrors(expected.Errors)) sort.Sort(gqlerrors.FormattedErrors(result.Errors)) if !reflect.DeepEqual(expected.Errors, result.Errors) { t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected.Errors, result.Errors)) } }