Skip to content

Commit 8334863

Browse files
authored
Merge pull request graph-gophers#374 from willnewrelic/operationName-from-query
Use operationName from query if missing from POST
2 parents f33e813 + d51b8b3 commit 8334863

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

graphql.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,19 @@ func (s *Schema) exec(ctx context.Context, queryString string, operationName str
182182
return &Response{Errors: []*errors.QueryError{errors.Errorf("%s", err)}}
183183
}
184184

185+
// If the optional "operationName" POST parameter is not provided then
186+
// use the query's operation name for improved tracing.
187+
if operationName == "" {
188+
operationName = op.Name.Name
189+
}
190+
185191
// Subscriptions are not valid in Exec. Use schema.Subscribe() instead.
186192
if op.Type == query.Subscription {
187-
return &Response{Errors: []*errors.QueryError{&errors.QueryError{ Message: "graphql-ws protocol header is missing" }}}
193+
return &Response{Errors: []*errors.QueryError{&errors.QueryError{Message: "graphql-ws protocol header is missing"}}}
188194
}
189195
if op.Type == query.Mutation {
190196
if _, ok := s.schema.EntryPoints["mutation"]; !ok {
191-
return &Response{Errors: []*errors.QueryError{{ Message: "no mutations are offered by the schema" }}}
197+
return &Response{Errors: []*errors.QueryError{{Message: "no mutations are offered by the schema"}}}
192198
}
193199
}
194200

0 commit comments

Comments
 (0)