diff --git a/src/stitching/delegateToSchema.ts b/src/stitching/delegateToSchema.ts index da1ef093601..73cdddc4983 100644 --- a/src/stitching/delegateToSchema.ts +++ b/src/stitching/delegateToSchema.ts @@ -88,6 +88,7 @@ async function delegateToSchemaImplementation( }; let transforms = [ + new CheckResultAndHandleErrors(info, options.fieldName), ...(options.transforms || []), new ExpandAbstractTypes(info.schema, targetSchema), ]; @@ -108,7 +109,6 @@ async function delegateToSchemaImplementation( transforms = transforms.concat([ new FilterToSchema(targetSchema), new AddTypenameToAbstract(targetSchema), - new CheckResultAndHandleErrors(info, options.fieldName), ]); const processedRequest = applyRequestTransforms(rawRequest, transforms); diff --git a/src/test/testTransforms.ts b/src/test/testTransforms.ts index 0dba395c698..7d5049fda89 100644 --- a/src/test/testTransforms.ts +++ b/src/test/testTransforms.ts @@ -160,7 +160,8 @@ describe('transforms', () => { let schema: GraphQLSchema; before(() => { const transforms = [ - new RenameTypes((name: string) => `Property_${name}`), + new RenameTypes((name: string) => `_${name}`), + new RenameTypes((name: string) => `Property${name}`), ]; schema = transformSchema(propertySchema, transforms); }); diff --git a/src/transforms/transformSchema.ts b/src/transforms/transformSchema.ts index a63bc06ce79..781150855c0 100644 --- a/src/transforms/transformSchema.ts +++ b/src/transforms/transformSchema.ts @@ -25,7 +25,7 @@ export function wrapSchema( const resolvers = generateProxyingResolvers( schemaOrSchemaExecutionConfig, - transforms, + transforms.slice().reverse(), ); addResolveFunctionsToSchema({ schema, @@ -43,6 +43,6 @@ export default function transformSchema( transforms: Array, ): GraphQLSchema & { transforms: Array } { const schema = wrapSchema(schemaOrSchemaExecutionConfig, transforms); - (schema as any).transforms = transforms; + (schema as any).transforms = transforms.slice().reverse(); return schema as GraphQLSchema & { transforms: Array }; } diff --git a/src/transforms/transforms.ts b/src/transforms/transforms.ts index 7a84cb1bfe1..2b1a1d3504e 100644 --- a/src/transforms/transforms.ts +++ b/src/transforms/transforms.ts @@ -32,7 +32,7 @@ export function applyResultTransforms( originalResult: any, transforms: Array, ): any { - return transforms.reduce( + return transforms.reduceRight( (result: any, transform: Transform) => transform.transformResult ? transform.transformResult(result) : result, originalResult,