Skip to content

Commit

Permalink
enhance(wrap/MapLeafValues): fallback to regular AST transformation i…
Browse files Browse the repository at this point in the history
…f astFromValue fails
  • Loading branch information
ardatan committed Mar 12, 2024
1 parent 31f89d0 commit 69181f6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/honest-steaks-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-tools/wrap": patch
---

MapLeafValues: fallback to `astFromValueUntyped` if `astFromValue` fails
3 changes: 3 additions & 0 deletions packages/utils/src/astFromValueUntyped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export function astFromValueUntyped(value: any): ValueNode | null {
}

if (typeof value === 'object') {
if (value instanceof Date) {
return { kind: Kind.STRING, value: value.toISOString() };
}
const fieldNodes: Array<ObjectFieldNode> = [];
for (const fieldName in value) {
const fieldValue = value[fieldName];
Expand Down
8 changes: 7 additions & 1 deletion packages/wrap/src/transforms/MapLeafValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from 'graphql';
import { DelegationContext, SubschemaConfig, Transform } from '@graphql-tools/delegate';
import {
astFromValueUntyped,
ExecutionRequest,
ExecutionResult,
ResultVisitorMap,
Expand Down Expand Up @@ -194,7 +195,12 @@ export default class MapLeafValues<TContext = Record<string, any>>
if (argValue?.kind === Kind.VARIABLE) {
variableValues[argValue.name.value] = transformedValue;
} else {
const newValueNode = astFromValue(transformedValue, argType);
let newValueNode: any;
try {
newValueNode = astFromValue(transformedValue, argType);
} catch (e) {
newValueNode = astFromValueUntyped(transformedValue);
}
if (newValueNode != null) {
argumentNodeMap[argName] = {
...argumentNode,
Expand Down

0 comments on commit 69181f6

Please sign in to comment.