graphql.js icon indicating copy to clipboard operation
graphql.js copied to clipboard

"An operation name is required if the query contains multiple operations"

Open Nasr-Ladib opened this issue 2 years ago • 2 comments

Hi. I am trying to put many queries and fragments inside one request. My POST request's body:

query login {
  createSession(email:"[email protected]", password: "foobar"){
    session
  }
}

query me {
  deserializeUser{
    id,
    email,
    name
  }
}

I found that I can add ./src/graphql.ts:11

const NON_VARIABLE_OPTIONS = ["method", "baseUrl", "url", "headers", "request", "query", "mediaType"]

add a non-variable option operationName

const NON_VARIABLE_OPTIONS = ["method", "baseUrl", "url", "headers", "request", "query", "mediaType","operationName"]

Please give me some clues. Thanks in advance.

Nasr-Ladib avatar Sep 22 '22 16:09 Nasr-Ladib

It looks like an error you are getting from the GraphQL API, I don't think this is an error with @octokit/graphql

gr2m avatar Sep 23 '22 19:09 gr2m

Actually, I can't pass the parameter on the body of operationName. Because the request needs (query and operationName) of a multi operation on the same graphQL.

I have queryFile has multiple operations as the following example:

query login {
  createSession(email:"[email protected]", password: "foobar"){
    session
  }
}

query me {
  deserializeUser{
    id,
    email,
    name
  }
}

So, I want to use the login operation for the first time than the me operation.

const result = await this.auth.graphql( queryFile, operationName );

Nasr-Ladib avatar Oct 06 '22 08:10 Nasr-Ladib