Skip to content

Commit

Permalink
Merge remote-tracking branch 'etalon/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
pugovok committed Jun 24, 2020
2 parents 505d5f7 + c1d9693 commit e925b16
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
4 changes: 4 additions & 0 deletions internal/exec/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func (r *Request) Subscribe(ctx context.Context, s *resolvable.Schema, op *query
}
}()

if f == nil {
return sendAndReturnClosed(&Response{Errors: []*errors.QueryError{err}})
}

if err != nil {
if _, nonNullChild := f.field.Type.(*common.NonNull); nonNullChild {
return sendAndReturnClosed(&Response{Errors: []*errors.QueryError{err}})
Expand Down
9 changes: 8 additions & 1 deletion internal/validation/testdata/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,13 @@
"query": "\n query Foo($a: String, $b: String, $c: String) {\n ... on Type {\n field(a: $a) {\n field(b: $b) {\n ... on Type {\n field(c: $c)\n }\n }\n }\n }\n }\n ",
"errors": []
},
{
"name": "Validate: fragments are used even when they are nested",
"rule": "NoUnusedFragments",
"schema": 1,
"query": "\n query Foo() {\n ...StringFragment\n stringBox {\n ...StringFragment\n ...StringFragmentPrime\n}\n}\n\n\n fragment StringFragment on StringBox {\n scalar\n}\n\n fragment StringFragmentPrime on StringBox {\n unrelatedField\n}\n",
"errors": []
},
{
"name": "Validate: No unused variables/uses all variables in fragments",
"rule": "NoUnusedVariables",
Expand Down Expand Up @@ -3853,4 +3860,4 @@
]
}
]
}
}
3 changes: 2 additions & 1 deletion internal/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,9 @@ func markUsedFragments(c *context, sels []query.Selection, fragUsed map[*query.F
}

if _, ok := fragUsed[frag]; ok {
return
continue
}

fragUsed[frag] = struct{}{}
markUsedFragments(c, frag.Selections, fragUsed)

Expand Down
34 changes: 34 additions & 0 deletions subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func (r *helloSaidResolver) HelloSaid(ctx context.Context) (chan *helloSaidEvent
return c, nil
}

func (r *rootResolver) OtherField(ctx context.Context) <-chan int32 {
return make(chan int32)
}

func (r *helloSaidEventResolver) Msg() (string, error) {
return r.msg, r.err
}
Expand Down Expand Up @@ -416,6 +420,36 @@ func TestRootOperations_validSubscriptionSchema(t *testing.T) {
})
}

func TestError_multiple_subscription_fields(t *testing.T) {
gqltesting.RunSubscribes(t, []*gqltesting.TestSubscription{
{
Name: "Explicit schema without subscription field",
Schema: graphql.MustParseSchema(`
schema {
query: Query
subscription: Subscription
}
type Query {
hello: String!
}
type Subscription {
helloSaid: HelloSaidEvent!
otherField: Int!
}
type HelloSaidEvent {
msg: String!
}
`, &rootResolver{helloSaidResolver: &helloSaidResolver{upstream: closedUpstream(&helloSaidEventResolver{msg: "Hello world!"})}}),
Query: `subscription { helloSaid { msg } otherField }`,
ExpectedResults: []gqltesting.TestResponse{
{
Errors: []*qerrors.QueryError{qerrors.Errorf("can subscribe to at most one subscription at a time")},
},
},
},
})
}

const schema = `
schema {
subscription: Subscription,
Expand Down

0 comments on commit e925b16

Please sign in to comment.