Apollo-client: One of the sources for assign has an enumerable key on the prototype chain. Are you trying to assign a prototype property? We don't allow it, as this is an edge case that we do not support.

Created on 9 Feb 2017  路  5Comments  路  Source: apollographql/apollo-client

I was on apollo-client 0.5.26 and everything was perfect, however, after upgrading to the latest version (0.8.3 at the moment) I get APOLLO_MUTATION_ERROR.

The error message is as follows

TypeError: One of the sources for assign has an enumerable key on the prototype chain. Are you trying to assign a prototype property? We don't allow it, as this is an edge case that we do not support. This error is a performance optimization and not spec compliant.
    at Object.assign (http://192.168.1.50:8081/index.ios.bundle?platform=ios&dev=true&hot=true:359:7)
    at HTTPFetchNetworkInterface.fetchFromRemoteEndpoint (http://192.168.1.50:8081/index.ios.bundle?platform=ios&dev=true&hot=true:132276:123)
    at http://192.168.1.50:8081/index.ios.bundle?platform=ios&dev=true&hot=true:132285:57
    at tryCallOne (http://192.168.1.50:8081/index.ios.bundle?platform=ios&dev=true&hot=true:38976:8)
    at http://192.168.1.50:8081/index.ios.bundle?platform=ios&dev=true&hot=true:39062:9
    at http://192.168.1.50:8081/index.ios.bundle?platform=ios&dev=true&hot=true:15621:49
    at Object.callTimer (http://192.168.1.50:8081/index.ios.bundle?platform=ios&dev=true&hot=true:14530:1)
    at Object.callImmediatesPass (http://192.168.1.50:8081/index.ios.bundle?platform=ios&dev=true&hot=true:14634:19)
    at Object.callImmediates (http://192.168.1.50:8081/index.ios.bundle?platform=ios&dev=true&hot=true:14649:25)
    at http://192.168.1.50:8081/index.ios.bundle?platform=ios&dev=true&hot=true:14336:43

Update
The error starts from v0.7.0

Most helpful comment

In case others find this, I just ran into this problem, and the above fix worked for me.

All 5 comments

What is the options object you are passing into ApolloClient, and/or what middleware and afterware are you using? If there are any prototype properties then that鈥檚 probably why you get this error 馃槪

This is how I create ApolloClient

function createApolloServer () {
    const networkInterface = createNetworkInterface({ uri: Settings.graphQLEndpoint });
    networkInterface.use([
        {
            async applyMiddleware(req, next) {
                const token = await AsyncStorage.getItem('token');

                if (!req.options.headers) {
                    req.options.headers = new Headers();
                }

                req.options.headers.token = token === null ? 'ping' : token;

                next();
            },
        },
    ]);

    const SubscriptionClientWS  = new SubscriptionClient(Settings.graphQLSubscriptionEndpoint, {
        keepalive: true,
        reconnect: true,
    });
    const subscriptionInterface = addGraphQLSubscriptions(networkInterface, SubscriptionClientWS);

    // initiate graphQL Client Connection
    const GraphQLClient = new ApolloClient({
        networkInterface: subscriptionInterface,
        queryTransformer: addTypename,
        dataIdFromObject: (result) => {
            if (result.id && result.__typename) { // eslint-disable-line no-underscore-dangle
                return result.__typename + result.id; // eslint-disable-line no-underscore-dangle
            }

            return null;
        },
        shouldBatch     : true,
    });

    return { SubscriptionClient, GraphQLClient };
}

P.S. I am doing this in react-native

It鈥檚 probably because you have req.options.headers = new Headers();. Could you try req.options.headers = {}; instead?

I鈥檓 going to close. The issue is almost certainly that req.options.headers = new Headers(); is being used instead of req.options.headers = {};. Please let us know if you have any further issues! 馃槉

In case others find this, I just ran into this problem, and the above fix worked for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stubailo picture stubailo  路  3Comments

skeithtan picture skeithtan  路  3Comments

stubailo picture stubailo  路  3Comments

gregorskii picture gregorskii  路  3Comments

MichaelDeBoey picture MichaelDeBoey  路  3Comments