diff --git a/subscription_test.go b/subscription_test.go index 20a4d618..803ee159 100644 --- a/subscription_test.go +++ b/subscription_test.go @@ -130,7 +130,7 @@ func TestSchemaSubscribe(t *testing.T) { }, }, { - Name: "subscribe_to_query_errors", + Name: "subscribe_to_query_succeeds", Schema: graphql.MustParseSchema(schema, &rootResolver{}), Query: ` query Hello { @@ -139,7 +139,11 @@ func TestSchemaSubscribe(t *testing.T) { `, ExpectedResults: []gqltesting.TestResponse{ { - Errors: []*qerrors.QueryError{qerrors.Errorf("%s: %s", "subscription unavailable for operation of type", "QUERY")}, + Data: json.RawMessage(` + { + "hello": "Hello world!" + } + `), }, }, }, diff --git a/subscriptions.go b/subscriptions.go index 2c1731bd..a78aa765 100644 --- a/subscriptions.go +++ b/subscriptions.go @@ -44,11 +44,6 @@ func (s *Schema) subscribe(ctx context.Context, queryString string, operationNam return sendAndReturnClosed(&Response{Errors: []*qerrors.QueryError{qerrors.Errorf("%s", err)}}) } - // TODO: Move to validation.Validate? - if op.Type != query.Subscription { - return sendAndReturnClosed(&Response{Errors: []*qerrors.QueryError{qerrors.Errorf("%s: %s", "subscription unavailable for operation of type", op.Type)}}) - } - r := &exec.Request{ Request: selected.Request{ Doc: doc, @@ -68,6 +63,11 @@ func (s *Schema) subscribe(ctx context.Context, queryString string, operationNam varTypes[v.Name.Name] = introspection.WrapType(t) } + if op.Type == query.Query || op.Type == query.Mutation { + data, errs := r.Execute(ctx, res, op) + return sendAndReturnClosed(&Response{Data: data, Errors: errs}) + } + responses := r.Subscribe(ctx, res, op) c := make(chan *Response) go func() {