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 | undefined, ): Record => { if (!argumentNodes || argumentNodes.length === 0) { return {}; } const result: Record = {}; for (const arg of argumentNodes) { const value = valueFromASTUntyped(arg.value, variables); if (!isDefined(value)) continue; result[arg.name.value] = value; } return result; };