graphql.d.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import type { Maybe } from './jsutils/Maybe';
  2. import type { Source } from './language/source';
  3. import type {
  4. GraphQLFieldResolver,
  5. GraphQLTypeResolver,
  6. } from './type/definition';
  7. import type { GraphQLSchema } from './type/schema';
  8. import type { ExecutionResult } 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. * typeResolver:
  44. * A type resolver function to use when none is provided by the schema.
  45. * If not provided, the default type resolver is used (which looks for a
  46. * `__typename` field or alternatively calls the `isTypeOf` method).
  47. */
  48. export interface GraphQLArgs {
  49. schema: GraphQLSchema;
  50. source: string | Source;
  51. rootValue?: unknown;
  52. contextValue?: unknown;
  53. variableValues?: Maybe<{
  54. readonly [variable: string]: unknown;
  55. }>;
  56. operationName?: Maybe<string>;
  57. fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
  58. typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;
  59. }
  60. export declare function graphql(args: GraphQLArgs): Promise<ExecutionResult>;
  61. /**
  62. * The graphqlSync function also fulfills GraphQL operations by parsing,
  63. * validating, and executing a GraphQL document along side a GraphQL schema.
  64. * However, it guarantees to complete synchronously (or throw an error) assuming
  65. * that all field resolvers are also synchronous.
  66. */
  67. export declare function graphqlSync(args: GraphQLArgs): ExecutionResult;