I am using remote schema stitching on my middlware server. I am able to get the schema remotely on middleware server, defined my route like this on middleware server.
app.use('/graphql', graphqlHTTP((request,res) => {
const startTime = Date.now();
return {
schema: remoteSchema
graphiql: false,
extensions({ document, variables, operationName, result }) {
return {
// here I am not getting extensions which I have on my another server as below.
console.log(res); // this does not have additional info and response headers
console.log(result); // this only has response against the query
}
};
}));
I am getting the result of the query in the result but not getting response headers and additional info which is a part of extension which I am adding on my other server where resolvers are there.
{
"data": {
"records": {
"record": [{
"id": 1,
},
{
"id": 2,
}
],
},
"additionalInfo": {}
},
"extensions": {
"info": {}
}
}
What could be the issue? This is how I am adding response headers and additional info on my another server in extensions. I debug below code where extension data is available. This is not being passed to middleware server.
extensions({ document, variables, operationName, result }) {
result.data.additionalInfo = res.additionalInfo;
// extension to write api headers in response
var headerObj = {};
res.apiHeaders.forEach(element => {
merge(headerObj, element);
});
result.headerObj = headerObj;
return {
information: headerObj
};
}
My application flow is that I am calling middleware route then another server route using remote schema stitching. I want extension which I am adding on another server should be forward to my middleware server in the response.
:
and=>
aren't necessary. The original example code is using the object literal shorthand for method definitions. – Rupertruperta