apollo-fetch icon indicating copy to clipboard operation
apollo-fetch copied to clipboard

Network request failed. Payload is not serializable: Converting circular structure to JSON

Open trivago-mbonilla opened this issue 7 years ago • 5 comments

using createaApolloFetch() to merge schemas I am having Network request failed. Payload is not serializable: Converting circular structure to JSON error and I don't know if I am doing something wrong, this is my piece of code:

const remoteUrl = "http://my_url/graphql";
const fetcher = createApolloFetch({ uri: remoteUrl });
fetcher.use(({ request, options }, next) => {
    options.headers = {
        'Authorization': "token"
    };

    next();
});
return makeRemoteExecutableSchema({
    schema: await introspectSchema(fetcher),
    fetcher
});

}

export const schema = remoteExecutableSchema();`

This is the error I am getting: Error: Network request failed. Payload is not serializable: Converting circular structure to JSON at Object.checkResultAndHandleErrors ...node_modules/graphql-tools/dist/stitching/errors.js:69:36) at Object.<anonymous> (/.../node_modules/graphql-tools/dist/stitching/delegateToSchema.js:92:52) at step (.../node_modules/graphql-tools/dist/stitching/delegateToSchema.js:40:23) at Object.next (.../node_modules/graphql-tools/dist/stitching/delegateToSchema.js:21:53) at fulfilled (.../node_modules/graphql-tools/dist/stitching/delegateToSchema.js:12:58) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7)

trivago-mbonilla avatar Feb 01 '18 09:02 trivago-mbonilla

I already found a "solution" modifying the library:

function constructDefaultOptions(requestOrRequests, options) {
       var body;
        try {
            var cache = [];
            body = JSON.stringify(requestOrRequests, function(key, value) {
                if (typeof value === 'object' && value !== null) {
                    if (cache.indexOf(value) !== -1) {
                        // Circular reference found, discard key
                        return;
                    }
                    // Store value in our collection
                    cache.push(value);
                }
                return value;
            });
            cache = null; // Enable garbage collection
        }
    catch (e) {
        throw new Error("Network request failed. Payload is not serializable: " + e.message);
    }
    return __assign({ body: body, method: 'POST' }, options, { headers: __assign({ Accept: '*/*', 'Content-Type': 'application/json' }, options.headers || []) });
}

Are you guys gonna do a change there or should I try to find another different solution?

trivago-mbonilla avatar Feb 01 '18 12:02 trivago-mbonilla

This worked for you @trivago-mbonilla ?

dev-jpnobrega avatar Feb 21 '18 15:02 dev-jpnobrega

yes, but as the change is in the lib I switched to apollo-link

trivago-mbonilla avatar Feb 21 '18 15:02 trivago-mbonilla

Thanks, it worked here too. @trivago-mbonilla

dev-jpnobrega avatar Feb 21 '18 18:02 dev-jpnobrega

Any updates on this?

nyteshade avatar Apr 11 '18 01:04 nyteshade