ApolloServer.d.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import type { GatewayExecutor } from '@apollo/server-gateway-interface';
  2. import { type KeyValueCache } from '@apollo/utils.keyvaluecache';
  3. import type { Logger } from '@apollo/utils.logger';
  4. import type { WithRequired } from '@apollo/utils.withrequired';
  5. import { type Resolvable } from './utils/resolvable.js';
  6. import { type DocumentNode, type FormattedExecutionResult, type GraphQLFieldResolver, type GraphQLFormattedError, type GraphQLSchema, type ParseOptions, type TypedQueryDocumentNode, type ValidationRule } from 'graphql';
  7. import type { ExecuteOperationOptions, VariableValues } from './externalTypes/graphql.js';
  8. import type { ApolloConfig, ApolloServerOptions, ApolloServerPlugin, BaseContext, ContextThunk, DocumentStore, GraphQLRequest, GraphQLResponse, HTTPGraphQLHead, HTTPGraphQLRequest, HTTPGraphQLResponse, LandingPage, PersistedQueryOptions } from './externalTypes/index.js';
  9. import type { GraphQLExperimentalIncrementalExecutionResults } from './incrementalDeliveryPolyfill.js';
  10. import { SchemaManager } from './utils/schemaManager.js';
  11. export type SchemaDerivedData = {
  12. schema: GraphQLSchema;
  13. documentStore: DocumentStore | null;
  14. documentStoreKeyPrefix: string;
  15. };
  16. type RunningServerState = {
  17. schemaManager: SchemaManager;
  18. landingPage: LandingPage | null;
  19. };
  20. type ServerState = {
  21. phase: 'initialized';
  22. schemaManager: SchemaManager;
  23. } | {
  24. phase: 'starting';
  25. barrier: Resolvable<void>;
  26. schemaManager: SchemaManager;
  27. startedInBackground: boolean;
  28. } | {
  29. phase: 'failed to start';
  30. error: Error;
  31. } | ({
  32. phase: 'started';
  33. drainServers: (() => Promise<void>) | null;
  34. toDispose: (() => Promise<void>)[];
  35. toDisposeLast: (() => Promise<void>)[];
  36. } & RunningServerState) | ({
  37. phase: 'draining';
  38. barrier: Resolvable<void>;
  39. } & RunningServerState) | {
  40. phase: 'stopping';
  41. barrier: Resolvable<void>;
  42. } | {
  43. phase: 'stopped';
  44. stopError: Error | null;
  45. };
  46. export interface ApolloServerInternals<TContext extends BaseContext> {
  47. state: ServerState;
  48. gatewayExecutor: GatewayExecutor | null;
  49. dangerouslyDisableValidation?: boolean;
  50. formatError?: (formattedError: GraphQLFormattedError, error: unknown) => GraphQLFormattedError;
  51. includeStacktraceInErrorResponses: boolean;
  52. persistedQueries?: WithRequired<PersistedQueryOptions, 'cache'>;
  53. nodeEnv: string;
  54. allowBatchedHttpRequests: boolean;
  55. apolloConfig: ApolloConfig;
  56. plugins: ApolloServerPlugin<TContext>[];
  57. parseOptions: ParseOptions;
  58. stopOnTerminationSignals: boolean | undefined;
  59. csrfPreventionRequestHeaders: string[] | null;
  60. rootValue?: ((parsedQuery: DocumentNode) => unknown) | unknown;
  61. validationRules: Array<ValidationRule>;
  62. fieldResolver?: GraphQLFieldResolver<any, TContext>;
  63. status400ForVariableCoercionErrors?: boolean;
  64. __testing_incrementalExecutionResults?: GraphQLExperimentalIncrementalExecutionResults;
  65. stringifyResult: (value: FormattedExecutionResult) => string | Promise<string>;
  66. }
  67. export declare class ApolloServer<in out TContext extends BaseContext = BaseContext> {
  68. private internals;
  69. readonly cache: KeyValueCache<string>;
  70. readonly logger: Logger;
  71. constructor(config: ApolloServerOptions<TContext>);
  72. start(): Promise<void>;
  73. startInBackgroundHandlingStartupErrorsByLoggingAndFailingAllRequests(): void;
  74. private _start;
  75. private maybeRegisterTerminationSignalHandlers;
  76. private _ensureStarted;
  77. assertStarted(expressionForError: string): void;
  78. private logStartupError;
  79. private static constructSchema;
  80. private static generateSchemaDerivedData;
  81. stop(): Promise<void>;
  82. private addDefaultPlugins;
  83. addPlugin(plugin: ApolloServerPlugin<TContext>): void;
  84. executeHTTPGraphQLRequest({ httpGraphQLRequest, context, }: {
  85. httpGraphQLRequest: HTTPGraphQLRequest;
  86. context: ContextThunk<TContext>;
  87. }): Promise<HTTPGraphQLResponse>;
  88. private errorResponse;
  89. private prefersHTML;
  90. executeOperation<TData = Record<string, unknown>, TVariables extends VariableValues = VariableValues>(this: ApolloServer<BaseContext>, request: Omit<GraphQLRequest<TVariables>, 'query'> & {
  91. query?: string | DocumentNode | TypedQueryDocumentNode<TData, TVariables>;
  92. }): Promise<GraphQLResponse<TData>>;
  93. executeOperation<TData = Record<string, unknown>, TVariables extends VariableValues = VariableValues>(request: Omit<GraphQLRequest<TVariables>, 'query'> & {
  94. query?: string | DocumentNode | TypedQueryDocumentNode<TData, TVariables>;
  95. }, options?: ExecuteOperationOptions<TContext>): Promise<GraphQLResponse<TData>>;
  96. }
  97. export declare function internalExecuteOperation<TContext extends BaseContext>({ server, graphQLRequest, internals, schemaDerivedData, sharedResponseHTTPGraphQLHead, }: {
  98. server: ApolloServer<TContext>;
  99. graphQLRequest: GraphQLRequest;
  100. internals: ApolloServerInternals<TContext>;
  101. schemaDerivedData: SchemaDerivedData;
  102. sharedResponseHTTPGraphQLHead: HTTPGraphQLHead | null;
  103. }, options: ExecuteOperationOptions<TContext>): Promise<GraphQLResponse>;
  104. export type ImplicitlyInstallablePlugin<TContext extends BaseContext> = ApolloServerPlugin<TContext> & {
  105. __internal_installed_implicitly__: boolean;
  106. };
  107. export declare function isImplicitlyInstallablePlugin<TContext extends BaseContext>(p: ApolloServerPlugin<TContext>): p is ImplicitlyInstallablePlugin<TContext>;
  108. export declare const MEDIA_TYPES: {
  109. APPLICATION_JSON: string;
  110. APPLICATION_JSON_GRAPHQL_CALLBACK: string;
  111. APPLICATION_GRAPHQL_RESPONSE_JSON: string;
  112. MULTIPART_MIXED_NO_DEFER_SPEC: string;
  113. MULTIPART_MIXED_EXPERIMENTAL: string;
  114. TEXT_HTML: string;
  115. };
  116. export declare function chooseContentTypeForSingleResultResponse(head: HTTPGraphQLHead): string | null;
  117. export {};
  118. //# sourceMappingURL=ApolloServer.d.ts.map