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 #3556

Closed
ivome opened this issue Jun 7, 2018 · 3 comments
Closed

Comments

@ivome
Copy link

ivome commented Jun 7, 2018

Intended outcome:
I am trying to use the link object on an ApolloClient instance to execute a query that is part of a document that contains multiple queries. Specific use case: I want to reuse the link with auth logic etc as a fetcher for GraphiQL where you would often write multiple queries in one document for testing. Right now when the query is executed it throws an exception because of this check:

https://github.com/apollographql/apollo-client/blob/master/packages/apollo-utilities/src/getFromAST.ts#L49

When I remove it, everything works as expected. IMO this check should happen at a higher level if required by apollo client and not when a valid GraphQL operation is executed directly on the link object.

Actual outcome:
Right now when I execute the query, it throws an exception "Ambiguous GraphQL document: contains N operations" even if the operationName is provided. This should be a valid GraphQL operation.

How to reproduce the issue:

import { execute, makePromise } from 'apollo-link';
import gql from 'graphql-tag';
import client from './myApolloClient';

let query = gql(`
query A {
  someFIeld
}

query B {
  someFIeld
}
`);

const operation = {
   query,
   variables: {},
   operationName: 'B'
};

makePromise(execute(client.link, operation))
  .then(console.log)
  .catch(console.error);

Versions

System:
OS: macOS High Sierra 10.13.4
Binaries:
Node: 9.8.0 - ~/.nvm/versions/node/v9.8.0/bin/node
Yarn: 1.7.0 - ~/.yarn/bin/yarn
npm: 5.6.0 - ~/.nvm/versions/node/v9.8.0/bin/npm
Browsers:
Chrome: 66.0.3359.181
Safari: 11.1
npmPackages:
apollo-cache-inmemory: ^1.1.4 => 1.2.2
apollo-client: ^2.1.0 => 2.3.2
apollo-client-preset: ^1.0.5 => 1.0.8
apollo-link: ^1.0.7 => 1.2.2
react-apollo: ^2.0.4 => 2.1.4

@kamilkisiela
Copy link
Contributor

I guess it's not a part of graphql-js yet
graphql/graphql-spec/issues/375

@ivome
Copy link
Author

ivome commented Jun 12, 2018

@kamilkisiela This is a separate and unrelated issue. They are talking there about running multiple queries within one request. I want to run only one query from one document that has multiple queries defined. The operationName is then provided to select the query to run. This is also part of graphql-js and works perfectly fine.

See an example in the GraphiQL demo: https://graphql.github.io/swapi-graphql/?query=query%20A%20%7B%0A%20%20allPlanets%20%7B%0A%20%20%20%20pageInfo%20%7B%0A%20%20%20%20%20%20hasNextPage%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A%0Aquery%20B%20%7B%0A%20%20allFilms%20%7B%0A%20%20%20%20totalCount%0A%20%20%7D%0A%7D%0A&operationName=A

This query is currently not supported by the apollo link data layer. If we remove the check that I mentioned above this would solve the problem. We only might have to ensure in a higher level that in case of a document with multiple queries an operationName is provided (if even necessary) to select the query to run.

@hwillson
Copy link
Member

hwillson commented Aug 5, 2018

To help provide a more clear separation between feature requests / discussions and bugs, and to help clean up the feature request / discussion backlog, Apollo Client feature requests / discussions are now being managed under the https://github.com/apollographql/apollo-feature-requests repository.

This feature request / discussion will be closed here, but anyone interested in migrating this issue to the new repository (to make sure it stays active), can click here to start the migration process. This manual migration process is intended to help identify which of the older feature requests are still considered to be of value to the community. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants