apollo-fetch
apollo-fetch copied to clipboard
Network request failed. Payload is not serializable: Converting circular structure to JSON
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)
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?
This worked for you @trivago-mbonilla ?
yes, but as the change is in the lib I switched to apollo-link
Thanks, it worked here too. @trivago-mbonilla
Any updates on this?