graphql-request
graphql-request copied to clipboard
fix: Get query's operation name from vars (#64)
Given the following query:
query HeroName {
hero {
name
}
}
query HeroNameAndFriends {
hero {
name
friends {
name
}
}
}
mutation CreateNewHero($name: String) {
hero {
createNewHero(name: $name) {
id
name
}
}
}
With this pull request, HeroName
can be called viz:
request(serverUrl, query, { __operation: 'HeroName' });
or, as:
// Configure a custom key for `operationName`
var client = new GraphqlClient(serverUrl, { operationNameKey: '$operationName' });
// Make a request with the custom key
client.request(query, { $operationName: 'HeroName' });
The mutation CreateNewHero
can be called viz:
request(serverUrl, query, { __operation: 'CreateNewHero', name: "New Hero Name" });
Notice how the name
variable played along with the __operation
variable.
Hope this helps.
Bump - this would be really useful to have.
Hey @adebisi-fa please rebase and I'll try to get this merged soon