I鈥檓 investigating a scenario where we proxy a remote GraphQL API, extend the types, and transform the data as it passes through.
Extending the types and merging the local schema/resolvers isn鈥檛 a problem, but I鈥檓 stuck when it comes to transforming the data as it passes through.
It seems like I can override the delegating resolver with a local one, but I can鈥檛 let the delegating resolver execute, and then pass the results into a local resolver to alter the data.
Is this even possible with the current mergeSchema and makeRemoteExecutableSchema? Or am I going to have to get my hands a little dirty.
Could I use a custom ApolloLink for this?
const postProcessingLink = new ApolloLink((operation, forward) => {
return forward(operation).map((data) => {
return graphql(
schema: postProcessingSchema,
requestString: operation.query,
rootValue: data,
variableValues: operation.variables,
operationName: operation.operationName
);
})
});
Is this a reasonable idea to explore?
So I'm just going to answer my own issue here in case this helps anyone else.
I was able to accomplish this with a post processing ApolloLink as suggested above. Here is a gist of how I did it.
I hope this is useful to someone else.
Your approach makes sense to me @adamkl - thanks for sharing!
Most helpful comment
So I'm just going to answer my own issue here in case this helps anyone else.
I was able to accomplish this with a post processing ApolloLink as suggested above. Here is a gist of how I did it.
I hope this is useful to someone else.