Open John-Blaine-Jr opened 4 years ago
Could you try the following?
useSofa({
schema,
execute: ({ source, variableNames, operationName }) => apolloServer.executeOperation({ query: source, variables: variableNames, operationName })
})
Thank you for the fast response!
I think you meant:
useSofa({
schema,
/* executor instead of execute */
executor: ({ source, variableNames, operationName }) => apolloServer.executeOperation({ query: source, variables: variableNames, operationName })
})
I did try this, but I am getting the same result - null
is returned at the gateway layer and the actual payload is returned at the microservice layer.
@John-Blaine-Jr I meant execute
not executor
.
@John-Blaine-Jr Any news?
@ardatan No, I tried using execute
instead of executor
and was getting an error instead of null
. I'll find the error again when I have some time later
I am overwriting the original message because I have good news! It worked! But I had to make one alteration:
useSofa({
schema,
executor: ({ source, variableValues, operationName }) => apolloServer.executeOperation({ query: source, variables: variableValues, operationName })
})
Change variableNames
to variableValues
and it works! That's a win!
useSofa({
schema,
execute: ({ source, variableValues, operationName }) => apolloServer.executeOperation({ query: source, variables: variableValues, operationName })
})
is the right code i think. this works fine for me on queries, but fails for mutations where the variables should be parsed from the body. The variableValues are always an empty Object ({}) in this case and the mutation fails
Don't know if its too late @byteninja, but I stumbled on this issue and found the following:
variableValues
come from query params on GET requests and body on POST requestsexecuteQueryPlan
in apollo gateway looks like so try {
let postProcessingErrors: GraphQLError[];
const variables = requestContext.request.variables;
({ data, errors: postProcessingErrors } = computeResponse({
operation,
variables,
input: unfilteredData,
introspectionHandling: (f) => executeIntrospection(
operationContext.schema,
f.expandFragments().toSelectionNode(),
operationContext.operation.variableDefinitions,
variables,
),
}));
Where it expects the variables from the context, but the issue is
contextValue.request.variables
is empty on POST
The solution I found that works is setting contextValue.request.variables = variableValues;
inside the custom execute
function
Example
execute: ({ document, variableValues, operationName, contextValue }) => {
contextValue.request.variables = variableValues;
return executor({ queryHash: operationName, operationName: operationName, document: document, request: contextValue.request });
},
Seems good so far
I have a microservice API that is using SOFA and seems to be serving up data via REST just fine:
But then, when I try to federate that microservice, and any number of microservices, into a gateway API as instantiated below, I recieve a
null
value whenever I make a REST query.So, the same query succeeds when made against the microservice, but returns
null
when made against the federated gateway service. Is it not possible to use SOFA with a federated Apollo server?