graphql.d.ts 3.3 KB

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