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

Created on 22 May 2017  Β·  24Comments  Β·  Source: apollographql/apollo-client

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.

βœ” confirmed 🐞 bug

Most helpful comment

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

All 24 comments

Hi @lunedis. :wave: I looked at the code for cloneDeep in Apollo Client, but I couldn't find an obvious reason why there would be an infinite recursion. Could you provide us with a GitHub repo that I can clone and then simply run npm install && npm test to reproduce the issue? Thanks in advance!

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 πŸ‘

Also having this same issue

RangeError: Maximum call stack size exceeded
    at cloneDeep (apollo.umd.js:1276)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)
    at cloneDeep (apollo.umd.js:1284)

Any idea when this could be fixed?
We got this triggered in a very special edge-case.

This issue has been automatically marked as stale becuase it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions to Apollo Client!

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 :)

I can confirm what @seeden says. If server is not available react-apollo goes crazy firingAPOLLO_QUERY_INITand APOLLO_QUERY_STOP which ends up in an app crash on react-native.

This issue has been automatically marked as stale becuase it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions to Apollo Client!

any update from apollo team?

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

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions to Apollo Client!

This issue has been automatically closed because it has not had recent activity after being marked as stale. If you belive this issue is still a problem or should be reopened, please reopen it! Thank you for your contributions to Apollo Client!

@seeden how to solve the problem, add the 'addTypename: false' not work.

I did not solve it. I have this issue still in my project

@jbaxleyiii can you reopen this issue?

I am not able to download introspection with latest apollo-client

import 'isomorphic-fetch';
import { parse, introspectionQuery } from 'graphql';
import { InMemoryCache } from 'apollo-cache-inmemory';
import ApolloClient from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { graphql } from '../config/client';

const link = new HttpLink({
  uri: graphql.url,
  credentials: 'same-origin',
});
const cache = new InMemoryCache({});

const client = new ApolloClient({
  link,
  cache,
});

const query = parse(introspectionQuery);

client
  .query({ query })
  .then((result) => {
    console.log(JSON.stringify(result, null, '  '));
  })
  .catch((err) => {
    console.error(err);
  });

I will always get

RangeError: Maximum call stack size exceeded
    at cloneDeep (/Users/seeden/Documents/git/node_modules/apollo-utilities/lib/util/cloneDeep.js:1:26)
    at cloneDeep (/Users/seeden/Documents/git/node_modules/apollo-utilities/lib/util/cloneDeep.js:9:34)
    at cloneDeep (/Users/seeden/Documents/git/node_modules/apollo-utilities/lib/util/cloneDeep.js:9:34)
    at cloneDeep (/Users/seeden/Documents/git/node_modules/apollo-utilities/lib/util/cloneDeep.js:9:34)
    at cloneDeep (/Users/seeden/Documents/git/node_modules/apollo-utilities/lib/util/cloneDeep.js:9:34)
    at cloneDeep (/Users/seeden/Documents/git/node_modules/apollo-utilities/lib/util/cloneDeep.js:9:34)
    at cloneDeep (/Users/seeden/Documents/git/node_modules/apollo-utilities/lib/util/cloneDeep.js:9:34)
    at cloneDeep (/Users/seeden/Documents/git/node_modules/apollo-utilities/lib/util/cloneDeep.js:9:34)
    at cloneDeep (/Users/seeden/Documents/git/node_modules/apollo-utilities/lib/util/cloneDeep.js:9:34)
    at cloneDeep (/Users/seeden/Documents/git/node_modules/apollo-utilities/lib/util/cloneDeep.js:9:34)

versions:

    "apollo-cache-inmemory": "^1.1.2",
    "apollo-client": "^2.1.0",
    "apollo-link": "^1.0.5",
    "apollo-link-batch-http": "^1.0.2",
    "apollo-link-dedup": "1.0.0",
    "apollo-link-http": "^1.3.0",
    "apollo-link-retry": "^1.0.2",
    "apollo-link-ws": "^1.0.2",
    "apollo-utilities": "^1.0.3",

I'm experiencing the same, would you consider a PR that replaces the custom cloneDeep with the standalone version from Lodash?

Having this issue as well, would be much appreciated if a solution was given

addTypename: false

Did not work for me
@helfer

addTypename: false is really bad idea because apollo needs to have it. I am looking different solution.

I'm still able to reproduce.

β”œβ”€β”¬ [email protected]
β”‚ β”œβ”€β”¬ [email protected]
β”‚ β”‚ β”œβ”€β”¬ [email protected]
β”‚ β”‚ β”‚ └── [email protected]
β”‚ β”‚ β”œβ”€β”€ [email protected]
β”‚ β”‚ └─┬ [email protected]
β”‚ β”‚ └── [email protected]
β”‚ β”œβ”€β”¬ [email protected]
β”‚ β”‚ β”œβ”€β”€ @types/[email protected]
β”‚ β”‚ β”œβ”€β”¬ [email protected]
β”‚ β”‚ β”‚ └── [email protected]
β”‚ β”‚ β”œβ”€β”€ [email protected]
β”‚ β”‚ └── [email protected]
β”‚ β”œβ”€β”€ [email protected]
β”‚ └─┬ [email protected]
β”‚ └── [email protected]
β”œβ”€β”¬ [email protected]
β”‚ └── [email protected]
└── [email protected]

@jbaxleyiii can you reopen this issue?

Still reproduceable

import 'isomorphic-fetch'

import {parse} from 'graphql/language/parser'
import {introspectionQuery} from 'graphql/utilities/introspectionQuery'

import {ApolloClient} from 'apollo-client'
import {createHttpLink} from 'apollo-link-http'
import {InMemoryCache} from 'apollo-cache-inmemory'

const GRAPHQL_URL = 'http://localhost:8000/graphql'


const query = parse(introspectionQuery)
const link = createHttpLink({uri: GRAPHQL_URL})
const cache = new InMemoryCache({addTypename: true})

const client = new ApolloClient({link, cache})

client.query({ query }).then((result) => {
  console.log(JSON.stringify(result, null, '  '))
}).catch((err) => console.error(err))

In fact, blows up with addTypename: false, too.

any solution?? We have same issue...

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.

@slycoder thanks! Your solution helped

Was this page helpful?
0 / 5 - 0 ratings