values.d.ts 2.2 KB

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