apollo-client: Running introspection query with apollo-client results in RangeError: maximum call stack size exceeded

Intended outcome:

Running the graqhql introspection query with apollo-client. It should return the server’s schema in JSON format.

import { parse, introspectionQuery} from 'graphql';
const query = parse(introspectionQuery);
client.query({query})
      .then(...)
      .catch(...);

Actual outcome:

RangeError: Maximum call stack size exceeded
    at cloneDeep (D:\Users\###\Documents\EVE\teddie\teddie-client\node_modules\apollo-client\util\cloneDeep.…:1)
    at cloneDeep (D:\Users\###\Documents\EVE\teddie\teddie-client\node_modules\apollo-client\util\cloneDeep.…:9)
    at cloneDeep (D:\Users\###\Documents\EVE\teddie\teddie-client\node_modules\apollo-client\util\cloneDeep.…:9)
    at cloneDeep (D:\Users\###\Documents\EVE\teddie\teddie-client\node_modules\apollo-client\util\cloneDeep.…:9)
...

(goes one for quite some lines)

Comment

Replacing the client.query code with networkInterface.query (not using all the fancy apollo features) works.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 24 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Would be great to have a solution for this. addTypename: false trick doesn’t work for me.

As pointed out above, this is happening because parse creates an object with circular references. These references are only in the location fields of the resulting object so I don’t think they’re actually needed. So you can try:

parse(your_query, { noLocation: true })

and see if that works for you.

I have same problem with all queries via react-apollo. I can simulate it very easily. Try to turn off your server during the query and you will see frozen browser and after one/few minutes a lot of errors. @helfer set addTypename to false is not a very good solution 😃

Actually, never mind, I think I figured out what is going on. If you’re using parse from graphql, that will result in an object with circular references, which gets cloned when typenames are added (so if you initialize the client with addTypename: false you won’t have the issue). If you use the gql tag, that’s not the case because it doesn’t include those circular references.

We should probably make our cloneDeep ignore circular references. I’d be happy to accept and merge a PR in that direction.

Finally, I just wanted to point out that I don’t think Apollo Client is the right tool if you simply want to execute a query against a server and get the result. For that it makes much more sense to use the network interface directly, as you have also done, it seems 👍