values.d.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import Maybe from '../tsutils/Maybe';
  2. import { GraphQLError } from '../error/GraphQLError';
  3. import {
  4. FieldNode,
  5. DirectiveNode,
  6. VariableDefinitionNode,
  7. } from '../language/ast';
  8. import { GraphQLDirective } from '../type/directives';
  9. import { GraphQLSchema } from '../type/schema';
  10. import {
  11. GraphQLInputType,
  12. GraphQLField,
  13. GraphQLArgument,
  14. } from '../type/definition';
  15. type CoercedVariableValues =
  16. | { errors: ReadonlyArray<GraphQLError>; coerced?: never }
  17. | { errors?: never; coerced: { [key: string]: any } };
  18. /**
  19. * Prepares an object map of variableValues of the correct type based on the
  20. * provided variable definitions and arbitrary input. If the input cannot be
  21. * parsed to match the variable definitions, a GraphQLError will be thrown.
  22. *
  23. * Note: The returned value is a plain Object with a prototype, since it is
  24. * exposed to user code. Care should be taken to not pull values from the
  25. * Object prototype.
  26. */
  27. export function getVariableValues(
  28. schema: GraphQLSchema,
  29. varDefNodes: VariableDefinitionNode[],
  30. inputs: { [key: string]: any },
  31. options?: { maxErrors?: number },
  32. ): CoercedVariableValues;
  33. /**
  34. * Prepares an object map of argument values given a list of argument
  35. * definitions and list of argument AST nodes.
  36. *
  37. * Note: The returned value is a plain Object with a prototype, since it is
  38. * exposed to user code. Care should be taken to not pull values from the
  39. * Object prototype.
  40. */
  41. export function getArgumentValues(
  42. def: GraphQLField<any, any> | GraphQLDirective,
  43. node: FieldNode | DirectiveNode,
  44. variableValues?: Maybe<{ [key: string]: any }>,
  45. ): { [key: string]: any };
  46. /**
  47. * Prepares an object map of argument values given a directive definition
  48. * and a AST node which may contain directives. Optionally also accepts a map
  49. * of variable values.
  50. *
  51. * If the directive does not exist on the node, returns undefined.
  52. *
  53. * Note: The returned value is a plain Object with a prototype, since it is
  54. * exposed to user code. Care should be taken to not pull values from the
  55. * Object prototype.
  56. */
  57. export function getDirectiveValues(
  58. directiveDef: GraphQLDirective,
  59. node: {
  60. readonly directives?: ReadonlyArray<DirectiveNode>;
  61. },
  62. variableValues?: Maybe<{ [key: string]: any }>,
  63. ): undefined | { [key: string]: any };