Urql: operationName is never set by fetchExchange

Created on 21 Aug 2019  路  4Comments  路  Source: FormidableLabs/urql

Describe the bug
When executing a query via urql, our graphql server (apollo) is not receiving an operationName. When using the apollo playground, even individual queries have an operationName computed.

I understand that operationName is only required for multiple operations in a query (as per https://graphql.org/learn/serving-over-http/#post-request) but from my experience, even multiple queries inside a transaction isn't setting it.

Steps to reproduce
Steps to reproduce the behavior:

  1. Create an apollo graphql server
  2. As part of it, create an extension (such as this one) and consume it in the extensions of apollo config
import { GraphQLExtension } from 'graphql-extensions';

export default class CustomExtension extends GraphQLExtension {
  requestDidStart({ operationName }) {
    console.log(`operation name is "${operationName}"`);
  }
}
  1. fire a call to the apollo server and you observe the server console

Expected behavior
The operationName should be picked intelligently such as the name of the query being executed (as apollo client does)

Actual behavior
The operationName parameter is undefined

Additional context
n/a

Most helpful comment

@kitten / @JoviDeCroock you guys are awesome, thanks for the speedy response!

All 4 comments

Yes, early on in development we've removed this, because it's optional and not needed. Specifying multiple queries and passing them to urql is not going to yield any desirable result, so setting this wasn't ever really relevant 馃

Is there any use-case that we're missing here where this is absolutely needed, ignoring a case where a document contains multiple queries, which is by convention not expect in urql nor Apollo?

So our use case is that we are doing transaction tracing to be able to timeline how long a call takes, and this is based on the operationName. With the value being undefined it means it's not very clear as to what the call was, so we have to drill in to see.

I have been doing some research on other clients (namely Apollo GraphQL, GraphQL playground, and GraphiQL) to see what behaviour they have around this. They all add the operationName to the request if available even if there is only a single named query. I have attached a screenshot of a GraphiQL IDE with only a single query and the network request to the server including the operationName in the request payload. image

@kitten / @JoviDeCroock you guys are awesome, thanks for the speedy response!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nicollecastrog picture nicollecastrog  路  3Comments

fivethreeo picture fivethreeo  路  5Comments

TLadd picture TLadd  路  4Comments

alexraginskiy picture alexraginskiy  路  3Comments

kitten picture kitten  路  4Comments