I’m just learning GraphQL, but I’m getting the idea here I think. I’ve been searching and searching for this. I tried keyword “nested” but that doesn’t appear to have been what I need.
Problem:
I have a mutation that requires, as part of its input, an ID. The only way I can get this ID is to run a query that returns it.
Here is the query to get the ID:
query getClientList($input: ListInfoInput!) {
getClientList(input: $input) {
clients {
accountId
}
}
}
Here is sample input:
{
"input": {
"page": 1,
"pageSize": 200,
"condition": {
"attribute": "name",
"operator": "contains",
"value": "ACME Inc"
}
}
}
This returns:
{
"data": {
"getClientList": {
"clients": [
{
"accountId": "123456"
}
]
}
}
}
I then need to use that accountID in this mutation:
mutation createTicket($input: CreateTicketInput!) {
createTicket(input: $input) {
ticketId
subject
ticketType
source
client
}
}
In this input:
{
"input": {
"subject": "Test subject",
"description": "This test description",
"ticketType": "SERVICE_REQUEST",
"source": "INTEGRATION",
"client": {"accountId": "123456"}
}
}
So the only way I can get that 123456 is by issuing a query like seen, and I need to do it in one API call. This is a https POST and needs to be just the one POST, without access to any javascript or server side handling.
This seems like it should be doable, but I can’t for the life of me figure out the syntax or even what it might be called? Is it “nesting”, those seem to be nested mutations and that isn’t really what this is?
I tried putting the query in the mutation input and that failed spectacularly. Does it go under the mutation somehow? I tried a few places and got a wide variety of errors that all basically suggested bad syntax, but I don’t know if I was even on the right track.
Thanks!