subscribe.d.ts 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { Maybe } from '../jsutils/Maybe';
  2. import { DocumentNode } from '../language/ast';
  3. import { ExecutionResult } from '../execution/execute';
  4. import { GraphQLSchema } from '../type/schema';
  5. import { GraphQLFieldResolver } from '../type/definition';
  6. export interface SubscriptionArgs {
  7. schema: GraphQLSchema;
  8. document: DocumentNode;
  9. rootValue?: any;
  10. contextValue?: any;
  11. variableValues?: Maybe<Record<string, any>>;
  12. operationName?: Maybe<string>;
  13. fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
  14. subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
  15. }
  16. /**
  17. * Implements the "Subscribe" algorithm described in the GraphQL specification.
  18. *
  19. * Returns a Promise which resolves to either an AsyncIterator (if successful)
  20. * or an ExecutionResult (client error). The promise will be rejected if a
  21. * server error occurs.
  22. *
  23. * If the client-provided arguments to this function do not result in a
  24. * compliant subscription, a GraphQL Response (ExecutionResult) with
  25. * descriptive errors and no data will be returned.
  26. *
  27. * If the the source stream could not be created due to faulty subscription
  28. * resolver logic or underlying systems, the promise will resolve to a single
  29. * ExecutionResult containing `errors` and no `data`.
  30. *
  31. * If the operation succeeded, the promise resolves to an AsyncIterator, which
  32. * yields a stream of ExecutionResults representing the response stream.
  33. *
  34. * Accepts either an object with named arguments, or individual arguments.
  35. */
  36. export function subscribe(
  37. args: SubscriptionArgs,
  38. ): Promise<AsyncIterableIterator<ExecutionResult> | ExecutionResult>;
  39. export function subscribe(
  40. schema: GraphQLSchema,
  41. document: DocumentNode,
  42. rootValue?: any,
  43. contextValue?: any,
  44. variableValues?: Maybe<{ [key: string]: any }>,
  45. operationName?: Maybe<string>,
  46. fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
  47. subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
  48. ): Promise<AsyncIterableIterator<ExecutionResult> | ExecutionResult>;
  49. /**
  50. * Implements the "CreateSourceEventStream" algorithm described in the
  51. * GraphQL specification, resolving the subscription source event stream.
  52. *
  53. * Returns a Promise<AsyncIterable>.
  54. *
  55. * If the client-provided invalid arguments, the source stream could not be
  56. * created, or the resolver did not return an AsyncIterable, this function will
  57. * will throw an error, which should be caught and handled by the caller.
  58. *
  59. * A Source Event Stream represents a sequence of events, each of which triggers
  60. * a GraphQL execution for that event.
  61. *
  62. * This may be useful when hosting the stateful subscription service in a
  63. * different process or machine than the stateless GraphQL execution engine,
  64. * or otherwise separating these two steps. For more on this, see the
  65. * "Supporting Subscriptions at Scale" information in the GraphQL specification.
  66. */
  67. export function createSourceEventStream(
  68. schema: GraphQLSchema,
  69. document: DocumentNode,
  70. rootValue?: any,
  71. contextValue?: any,
  72. variableValues?: { [key: string]: any },
  73. operationName?: Maybe<string>,
  74. fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
  75. ): Promise<AsyncIterable<any> | ExecutionResult>;