graphql.d.ts 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import Maybe from './tsutils/Maybe';
  2. import { Source } from './language/source';
  3. import { GraphQLSchema } from './type/schema';
  4. import { GraphQLFieldResolver, GraphQLTypeResolver } from './type/definition';
  5. import {
  6. ExecutionResult,
  7. ExecutionResultDataDefault,
  8. } from './execution/execute';
  9. /**
  10. * This is the primary entry point function for fulfilling GraphQL operations
  11. * by parsing, validating, and executing a GraphQL document along side a
  12. * GraphQL schema.
  13. *
  14. * More sophisticated GraphQL servers, such as those which persist queries,
  15. * may wish to separate the validation and execution phases to a static time
  16. * tooling step, and a server runtime step.
  17. *
  18. * Accepts either an object with named arguments, or individual arguments:
  19. *
  20. * schema:
  21. * The GraphQL type system to use when validating and executing a query.
  22. * source:
  23. * A GraphQL language formatted string representing the requested operation.
  24. * rootValue:
  25. * The value provided as the first argument to resolver functions on the top
  26. * level type (e.g. the query object type).
  27. * contextValue:
  28. * The context value is provided as an argument to resolver functions after
  29. * field arguments. It is used to pass shared information useful at any point
  30. * during executing this query, for example the currently logged in user and
  31. * connections to databases or other services.
  32. * variableValues:
  33. * A mapping of variable name to runtime value to use for all variables
  34. * defined in the requestString.
  35. * operationName:
  36. * The name of the operation to use if requestString contains multiple
  37. * possible operations. Can be omitted if requestString contains only
  38. * one operation.
  39. * fieldResolver:
  40. * A resolver function to use when one is not provided by the schema.
  41. * If not provided, the default field resolver is used (which looks for a
  42. * value or method on the source value with the field's name).
  43. */
  44. export interface GraphQLArgs {
  45. schema: GraphQLSchema;
  46. source: string | Source;
  47. rootValue?: any;
  48. contextValue?: any;
  49. variableValues?: Maybe<{ [key: string]: any }>;
  50. operationName?: Maybe<string>;
  51. fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
  52. typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;
  53. }
  54. export function graphql<TData = ExecutionResultDataDefault>(
  55. args: GraphQLArgs,
  56. ): Promise<ExecutionResult<TData>>;
  57. export function graphql<TData = ExecutionResultDataDefault>(
  58. schema: GraphQLSchema,
  59. source: Source | string,
  60. rootValue?: any,
  61. contextValue?: any,
  62. variableValues?: Maybe<{ [key: string]: any }>,
  63. operationName?: Maybe<string>,
  64. fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
  65. typeResolver?: Maybe<GraphQLTypeResolver<any, any>>,
  66. ): Promise<ExecutionResult<TData>>;
  67. /**
  68. * The graphqlSync function also fulfills GraphQL operations by parsing,
  69. * validating, and executing a GraphQL document along side a GraphQL schema.
  70. * However, it guarantees to complete synchronously (or throw an error) assuming
  71. * that all field resolvers are also synchronous.
  72. */
  73. export function graphqlSync<TData = ExecutionResultDataDefault>(
  74. args: GraphQLArgs,
  75. ): ExecutionResult<TData>;
  76. export function graphqlSync<TData = ExecutionResultDataDefault>(
  77. schema: GraphQLSchema,
  78. source: Source | string,
  79. rootValue?: any,
  80. contextValue?: any,
  81. variableValues?: Maybe<{ [key: string]: any }>,
  82. operationName?: Maybe<string>,
  83. fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
  84. typeResolver?: Maybe<GraphQLTypeResolver<any, any>>,
  85. ): ExecutionResult<TData>;