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

Commit

Permalink
fix(transforms): to properly allow chaining.
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

Result transforms should be reversed, so that multiple request and result transforms can be properly executed.

Request and result transforms must be inverted when transforming a schema, as these transforms work to move from the final schema back to the original schema.

These CHANGES have the potential to be BREAKING.
  • Loading branch information
yaacovCR committed Oct 13, 2019
1 parent f4d183e commit b749aeb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/stitching/delegateToSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ async function delegateToSchemaImplementation(
};

let transforms = [
new CheckResultAndHandleErrors(info, options.fieldName),
...(options.transforms || []),
new ExpandAbstractTypes(info.schema, targetSchema),
];
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/test/testTransforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
4 changes: 2 additions & 2 deletions src/transforms/transformSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function wrapSchema(

const resolvers = generateProxyingResolvers(
schemaOrSchemaExecutionConfig,
transforms,
transforms.slice().reverse(),
);
addResolveFunctionsToSchema({
schema,
Expand All @@ -43,6 +43,6 @@ export default function transformSchema(
transforms: Array<Transform>,
): GraphQLSchema & { transforms: Array<Transform> } {
const schema = wrapSchema(schemaOrSchemaExecutionConfig, transforms);
(schema as any).transforms = transforms;
(schema as any).transforms = transforms.slice().reverse();
return schema as GraphQLSchema & { transforms: Array<Transform> };
}
2 changes: 1 addition & 1 deletion src/transforms/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function applyResultTransforms(
originalResult: any,
transforms: Array<Transform>,
): any {
return transforms.reduce(
return transforms.reduceRight(
(result: any, transform: Transform) =>
transform.transformResult ? transform.transformResult(result) : result,
originalResult,
Expand Down

0 comments on commit b749aeb

Please sign in to comment.