Skip to content

Commit

Permalink
No need to throw error on recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed May 22, 2023
1 parent b35e3bf commit f5ed1d8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 30 deletions.
30 changes: 4 additions & 26 deletions grafast/grafast/src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,13 @@ export function inputPlan(
inputType: GraphQLInputType,
rawInputValue: ValueNode | undefined,
defaultValue: ConstValueNode | undefined = undefined,
inSeenTypes?: ReadonlyArray<GraphQLInputType>,
): InputStep {
// This prevents recursion
if (rawInputValue === undefined && defaultValue === undefined) {
return constant(undefined);
}

if (inSeenTypes?.includes(inputType)) {
// FIXME: Stop recursion if no data
throw new Error(
"GrafastInternalError<441c4f9f-d3d2-41ec-b7bc-e0b96885affe>: Grafast doesn't currently support planning through recursive input values; please raise an issue and explain how this affects you!",
);
}
const isObj = isInputObjectType(inputType);
const seenTypes = isObj
? inSeenTypes === undefined
? [inputType]
: [...inSeenTypes, inputType]
: inSeenTypes;

let inputValue = rawInputValue;
if (inputValue?.kind === "Variable") {
Expand All @@ -134,7 +123,6 @@ export function inputPlan(
operationPlan,
variableName,
variableType,
seenTypes,
inputType,
defaultValue,
);
Expand All @@ -149,11 +137,10 @@ export function inputPlan(
innerType,
inputValue,
undefined,
seenTypes,
);
return inputNonNullPlan(operationPlan, valuePlan);
} else if (inputType instanceof GraphQLList) {
return new __InputListStep(inputType, seenTypes, inputValue);
return new __InputListStep(inputType, inputValue);
} else if (isLeafType(inputType)) {
if (inputValue?.kind === Kind.OBJECT || inputValue?.kind === Kind.LIST) {
const scalarType = assertScalarType(inputType);
Expand All @@ -166,7 +153,7 @@ export function inputPlan(
return new __InputStaticLeafStep(inputType, inputValue);
}
} else if (isObj) {
return new __InputObjectStep(inputType, seenTypes!, inputValue);
return new __InputObjectStep(inputType, inputValue);
} else {
const never: never = inputType;
throw new Error(`Unsupported type in inputPlan: '${inspect(never)}'`);
Expand All @@ -187,7 +174,6 @@ function inputVariablePlan(
operationPlan: OperationPlan,
variableName: string,
variableType: GraphQLInputType,
seenTypes: ReadonlyArray<GraphQLInputType> | undefined,
inputType: GraphQLInputType,
defaultValue: ConstValueNode | undefined = undefined,
): InputStep {
Expand All @@ -200,7 +186,6 @@ function inputVariablePlan(
operationPlan,
variableName,
unwrappedVariableType,
seenTypes,
inputType,
defaultValue,
);
Expand All @@ -216,7 +201,6 @@ function inputVariablePlan(
operationPlan,
variableName,
variableType,
seenTypes,
inputType.ofType,
defaultValue,
);
Expand All @@ -240,13 +224,7 @@ function inputVariablePlan(
// `defaultValue` is NOT undefined, and we know variableValue is
// `undefined` (and always will be); we're going to loop back and pretend
// that no value was passed in the first place (instead of the variable):
return inputPlan(
operationPlan,
inputType,
undefined,
defaultValue,
seenTypes,
);
return inputPlan(operationPlan, inputType, undefined, defaultValue);
}
}

Expand Down
2 changes: 0 additions & 2 deletions grafast/grafast/src/steps/__inputList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class __InputListStep extends ExecutableStep {

constructor(
inputType: graphql.GraphQLList<GraphQLInputType>,
seenTypes: ReadonlyArray<GraphQLInputType> | undefined,
private readonly inputValues: NotVariableValueNode | undefined,
) {
super();
Expand Down Expand Up @@ -56,7 +55,6 @@ export class __InputListStep extends ExecutableStep {
innerType,
inputValue,
undefined,
seenTypes,
);
this.addDependency(innerPlan);
this.itemCount++;
Expand Down
2 changes: 0 additions & 2 deletions grafast/grafast/src/steps/__inputObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export class __InputObjectStep extends UnbatchedExecutableStep {
} = Object.create(null);
constructor(
private inputObjectType: GraphQLInputObjectType,
seenTypes: ReadonlyArray<GraphQLInputType>,
private inputValues: NotVariableValueNode | undefined,
) {
super();
Expand All @@ -48,7 +47,6 @@ export class __InputObjectStep extends UnbatchedExecutableStep {
inputFieldType,
inputFieldValue?.value,
defaultValue,
seenTypes,
);
this.inputFields[inputFieldName] = {
step,
Expand Down

0 comments on commit f5ed1d8

Please sign in to comment.