Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL documents with multiple queries + operationName throws exception #66

Open
Fi1osof opened this issue Oct 31, 2018 · 3 comments
Open
Labels
core Feature requests related to core functionality project-apollo-client (legacy) LEGACY TAG DO NOT USE

Comments

@Fi1osof
Copy link

Fi1osof commented Oct 31, 2018

Migrated from: apollographql/apollo-client#3556

I use https://github.com/graphql/graphiql and create fetcher with apollo-client.

fetcher = async (props) => {
  
  const {
    query,
    ...other
  } = props;

  const {
    client,
  } = this.context;

  return await client.initQueryManager().query({
    query: gql(query),
    ...other
  })
  .catch(error => {
    console.error(error);
    throw error;
  })
}

Single query executed fine.

query users{users(where:{id: "dsf"}){
  id
}}

But multiple throws exception.

query users{users(where:{id: "dsf"}){
  id
}}

mutation createUser{
  createUser(
    data:{ }
  ){
    id
  }
}

Client props:

{"query":"\n\nquery users{users(where:{id: \"dsf\"}){\n  id\n}}\n\nmutation createUser{\n  createUser(\n    data:{ }\n  ){\n    id\n  }\n}","variables":null,"operationName":"users"}

Exception:

Error: Ambiguous GraphQL document: contains 2 operations
    at checkDocument (getFromAST.js:31)
    at getOperationDefinition (getFromAST.js:35)
    at getQueryDefinition (getFromAST.js:62)
    at QueryManager.watchQuery (QueryManager.js:639)
    at QueryManager.js:682
    at new Promise (<anonymous>)
    at QueryManager.query (QueryManager.js:679)
    at _callee$ (App.js:89)
    at tryCatch (runtime.js:62)
    at Generator.invoke [as _invoke] (runtime.js:288)
    at Generator.prototype.(:3000/anonymous function) [as next] (http://localhost:3000/static/js/1.chunk.js:697:21)
    at asyncGeneratorStep (asyncToGenerator.js:3)
    at _next (asyncToGenerator.js:25)
    at asyncToGenerator.js:32
    at new Promise (<anonymous>)
    at asyncToGenerator.js:21
    at App.js:50
    at QueryBuilder._fetchQuery (GraphiQL.js:628)
    at Object.handleRunQuery [as onRun] (GraphiQL.js:792)
    at ExecuteButton._this._onOptionSelected (ExecuteButton.js:105)
    at onMouseUp (ExecuteButton.js:173)
    at HTMLUnknownElement.callCallback (react-dom.development.js:147)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:196)
    at invokeGuardedCallback (react-dom.development.js:250)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:265)
    at executeDispatch (react-dom.development.js:622)
    at executeDispatchesInOrder (react-dom.development.js:647)
    at executeDispatchesAndRelease (react-dom.development.js:747)
    at executeDispatchesAndReleaseTopLevel (react-dom.development.js:760)
    at forEachAccumulated (react-dom.development.js:727)
    at runEventsInBatch (react-dom.development.js:903)
    at runExtractedEventsInBatch (react-dom.development.js:913)
    at handleTopLevel (react-dom.development.js:5078)
    at batchedUpdates$1 (react-dom.development.js:19041)
    at batchedUpdates (react-dom.development.js:2307)
    at dispatchEvent (react-dom.development.js:5158)
    at interactiveUpdates$1 (react-dom.development.js:19103)
    at interactiveUpdates (react-dom.development.js:2328)
    at dispatchInteractiveEvent (react-dom.development.js:5134)
@barruda
Copy link

barruda commented Aug 1, 2019

is there a way to have multiple queries on a single file? having a file per query is really annoying

@dylanwulf
Copy link

is there a way to have multiple queries on a single file? having a file per query is really annoying

@barruda Yes, if you use the gql tag from the graphql-tag package then you can keep multiple queries/fragments/mutations in the same file.

@barruda
Copy link

barruda commented Aug 2, 2019

Thanks for the fast answer, I was forgetting the {} around the import.. so there was no way to know which query I was pointing to... for reference the right use should be like:
import { GetConteudoByTagNome } from '~/apollo/queries/tag'
where GetConteudoByTagNome is the name of the query

@jerelmiller jerelmiller added project-apollo-client (legacy) LEGACY TAG DO NOT USE core Feature requests related to core functionality labels Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Feature requests related to core functionality project-apollo-client (legacy) LEGACY TAG DO NOT USE
Projects
None yet
Development

No branches or pull requests

4 participants