Skip to content

Commit

Permalink
Merge pull request #374 from willnewrelic/operationName-from-query
Browse files Browse the repository at this point in the history
Use operationName from query if missing from POST
  • Loading branch information
pavelnikolov authored Feb 7, 2020
2 parents f33e813 + d51b8b3 commit 8334863
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,19 @@ func (s *Schema) exec(ctx context.Context, queryString string, operationName str
return &Response{Errors: []*errors.QueryError{errors.Errorf("%s", err)}}
}

// If the optional "operationName" POST parameter is not provided then
// use the query's operation name for improved tracing.
if operationName == "" {
operationName = op.Name.Name
}

// Subscriptions are not valid in Exec. Use schema.Subscribe() instead.
if op.Type == query.Subscription {
return &Response{Errors: []*errors.QueryError{&errors.QueryError{ Message: "graphql-ws protocol header is missing" }}}
return &Response{Errors: []*errors.QueryError{&errors.QueryError{Message: "graphql-ws protocol header is missing"}}}
}
if op.Type == query.Mutation {
if _, ok := s.schema.EntryPoints["mutation"]; !ok {
return &Response{Errors: []*errors.QueryError{{ Message: "no mutations are offered by the schema" }}}
return &Response{Errors: []*errors.QueryError{{Message: "no mutations are offered by the schema"}}}
}
}

Expand Down

0 comments on commit 8334863

Please sign in to comment.