Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
fix(stitching): do not reproxy a nested root field
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Mar 6, 2020
1 parent 9aeee75 commit dd3bae0
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/stitching/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { Transform } from '../transforms';

import delegateToSchema from './delegateToSchema';
import { makeMergedType } from './makeMergedType';
import { getResponseKeyFromInfo } from './getResponseKeyFromInfo';
import { getErrors, getSubschema } from './proxiedResult';
import { handleResult } from './checkResultAndHandleErrors';

export type Mapping = {
[typeName: string]: {
Expand Down Expand Up @@ -112,13 +115,27 @@ function defaultCreateProxyingResolver({
schema: SubschemaConfig;
transforms: Array<Transform>;
}): GraphQLFieldResolver<any, any> {
return (_parent, _args, context, info) =>
delegateToSchema({
return (parent, _args, context, info) => {
if (parent != null) {
const responseKey = getResponseKeyFromInfo(info);
const errors = getErrors(parent, responseKey);

// check to see if parent is a proxied result, possible if root types are also nested
if (errors != null) {
const result = parent[responseKey];
const subschema = getSubschema(parent, responseKey);

return handleResult(result, errors, subschema, context, info);
}
}

return delegateToSchema({
schema,
context,
info,
transforms,
});
};
}

export function stripResolvers(schema: GraphQLSchema): void {
Expand Down

0 comments on commit dd3bae0

Please sign in to comment.