index.d.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import type { KeyValueCache } from '@apollo/utils.keyvaluecache';
  2. import type { DocumentNode, ExecutionResult, GraphQLError, GraphQLFormattedError, GraphQLSchema, OperationDefinitionNode } from 'graphql';
  3. import type { Logger } from '@apollo/utils.logger';
  4. import type { Trace } from '@apollo/usage-reporting-protobuf';
  5. import type { FetcherHeaders } from '@apollo/utils.fetcher';
  6. export interface GatewayInterface {
  7. onSchemaLoadOrUpdate(callback: GatewaySchemaLoadOrUpdateCallback): GatewayUnsubscriber;
  8. load(options: {
  9. apollo: GatewayApolloConfig;
  10. }): Promise<GatewayLoadResult>;
  11. stop(): Promise<void>;
  12. }
  13. export type GatewaySchemaLoadOrUpdateCallback = (schemaContext: {
  14. apiSchema: GraphQLSchema;
  15. coreSupergraphSdl: string;
  16. }) => void;
  17. export type GatewayUnsubscriber = () => void;
  18. export interface GatewayApolloConfig {
  19. key?: string;
  20. keyHash?: string;
  21. graphRef?: string;
  22. }
  23. export interface GatewayLoadResult {
  24. executor: GatewayExecutor | null;
  25. }
  26. export type GatewayExecutor = (requestContext: GatewayGraphQLRequestContext) => Promise<GatewayExecutionResult>;
  27. export type GatewayExecutionResult = ExecutionResult<Record<string, any>, Record<string, any>>;
  28. export interface GatewayGraphQLRequestContext<TContext = Record<string, any>> {
  29. readonly request: GatewayGraphQLRequest;
  30. readonly response?: GatewayGraphQLResponse;
  31. logger: Logger;
  32. readonly schema: GraphQLSchema;
  33. readonly schemaHash: GatewaySchemaHash;
  34. readonly context: TContext;
  35. readonly cache: KeyValueCache;
  36. readonly queryHash: string;
  37. readonly document: DocumentNode;
  38. readonly source: string;
  39. readonly operationName: string | null;
  40. readonly operation: OperationDefinitionNode;
  41. readonly errors?: ReadonlyArray<GraphQLError>;
  42. readonly metrics: GatewayGraphQLRequestMetrics;
  43. debug?: boolean;
  44. readonly overallCachePolicy: any;
  45. readonly requestIsBatched?: boolean;
  46. }
  47. export interface GatewayGraphQLRequest {
  48. query?: string;
  49. operationName?: string;
  50. variables?: Record<string, any>;
  51. extensions?: Record<string, any>;
  52. http?: GatewayHTTPRequest;
  53. }
  54. export interface GatewayHTTPRequest {
  55. readonly method: string;
  56. readonly url: string;
  57. readonly headers: FetcherHeaders;
  58. }
  59. export interface GatewayGraphQLResponse {
  60. data?: Record<string, any> | null;
  61. errors?: ReadonlyArray<GraphQLFormattedError>;
  62. extensions?: Record<string, any>;
  63. http?: GatewayHTTPResponse;
  64. }
  65. export interface GatewayHTTPResponse {
  66. readonly headers: FetcherHeaders;
  67. status?: number;
  68. }
  69. export type GatewaySchemaHash = string & {
  70. __fauxpaque: 'SchemaHash';
  71. };
  72. export interface NonFtv1ErrorPath {
  73. subgraph: string;
  74. path: GraphQLError['path'];
  75. }
  76. export interface GatewayGraphQLRequestMetrics {
  77. captureTraces?: boolean;
  78. persistedQueryHit?: boolean;
  79. persistedQueryRegister?: boolean;
  80. responseCacheHit?: boolean;
  81. forbiddenOperation?: boolean;
  82. registeredOperation?: boolean;
  83. startHrTime?: [number, number];
  84. queryPlanTrace?: Trace.QueryPlanNode;
  85. nonFtv1ErrorPaths?: NonFtv1ErrorPath[];
  86. }
  87. export interface GatewayCachePolicy extends GatewayCacheHint {
  88. replace(hint: GatewayCacheHint): void;
  89. restrict(hint: GatewayCacheHint): void;
  90. policyIfCacheable(): Required<GatewayCacheHint> | null;
  91. }
  92. export interface GatewayCacheHint {
  93. maxAge?: number;
  94. scope?: any;
  95. }
  96. //# sourceMappingURL=index.d.ts.map