twenty / packages /twenty-server /src /engine /api /graphql /direct-execution /utils /extract-arguments-from-ast.util.ts
Jules
Initial clean CRM deployment with prebuilt assets
d9494a5
Raw
History Blame Contribute Delete
731 Bytes
import { type ArgumentNode, valueFromASTUntyped } from 'graphql';
import { isDefined } from 'twenty-shared/utils';
// Converts GraphQL AST argument nodes into a plain JS object,
// resolving variable references from the variables map.
export const extractArgumentsFromAst = (
argumentNodes: readonly ArgumentNode[] | undefined,
variables: Record<string, unknown> | undefined,
): Record<string, unknown> => {
if (!argumentNodes || argumentNodes.length === 0) {
return {};
}
const result: Record<string, unknown> = {};
for (const arg of argumentNodes) {
const value = valueFromASTUntyped(arg.value, variables);
if (!isDefined(value)) continue;
result[arg.name.value] = value;
}
return result;
};