{
  "version": 3,
  "sources": ["../src/values.ts"],
  "sourcesContent": ["import {\n  GraphQLError,\n  Kind,\n  print,\n  locatedError,\n  DirectiveNode,\n  FieldNode,\n  VariableDefinitionNode,\n} from \"graphql\";\nimport { inspect } from \"./jsutils/inspect\";\nimport { printPathArray } from \"./jsutils/printPathArray\";\nimport { ExecutionContext } from \"./executeWithoutSchema\";\nimport {\n  DirectiveDefinitionTuple,\n  FieldDefinition,\n  getFieldDefinitionArgs,\n  getDirectiveDefinitionName,\n  getInputDefaultValue,\n  getInputValueTypeReference,\n  isDefined,\n  isInputType,\n  getDirectiveDefinitionArgs,\n  getInputObjectType,\n  getInputObjectFields,\n} from \"./schema/definition\";\nimport { valueFromAST } from \"./utilities/valueFromAST\";\nimport { coerceInputValue } from \"./utilities/coerceInputValue\";\nimport {\n  inspectTypeReference,\n  isNonNullType,\n  typeReferenceFromNode,\n  typeNameFromReference,\n} from \"./schema/reference\";\nimport type { SchemaFragment } from \"./types\";\n\ntype CoercedVariableValues =\n  | { errors: Array<GraphQLError>; coerced?: never }\n  | { coerced: { [variable: string]: unknown }; errors?: never };\n\n/**\n * Prepares an object map of variableValues of the correct type based on the\n * provided variable definitions and arbitrary input. If the input cannot be\n * parsed to match the variable definitions, a GraphQLError will be thrown.\n *\n * Note: The returned value is a plain Object with a prototype, since it is\n * exposed to user code. Care should be taken to not pull values from the\n * Object prototype.\n *\n * @internal\n */\nexport function getVariableValues(\n  schemaFragment: SchemaFragment,\n  varDefNodes: ReadonlyArray<VariableDefinitionNode>,\n  inputs: { [variable: string]: unknown },\n  options?: { maxErrors?: number },\n): CoercedVariableValues {\n  const errors: GraphQLError[] = [];\n  const maxErrors = options?.maxErrors;\n  try {\n    const coerced = coerceVariableValues(\n      schemaFragment,\n      varDefNodes,\n      inputs,\n      (error) => {\n        if (maxErrors != null && errors.length >= maxErrors) {\n          throw locatedError(\n            \"Too many errors processing variables, error limit reached. Execution aborted.\",\n            [],\n          );\n        }\n        errors.push(error);\n      },\n    );\n\n    if (errors.length === 0) {\n      return { coerced };\n    }\n  } catch (error) {\n    errors.push(error as GraphQLError);\n  }\n\n  return { errors: errors };\n}\n\nexport function getMissingVariableTypes(\n  varDefNodes: ReadonlyArray<VariableDefinitionNode>,\n  schemaFragment: SchemaFragment,\n) {\n  const missingTypeReferences = [];\n  const typeReferencesToValidate = varDefNodes.map((varDefNode) =>\n    typeReferenceFromNode(varDefNode.type),\n  );\n  const queuedForValidation = new Set(typeReferencesToValidate);\n\n  let index = 0;\n  while (index < typeReferencesToValidate.length) {\n    const varTypeReference = typeReferencesToValidate[index++];\n    if (!isInputType(schemaFragment.definitions, varTypeReference)) {\n      missingTypeReferences.push(typeNameFromReference(varTypeReference));\n      continue;\n    }\n\n    const inputObjectDef = getInputObjectType(\n      schemaFragment.definitions,\n      varTypeReference,\n    );\n    if (inputObjectDef) {\n      for (const maybeTypeReference of Object.values(\n        getInputObjectFields(inputObjectDef),\n      )) {\n        const typeReference = Array.isArray(maybeTypeReference)\n          ? maybeTypeReference[0]\n          : maybeTypeReference;\n\n        if (!queuedForValidation.has(typeReference)) {\n          queuedForValidation.add(typeReference);\n          typeReferencesToValidate.push(typeReference);\n        }\n      }\n    }\n  }\n\n  return missingTypeReferences;\n}\n\nfunction coerceVariableValues(\n  schemaFragment: SchemaFragment,\n  varDefNodes: ReadonlyArray<VariableDefinitionNode>,\n  inputs: { [variable: string]: unknown },\n  onError: (error: GraphQLError) => void,\n): { [variable: string]: unknown } {\n  const coercedValues: { [variable: string]: unknown } = {};\n  for (const varDefNode of varDefNodes) {\n    const varName = varDefNode.variable.name.value;\n    const varTypeReference = typeReferenceFromNode(varDefNode.type);\n\n    if (!isInputType(schemaFragment.definitions, varTypeReference)) {\n      // Must use input types for variables. This should be caught during\n      // validation, however is checked again here for safety.\n      const errorMessage = !isDefined(\n        schemaFragment.definitions,\n        varTypeReference,\n      )\n        ? `Missing definition for input type \"${typeNameFromReference(\n            varTypeReference,\n          )}\"`\n        : `Variable \"$${varName}\" expected value of type \"${inspectTypeReference(\n            varTypeReference,\n          )}\" which cannot be used as an input type.`;\n\n      onError(locatedError(errorMessage, [varDefNode.type]));\n      continue;\n    }\n\n    if (!hasOwnProperty(inputs, varName)) {\n      if (varDefNode.defaultValue) {\n        coercedValues[varName] = valueFromAST(\n          varDefNode.defaultValue,\n          varTypeReference,\n          schemaFragment,\n        );\n      } else if (isNonNullType(varTypeReference)) {\n        const varTypeStr = inspectTypeReference(varTypeReference);\n        onError(\n          locatedError(\n            `Variable \"$${varName}\" of required type \"${varTypeStr}\" was not provided.`,\n            [varDefNode],\n          ),\n        );\n      }\n      continue;\n    }\n\n    const value = inputs[varName];\n    if (value === null && isNonNullType(varTypeReference)) {\n      const varTypeStr = inspectTypeReference(varTypeReference);\n      onError(\n        locatedError(\n          `Variable \"$${varName}\" of non-null type \"${varTypeStr}\" must not be null.`,\n          [varDefNode],\n        ),\n      );\n      continue;\n    }\n\n    coercedValues[varName] = coerceInputValue(\n      value,\n      varTypeReference,\n      schemaFragment,\n      (path, invalidValue, error) => {\n        let prefix =\n          `Variable \"$${varName}\" got invalid value ` + inspect(invalidValue);\n        if (path.length > 0) {\n          prefix += ` at \"${varName}${printPathArray(path)}\"`;\n        }\n        onError(locatedError(prefix + \"; \" + error.message, [varDefNode]));\n      },\n    );\n  }\n\n  return coercedValues;\n}\n\nfunction isFieldDefinition(\n  def: FieldDefinition | DirectiveDefinitionTuple,\n  node: FieldNode | DirectiveNode,\n): def is FieldDefinition {\n  return node.kind === Kind.FIELD;\n}\n\n/**\n * Prepares an object map of argument values given a list of argument\n * definitions and list of argument AST nodes.\n *\n * Note: The returned value is a plain Object with a prototype, since it is\n * exposed to user code. Care should be taken to not pull values from the\n * Object prototype.\n *\n * @internal\n */\nexport function getArgumentValues(\n  exeContext: ExecutionContext,\n  def: FieldDefinition | DirectiveDefinitionTuple,\n  node: FieldNode | DirectiveNode,\n): { [argument: string]: unknown } {\n  const definitions = exeContext.schemaFragment.definitions;\n  const coercedValues: { [argument: string]: unknown } = {};\n  const argumentDefs = isFieldDefinition(def, node)\n    ? getFieldDefinitionArgs(def)\n    : getDirectiveDefinitionArgs(def);\n  if (!argumentDefs) {\n    return coercedValues;\n  }\n  // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')\n  const argumentNodes = node.arguments ?? [];\n  const argNodeMap = new Map(argumentNodes.map((arg) => [arg.name.value, arg]));\n\n  for (const [name, argumentDef] of Object.entries(argumentDefs)) {\n    const argumentNode = argNodeMap.get(name);\n    const argumentTypeRef = getInputValueTypeReference(argumentDef);\n    const defaultValue = getInputDefaultValue(argumentDef);\n\n    if (argumentNode == null) {\n      if (defaultValue !== undefined) {\n        coercedValues[name] = defaultValue;\n      } else if (isNonNullType(argumentTypeRef)) {\n        const type = inspectTypeReference(argumentTypeRef);\n        throw locatedError(\n          `Argument \"${name}\" of required type \"${type}\" was not provided.`,\n          [node],\n        );\n      }\n      continue;\n    }\n\n    if (!isDefined(definitions, argumentTypeRef)) {\n      throw locatedError(\n        `Could not find type for argument ${name} in ${node.kind} ${node.name.value}`,\n        [argumentNode],\n      );\n    }\n\n    // if (!schemaTypes.isInputType(argumentTypeRef)) {\n    //   const type = schemaTypes.printTypeRef(argumentTypeRef);\n    //   throw locatedError(\n    //     `Argument \"$${name}\" expected value of type \"${type}\" which cannot be used as an input type.`,\n    //     [argumentNode],\n    //   );\n    // }\n\n    const valueNode = argumentNode.value;\n    let isNull = valueNode.kind === Kind.NULL;\n\n    if (valueNode.kind === Kind.VARIABLE) {\n      const variableName = valueNode.name.value;\n      if (\n        exeContext.variableValues == null ||\n        !hasOwnProperty(exeContext.variableValues, variableName)\n      ) {\n        if (defaultValue !== undefined) {\n          coercedValues[name] = defaultValue;\n        } else if (isNonNullType(argumentTypeRef)) {\n          const type = inspectTypeReference(argumentTypeRef);\n          throw locatedError(\n            `Argument \"${name}\" of required type \"${type}\" ` +\n              `was provided the variable \"$${variableName}\" which was not provided a runtime value.`,\n            [valueNode],\n          );\n        }\n        continue;\n      }\n      isNull = exeContext.variableValues[variableName] == null;\n    }\n\n    if (isNull && isNonNullType(argumentTypeRef)) {\n      const type = inspectTypeReference(argumentTypeRef);\n      throw locatedError(\n        `Argument \"${name}\" of non-null type \"${type}\" must not be null.\"`,\n        [valueNode],\n      );\n    }\n\n    const coercedValue = valueFromAST(\n      valueNode,\n      argumentTypeRef,\n      exeContext.schemaFragment,\n      exeContext.variableValues,\n    );\n    if (coercedValue === undefined) {\n      // Note: ValuesOfCorrectTypeRule validation should catch this before\n      // execution. This is a runtime check to ensure execution does not\n      // continue with an invalid argument value.\n      throw locatedError(\n        `Argument \"${name}\" has invalid value ${print(valueNode)}.`,\n        [valueNode],\n      );\n    }\n    coercedValues[name] = coercedValue;\n  }\n\n  return coercedValues;\n}\n\n/**\n * Prepares an object map of argument values given a directive definition\n * and a AST node which may contain directives. Optionally also accepts a map\n * of variable values.\n *\n * If the directive does not exist on the node, returns undefined.\n *\n * Note: The returned value is a plain Object with a prototype, since it is\n * exposed to user code. Care should be taken to not pull values from the\n * Object prototype.\n */\nexport function getDirectiveValues(\n  exeContext: ExecutionContext,\n  directiveDef: DirectiveDefinitionTuple,\n  node: { directives?: ReadonlyArray<DirectiveNode> },\n): undefined | { [argument: string]: unknown } {\n  const name = getDirectiveDefinitionName(directiveDef);\n\n  // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')\n  const directiveNode = node.directives?.find(\n    (directive) => directive.name.value === name,\n  );\n\n  if (directiveNode) {\n    return getArgumentValues(exeContext, directiveDef, directiveNode);\n  }\n}\n\nfunction hasOwnProperty(obj: unknown, prop: string): boolean {\n  return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n"],
  "mappings": ";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAE/B;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,E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