forked from arsmn/fastgql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle colliding fields in complexity root gracefully
- Loading branch information
Adam Scarr
committed
Mar 14, 2019
1 parent
e497a5c
commit 23e4073
Showing
19 changed files
with
867 additions
and
470 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package codegen | ||
|
||
func (o *Object) UniqueFields() map[string]*Field { | ||
m := map[string]*Field{} | ||
|
||
for _, f := range o.Fields { | ||
m[f.GoFieldName] = f | ||
} | ||
|
||
return m | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
extend type Query { | ||
overlapping: OverlappingFields | ||
} | ||
|
||
type OverlappingFields { | ||
oneFoo: Int! | ||
twoFoo: Int! | ||
oldFoo: Int! | ||
newFoo: Int! | ||
new_foo: Int! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package testserver | ||
|
||
import ( | ||
"context" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/99designs/gqlgen/client" | ||
"github.com/99designs/gqlgen/handler" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestComplexityCollisions(t *testing.T) { | ||
resolvers := &Stub{} | ||
|
||
srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(Config{Resolvers: resolvers}))) | ||
c := client.New(srv.URL) | ||
|
||
resolvers.QueryResolver.Overlapping = func(ctx context.Context) (fields *OverlappingFields, e error) { | ||
return &OverlappingFields{ | ||
Foo: 2, | ||
NewFoo: 3, | ||
}, nil | ||
} | ||
|
||
resolvers.OverlappingFieldsResolver.OldFoo = func(ctx context.Context, obj *OverlappingFields) (i int, e error) { | ||
return obj.Foo, nil | ||
} | ||
|
||
var resp struct { | ||
Overlapping struct { | ||
OneFoo int `json:"oneFoo"` | ||
TwoFoo int `json:"twoFoo"` | ||
OldFoo int `json:"oldFoo"` | ||
NewFoo int `json:"newFoo"` | ||
New_foo int `json:"new_foo"` | ||
} | ||
} | ||
c.MustPost(`query { overlapping { oneFoo, twoFoo, oldFoo, newFoo, new_foo } }`, &resp) | ||
require.Equal(t, 2, resp.Overlapping.OneFoo) | ||
require.Equal(t, 2, resp.Overlapping.TwoFoo) | ||
require.Equal(t, 2, resp.Overlapping.OldFoo) | ||
require.Equal(t, 3, resp.Overlapping.NewFoo) | ||
require.Equal(t, 3, resp.Overlapping.New_foo) | ||
|
||
} |
Oops, something went wrong.