Skip to content

Commit

Permalink
enhance(wrap): avoid calling MapLeafValues.transformRequest if nothin…
Browse files Browse the repository at this point in the history
…g is transformed during transformSchema
  • Loading branch information
ardatan committed Oct 31, 2022
1 parent c83f048 commit c1d01f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/thick-panthers-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/wrap': patch
---

Do not transform request if there is no value transformed during the schema transformation
8 changes: 8 additions & 0 deletions packages/wrap/src/transforms/TransformEnumValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default class TransformEnumValues<TContext = Record<string, any>>
private transformedSchema: GraphQLSchema | undefined;
private mapping: Record<string, Record<string, string>>;
private reverseMapping: Record<string, Record<string, string>>;
private noTransformation = true;

constructor(
enumValueTransformer: EnumValueTransformer,
Expand Down Expand Up @@ -50,6 +51,9 @@ export default class TransformEnumValues<TContext = Record<string, any>>
delegationContext: DelegationContext<TContext>,
transformationContext: TransformEnumValuesTransformationContext
): ExecutionRequest {
if (this.noTransformation) {
return originalRequest;
}
return this.transformer.transformRequest(originalRequest, delegationContext, transformationContext);
}

Expand All @@ -58,6 +62,9 @@ export default class TransformEnumValues<TContext = Record<string, any>>
delegationContext: DelegationContext<TContext>,
transformationContext: TransformEnumValuesTransformationContext
) {
if (this.noTransformation) {
return originalResult;
}
return this.transformer.transformResult(originalResult, delegationContext, transformationContext);
}

Expand All @@ -77,6 +84,7 @@ export default class TransformEnumValues<TContext = Record<string, any>>
}
this.mapping[typeName][externalValue] = newExternalValue;
this.reverseMapping[typeName][newExternalValue] = externalValue;
this.noTransformation = false;
}
}
return transformedEnumValue;
Expand Down

0 comments on commit c1d01f3

Please sign in to comment.