Skip to content

Commit 2b7e7ef

Browse files
Fix queries not using new reshaping code
1 parent 449826c commit 2b7e7ef

File tree

1 file changed

+1
-24
lines changed

1 file changed

+1
-24
lines changed

ndc-lambda-sdk/src/execution.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export async function executeQuery(queryRequest: sdk.QueryRequest, functionsSche
2828
const rows: Record<string, unknown>[] = [];
2929
for (const invocationPreparedArgs of functionInvocationPreparedArgs) {
3030
const result = await invokeFunction(runtimeFunction, invocationPreparedArgs, functionName);
31-
const prunedResult = pruneFields(result, queryRequest.query.fields, functionName, functionDefinition.resultType);
31+
const prunedResult = reshapeResultToNdcResponseValue(result, functionDefinition.resultType, queryRequest.query.fields ?? {}, functionsSchema.objectTypes);
3232
rows.push({
3333
__value: prunedResult
3434
});
@@ -217,29 +217,6 @@ export function reshapeResultToNdcResponseValue(value: unknown, type: schema.Typ
217217
}
218218
}
219219

220-
function pruneFields(result: unknown, fields: Record<string, sdk.Field> | null | undefined, functionName: string, returnType: schema.TypeDefinition): unknown {
221-
if (!fields || Object.keys(fields).length === 0) {
222-
return result;
223-
}
224-
225-
const response: Record<string, unknown> = {};
226-
227-
if (result === null || Array.isArray(result) || typeof result !== "object")
228-
throw new sdk.InternalServerError(`Function '${functionName}' did not return an object when expected to`);
229-
230-
for (const [fieldName,field] of Object.entries(fields)) {
231-
switch(field.type) {
232-
case 'column':
233-
response[fieldName] = (result as Record<string, unknown>)[field.column] ?? null; // Coalesce undefined into null to ensure we always have a value for a requested column
234-
break;
235-
default:
236-
throw new sdk.NotSupported(`Function '${functionName}' field of type '${field.type}' is not supported.`)
237-
}
238-
}
239-
240-
return response;
241-
}
242-
243220
function convertBuiltInNdcJsonScalarToJsScalar(value: unknown, valuePath: string[], scalarType: schema.BuiltInScalarTypeDefinition): string | number | boolean | BigInt | Date {
244221
switch (scalarType.name) {
245222
case schema.BuiltInScalarTypeName.String:

0 commit comments

Comments
 (0)