After generating code based on the downloaded schema I receive query's like:
public static let operationDefinition =
"query QueryName($parameters: [String]!) {" +
" foo(bar: $lorem) {" +
" __typename" +
" x" +
" y" +
" }" +
"}"
I can then easily tell the client to do a fetch request and pass an instance of this query. It works fine but for some reason the QueryName (which is the operationName right?) is not set in the request. Using Charles Proxy I found that the iOS SDK is also not setting any operationName on the request and therefore our request are marked as "unknown" in new relic.
If I inspect our javascript client on our website it does actually add an operationName to the request. This is done automatically. Is there a way to also do this for the iOS SDK?
Using Apollo iOS version 0.5.6.
Since operationName is only required when multiple operations are included in a single query document, and Apollo iOS never sends multiple operations, we don't currently set this. But it would be pretty easy to add to HTTPNetworkTransport if you have a need for it (like logging in New Relic).
Thanks @martijnwalraven . Do you know how I can easily retrieve the query name from the generated code? I see that I can easily change the send method in the NetworkTransport protocol implementation to include an operationName but am not sure how to retrieve the matching name that goes with that specific request.
Maybe from the GraphQLOperation parameter?
Ah, you're right, we don't currently generate an operationName on GraphQLOperation either. We could definitely do that, but it does require changes to codegen. It's a bit of a hack, but for now you might be able to derive it from operationDefinition (looking at operationType to cut off query or mutation and know where to find the name in the string).
According to this document: _"It is only required in multi-operation documents, but its use is encouraged because it is very helpful for debugging and server-side logging."_
We'd like to use them for subscriptions so support for them would be welcome. Does the note in the draft section 5.2.3.1 mandate to send the operation name or am I misunderstanding this?
Here's a tree with a simple operationName implementation (commit) that we're now using. Is this an implementation that would would be useful? (i.e., should I do a PR or is there a better way to solve this?)
Ping @martijnwalraven : how's your take on supporting operationName?
This is definitely something we're looking at including - I have to see where things are with our current setup with the typescript stuff, but this is a totally reasonable request.
This is now included with everything as of 0.13.0!
Most helpful comment
This is now included with everything as of 0.13.0!