@depup/apollo__server 5.5.0-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -0
- package/changes.json +46 -0
- package/dist/cjs/ApolloServer.d.ts +126 -0
- package/dist/cjs/ApolloServer.d.ts.map +1 -0
- package/dist/cjs/ApolloServer.js +726 -0
- package/dist/cjs/ApolloServer.js.map +1 -0
- package/dist/cjs/cachePolicy.d.ts +3 -0
- package/dist/cjs/cachePolicy.d.ts.map +1 -0
- package/dist/cjs/cachePolicy.js +33 -0
- package/dist/cjs/cachePolicy.js.map +1 -0
- package/dist/cjs/determineApolloConfig.d.ts +4 -0
- package/dist/cjs/determineApolloConfig.d.ts.map +1 -0
- package/dist/cjs/determineApolloConfig.js +58 -0
- package/dist/cjs/determineApolloConfig.js.map +1 -0
- package/dist/cjs/errorNormalize.d.ts +12 -0
- package/dist/cjs/errorNormalize.d.ts.map +1 -0
- package/dist/cjs/errorNormalize.js +71 -0
- package/dist/cjs/errorNormalize.js.map +1 -0
- package/dist/cjs/errors/index.d.ts +16 -0
- package/dist/cjs/errors/index.d.ts.map +1 -0
- package/dist/cjs/errors/index.js +28 -0
- package/dist/cjs/errors/index.js.map +1 -0
- package/dist/cjs/externalTypes/constructor.d.ts +78 -0
- package/dist/cjs/externalTypes/constructor.d.ts.map +1 -0
- package/dist/cjs/externalTypes/constructor.js +3 -0
- package/dist/cjs/externalTypes/constructor.js.map +1 -0
- package/dist/cjs/externalTypes/context.d.ts +4 -0
- package/dist/cjs/externalTypes/context.d.ts.map +1 -0
- package/dist/cjs/externalTypes/context.js +3 -0
- package/dist/cjs/externalTypes/context.js.map +1 -0
- package/dist/cjs/externalTypes/graphql.d.ts +41 -0
- package/dist/cjs/externalTypes/graphql.d.ts.map +1 -0
- package/dist/cjs/externalTypes/graphql.js +3 -0
- package/dist/cjs/externalTypes/graphql.js.map +1 -0
- package/dist/cjs/externalTypes/http.d.ts +22 -0
- package/dist/cjs/externalTypes/http.d.ts.map +1 -0
- package/dist/cjs/externalTypes/http.js +3 -0
- package/dist/cjs/externalTypes/http.js.map +1 -0
- package/dist/cjs/externalTypes/incrementalDeliveryPolyfillAlpha2.d.ts +28 -0
- package/dist/cjs/externalTypes/incrementalDeliveryPolyfillAlpha2.d.ts.map +1 -0
- package/dist/cjs/externalTypes/incrementalDeliveryPolyfillAlpha2.js +3 -0
- package/dist/cjs/externalTypes/incrementalDeliveryPolyfillAlpha2.js.map +1 -0
- package/dist/cjs/externalTypes/incrementalDeliveryPolyfillAlpha9.d.ts +43 -0
- package/dist/cjs/externalTypes/incrementalDeliveryPolyfillAlpha9.d.ts.map +1 -0
- package/dist/cjs/externalTypes/incrementalDeliveryPolyfillAlpha9.js +3 -0
- package/dist/cjs/externalTypes/incrementalDeliveryPolyfillAlpha9.js.map +1 -0
- package/dist/cjs/externalTypes/index.d.ts +9 -0
- package/dist/cjs/externalTypes/index.d.ts.map +1 -0
- package/dist/cjs/externalTypes/index.js +3 -0
- package/dist/cjs/externalTypes/index.js.map +1 -0
- package/dist/cjs/externalTypes/plugins.d.ts +75 -0
- package/dist/cjs/externalTypes/plugins.d.ts.map +1 -0
- package/dist/cjs/externalTypes/plugins.js +3 -0
- package/dist/cjs/externalTypes/plugins.js.map +1 -0
- package/dist/cjs/externalTypes/requestPipeline.d.ts +50 -0
- package/dist/cjs/externalTypes/requestPipeline.d.ts.map +1 -0
- package/dist/cjs/externalTypes/requestPipeline.js +3 -0
- package/dist/cjs/externalTypes/requestPipeline.js.map +1 -0
- package/dist/cjs/generated/packageVersion.d.ts +2 -0
- package/dist/cjs/generated/packageVersion.d.ts.map +1 -0
- package/dist/cjs/generated/packageVersion.js +5 -0
- package/dist/cjs/generated/packageVersion.js.map +1 -0
- package/dist/cjs/httpBatching.d.ts +4 -0
- package/dist/cjs/httpBatching.d.ts.map +1 -0
- package/dist/cjs/httpBatching.js +58 -0
- package/dist/cjs/httpBatching.js.map +1 -0
- package/dist/cjs/incrementalDeliveryPolyfill.d.ts +82 -0
- package/dist/cjs/incrementalDeliveryPolyfill.d.ts.map +1 -0
- package/dist/cjs/incrementalDeliveryPolyfill.js +74 -0
- package/dist/cjs/incrementalDeliveryPolyfill.js.map +1 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/internalErrorClasses.d.ts +28 -0
- package/dist/cjs/internalErrorClasses.d.ts.map +1 -0
- package/dist/cjs/internalErrorClasses.js +91 -0
- package/dist/cjs/internalErrorClasses.js.map +1 -0
- package/dist/cjs/internalPlugin.d.ts +9 -0
- package/dist/cjs/internalPlugin.d.ts.map +1 -0
- package/dist/cjs/internalPlugin.js +11 -0
- package/dist/cjs/internalPlugin.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/plugin/cacheControl/index.d.ts +9 -0
- package/dist/cjs/plugin/cacheControl/index.d.ts.map +1 -0
- package/dist/cjs/plugin/cacheControl/index.js +223 -0
- package/dist/cjs/plugin/cacheControl/index.js.map +1 -0
- package/dist/cjs/plugin/disableSuggestions/index.d.ts +3 -0
- package/dist/cjs/plugin/disableSuggestions/index.d.ts.map +1 -0
- package/dist/cjs/plugin/disableSuggestions/index.js +22 -0
- package/dist/cjs/plugin/disableSuggestions/index.js.map +1 -0
- package/dist/cjs/plugin/disabled/index.d.ts +7 -0
- package/dist/cjs/plugin/disabled/index.d.ts.map +1 -0
- package/dist/cjs/plugin/disabled/index.js +30 -0
- package/dist/cjs/plugin/disabled/index.js.map +1 -0
- package/dist/cjs/plugin/drainHttpServer/index.d.ts +8 -0
- package/dist/cjs/plugin/drainHttpServer/index.d.ts.map +1 -0
- package/dist/cjs/plugin/drainHttpServer/index.js +19 -0
- package/dist/cjs/plugin/drainHttpServer/index.js.map +1 -0
- package/dist/cjs/plugin/drainHttpServer/stoppable.d.ts +10 -0
- package/dist/cjs/plugin/drainHttpServer/stoppable.d.ts.map +1 -0
- package/dist/cjs/plugin/drainHttpServer/stoppable.js +54 -0
- package/dist/cjs/plugin/drainHttpServer/stoppable.js.map +1 -0
- package/dist/cjs/plugin/inlineTrace/index.d.ts +8 -0
- package/dist/cjs/plugin/inlineTrace/index.d.ts.map +1 -0
- package/dist/cjs/plugin/inlineTrace/index.js +70 -0
- package/dist/cjs/plugin/inlineTrace/index.js.map +1 -0
- package/dist/cjs/plugin/landingPage/default/getEmbeddedHTML.d.ts +4 -0
- package/dist/cjs/plugin/landingPage/default/getEmbeddedHTML.d.ts.map +1 -0
- package/dist/cjs/plugin/landingPage/default/getEmbeddedHTML.js +143 -0
- package/dist/cjs/plugin/landingPage/default/getEmbeddedHTML.js.map +1 -0
- package/dist/cjs/plugin/landingPage/default/index.d.ts +9 -0
- package/dist/cjs/plugin/landingPage/default/index.d.ts.map +1 -0
- package/dist/cjs/plugin/landingPage/default/index.js +146 -0
- package/dist/cjs/plugin/landingPage/default/index.js.map +1 -0
- package/dist/cjs/plugin/landingPage/default/types.d.ts +56 -0
- package/dist/cjs/plugin/landingPage/default/types.d.ts.map +1 -0
- package/dist/cjs/plugin/landingPage/default/types.js +3 -0
- package/dist/cjs/plugin/landingPage/default/types.js.map +1 -0
- package/dist/cjs/plugin/schemaIsSubgraph.d.ts +3 -0
- package/dist/cjs/plugin/schemaIsSubgraph.d.ts.map +1 -0
- package/dist/cjs/plugin/schemaIsSubgraph.js +23 -0
- package/dist/cjs/plugin/schemaIsSubgraph.js.map +1 -0
- package/dist/cjs/plugin/schemaReporting/index.d.ts +10 -0
- package/dist/cjs/plugin/schemaReporting/index.d.ts.map +1 -0
- package/dist/cjs/plugin/schemaReporting/index.js +104 -0
- package/dist/cjs/plugin/schemaReporting/index.js.map +1 -0
- package/dist/cjs/plugin/schemaReporting/schemaReporter.d.ts +33 -0
- package/dist/cjs/plugin/schemaReporting/schemaReporter.d.ts.map +1 -0
- package/dist/cjs/plugin/schemaReporting/schemaReporter.js +147 -0
- package/dist/cjs/plugin/schemaReporting/schemaReporter.js.map +1 -0
- package/dist/cjs/plugin/subscriptionCallback/index.d.ts +12 -0
- package/dist/cjs/plugin/subscriptionCallback/index.d.ts.map +1 -0
- package/dist/cjs/plugin/subscriptionCallback/index.js +434 -0
- package/dist/cjs/plugin/subscriptionCallback/index.js.map +1 -0
- package/dist/cjs/plugin/traceTreeBuilder.d.ts +25 -0
- package/dist/cjs/plugin/traceTreeBuilder.d.ts.map +1 -0
- package/dist/cjs/plugin/traceTreeBuilder.js +201 -0
- package/dist/cjs/plugin/traceTreeBuilder.js.map +1 -0
- package/dist/cjs/plugin/usageReporting/defaultSendOperationsAsTrace.d.ts +3 -0
- package/dist/cjs/plugin/usageReporting/defaultSendOperationsAsTrace.d.ts.map +1 -0
- package/dist/cjs/plugin/usageReporting/defaultSendOperationsAsTrace.js +44 -0
- package/dist/cjs/plugin/usageReporting/defaultSendOperationsAsTrace.js.map +1 -0
- package/dist/cjs/plugin/usageReporting/durationHistogram.d.ts +16 -0
- package/dist/cjs/plugin/usageReporting/durationHistogram.d.ts.map +1 -0
- package/dist/cjs/plugin/usageReporting/durationHistogram.js +68 -0
- package/dist/cjs/plugin/usageReporting/durationHistogram.js.map +1 -0
- package/dist/cjs/plugin/usageReporting/index.d.ts +3 -0
- package/dist/cjs/plugin/usageReporting/index.d.ts.map +1 -0
- package/dist/cjs/plugin/usageReporting/index.js +6 -0
- package/dist/cjs/plugin/usageReporting/index.js.map +1 -0
- package/dist/cjs/plugin/usageReporting/iterateOverTrace.d.ts +7 -0
- package/dist/cjs/plugin/usageReporting/iterateOverTrace.d.ts.map +1 -0
- package/dist/cjs/plugin/usageReporting/iterateOverTrace.js +81 -0
- package/dist/cjs/plugin/usageReporting/iterateOverTrace.js.map +1 -0
- package/dist/cjs/plugin/usageReporting/operationDerivedDataCache.d.ts +12 -0
- package/dist/cjs/plugin/usageReporting/operationDerivedDataCache.d.ts.map +1 -0
- package/dist/cjs/plugin/usageReporting/operationDerivedDataCache.js +33 -0
- package/dist/cjs/plugin/usageReporting/operationDerivedDataCache.js.map +1 -0
- package/dist/cjs/plugin/usageReporting/options.d.ts +60 -0
- package/dist/cjs/plugin/usageReporting/options.d.ts.map +1 -0
- package/dist/cjs/plugin/usageReporting/options.js +3 -0
- package/dist/cjs/plugin/usageReporting/options.js.map +1 -0
- package/dist/cjs/plugin/usageReporting/plugin.d.ts +7 -0
- package/dist/cjs/plugin/usageReporting/plugin.d.ts.map +1 -0
- package/dist/cjs/plugin/usageReporting/plugin.js +494 -0
- package/dist/cjs/plugin/usageReporting/plugin.js.map +1 -0
- package/dist/cjs/plugin/usageReporting/stats.d.ts +96 -0
- package/dist/cjs/plugin/usageReporting/stats.d.ts.map +1 -0
- package/dist/cjs/plugin/usageReporting/stats.js +289 -0
- package/dist/cjs/plugin/usageReporting/stats.js.map +1 -0
- package/dist/cjs/plugin/usageReporting/traceDetails.d.ts +4 -0
- package/dist/cjs/plugin/usageReporting/traceDetails.d.ts.map +1 -0
- package/dist/cjs/plugin/usageReporting/traceDetails.js +63 -0
- package/dist/cjs/plugin/usageReporting/traceDetails.js.map +1 -0
- package/dist/cjs/preventCsrf.d.ts +4 -0
- package/dist/cjs/preventCsrf.d.ts.map +1 -0
- package/dist/cjs/preventCsrf.js +41 -0
- package/dist/cjs/preventCsrf.js.map +1 -0
- package/dist/cjs/requestPipeline.d.ts +9 -0
- package/dist/cjs/requestPipeline.d.ts.map +1 -0
- package/dist/cjs/requestPipeline.js +371 -0
- package/dist/cjs/requestPipeline.js.map +1 -0
- package/dist/cjs/runHttpQuery.d.ts +15 -0
- package/dist/cjs/runHttpQuery.d.ts.map +1 -0
- package/dist/cjs/runHttpQuery.js +230 -0
- package/dist/cjs/runHttpQuery.js.map +1 -0
- package/dist/cjs/standalone/index.d.ts +25 -0
- package/dist/cjs/standalone/index.d.ts.map +1 -0
- package/dist/cjs/standalone/index.js +97 -0
- package/dist/cjs/standalone/index.js.map +1 -0
- package/dist/cjs/utils/HeaderMap.d.ts +8 -0
- package/dist/cjs/utils/HeaderMap.d.ts.map +1 -0
- package/dist/cjs/utils/HeaderMap.js +20 -0
- package/dist/cjs/utils/HeaderMap.js.map +1 -0
- package/dist/cjs/utils/UnreachableCaseError.d.ts +4 -0
- package/dist/cjs/utils/UnreachableCaseError.d.ts.map +1 -0
- package/dist/cjs/utils/UnreachableCaseError.js +10 -0
- package/dist/cjs/utils/UnreachableCaseError.js.map +1 -0
- package/dist/cjs/utils/computeCoreSchemaHash.d.ts +2 -0
- package/dist/cjs/utils/computeCoreSchemaHash.d.ts.map +1 -0
- package/dist/cjs/utils/computeCoreSchemaHash.js +8 -0
- package/dist/cjs/utils/computeCoreSchemaHash.js.map +1 -0
- package/dist/cjs/utils/invokeHooks.d.ts +7 -0
- package/dist/cjs/utils/invokeHooks.d.ts.map +1 -0
- package/dist/cjs/utils/invokeHooks.js +36 -0
- package/dist/cjs/utils/invokeHooks.js.map +1 -0
- package/dist/cjs/utils/isDefined.d.ts +2 -0
- package/dist/cjs/utils/isDefined.d.ts.map +1 -0
- package/dist/cjs/utils/isDefined.js +7 -0
- package/dist/cjs/utils/isDefined.js.map +1 -0
- package/dist/cjs/utils/makeGatewayGraphQLRequestContext.d.ts +5 -0
- package/dist/cjs/utils/makeGatewayGraphQLRequestContext.d.ts.map +1 -0
- package/dist/cjs/utils/makeGatewayGraphQLRequestContext.js +96 -0
- package/dist/cjs/utils/makeGatewayGraphQLRequestContext.js.map +1 -0
- package/dist/cjs/utils/resolvable.d.ts +7 -0
- package/dist/cjs/utils/resolvable.d.ts.map +1 -0
- package/dist/cjs/utils/resolvable.js +14 -0
- package/dist/cjs/utils/resolvable.js.map +1 -0
- package/dist/cjs/utils/schemaInstrumentation.d.ts +16 -0
- package/dist/cjs/utils/schemaInstrumentation.d.ts.map +1 -0
- package/dist/cjs/utils/schemaInstrumentation.js +75 -0
- package/dist/cjs/utils/schemaInstrumentation.js.map +1 -0
- package/dist/cjs/utils/schemaManager.d.ts +31 -0
- package/dist/cjs/utils/schemaManager.d.ts.map +1 -0
- package/dist/cjs/utils/schemaManager.js +103 -0
- package/dist/cjs/utils/schemaManager.js.map +1 -0
- package/dist/cjs/utils/urlForHttpServer.d.ts +3 -0
- package/dist/cjs/utils/urlForHttpServer.d.ts.map +1 -0
- package/dist/cjs/utils/urlForHttpServer.js +15 -0
- package/dist/cjs/utils/urlForHttpServer.js.map +1 -0
- package/dist/cjs/validationRules/NoIntrospection.d.ts +3 -0
- package/dist/cjs/validationRules/NoIntrospection.d.ts.map +1 -0
- package/dist/cjs/validationRules/NoIntrospection.js +19 -0
- package/dist/cjs/validationRules/NoIntrospection.js.map +1 -0
- package/dist/cjs/validationRules/RecursiveSelectionsLimit.d.ts +4 -0
- package/dist/cjs/validationRules/RecursiveSelectionsLimit.d.ts.map +1 -0
- package/dist/cjs/validationRules/RecursiveSelectionsLimit.js +150 -0
- package/dist/cjs/validationRules/RecursiveSelectionsLimit.js.map +1 -0
- package/dist/cjs/validationRules/index.d.ts +3 -0
- package/dist/cjs/validationRules/index.d.ts.map +1 -0
- package/dist/cjs/validationRules/index.js +9 -0
- package/dist/cjs/validationRules/index.js.map +1 -0
- package/dist/esm/ApolloServer.d.ts +126 -0
- package/dist/esm/ApolloServer.d.ts.map +1 -0
- package/dist/esm/ApolloServer.js +683 -0
- package/dist/esm/ApolloServer.js.map +1 -0
- package/dist/esm/cachePolicy.d.ts +3 -0
- package/dist/esm/cachePolicy.d.ts.map +1 -0
- package/dist/esm/cachePolicy.js +30 -0
- package/dist/esm/cachePolicy.js.map +1 -0
- package/dist/esm/determineApolloConfig.d.ts +4 -0
- package/dist/esm/determineApolloConfig.d.ts.map +1 -0
- package/dist/esm/determineApolloConfig.js +55 -0
- package/dist/esm/determineApolloConfig.js.map +1 -0
- package/dist/esm/errorNormalize.d.ts +12 -0
- package/dist/esm/errorNormalize.d.ts.map +1 -0
- package/dist/esm/errorNormalize.js +66 -0
- package/dist/esm/errorNormalize.js.map +1 -0
- package/dist/esm/errors/index.d.ts +16 -0
- package/dist/esm/errors/index.d.ts.map +1 -0
- package/dist/esm/errors/index.js +24 -0
- package/dist/esm/errors/index.js.map +1 -0
- package/dist/esm/externalTypes/constructor.d.ts +78 -0
- package/dist/esm/externalTypes/constructor.d.ts.map +1 -0
- package/dist/esm/externalTypes/constructor.js +2 -0
- package/dist/esm/externalTypes/constructor.js.map +1 -0
- package/dist/esm/externalTypes/context.d.ts +4 -0
- package/dist/esm/externalTypes/context.d.ts.map +1 -0
- package/dist/esm/externalTypes/context.js +2 -0
- package/dist/esm/externalTypes/context.js.map +1 -0
- package/dist/esm/externalTypes/graphql.d.ts +41 -0
- package/dist/esm/externalTypes/graphql.d.ts.map +1 -0
- package/dist/esm/externalTypes/graphql.js +2 -0
- package/dist/esm/externalTypes/graphql.js.map +1 -0
- package/dist/esm/externalTypes/http.d.ts +22 -0
- package/dist/esm/externalTypes/http.d.ts.map +1 -0
- package/dist/esm/externalTypes/http.js +2 -0
- package/dist/esm/externalTypes/http.js.map +1 -0
- package/dist/esm/externalTypes/incrementalDeliveryPolyfillAlpha2.d.ts +28 -0
- package/dist/esm/externalTypes/incrementalDeliveryPolyfillAlpha2.d.ts.map +1 -0
- package/dist/esm/externalTypes/incrementalDeliveryPolyfillAlpha2.js +2 -0
- package/dist/esm/externalTypes/incrementalDeliveryPolyfillAlpha2.js.map +1 -0
- package/dist/esm/externalTypes/incrementalDeliveryPolyfillAlpha9.d.ts +43 -0
- package/dist/esm/externalTypes/incrementalDeliveryPolyfillAlpha9.d.ts.map +1 -0
- package/dist/esm/externalTypes/incrementalDeliveryPolyfillAlpha9.js +2 -0
- package/dist/esm/externalTypes/incrementalDeliveryPolyfillAlpha9.js.map +1 -0
- package/dist/esm/externalTypes/index.d.ts +9 -0
- package/dist/esm/externalTypes/index.d.ts.map +1 -0
- package/dist/esm/externalTypes/index.js +2 -0
- package/dist/esm/externalTypes/index.js.map +1 -0
- package/dist/esm/externalTypes/plugins.d.ts +75 -0
- package/dist/esm/externalTypes/plugins.d.ts.map +1 -0
- package/dist/esm/externalTypes/plugins.js +2 -0
- package/dist/esm/externalTypes/plugins.js.map +1 -0
- package/dist/esm/externalTypes/requestPipeline.d.ts +50 -0
- package/dist/esm/externalTypes/requestPipeline.d.ts.map +1 -0
- package/dist/esm/externalTypes/requestPipeline.js +2 -0
- package/dist/esm/externalTypes/requestPipeline.js.map +1 -0
- package/dist/esm/generated/packageVersion.d.ts +2 -0
- package/dist/esm/generated/packageVersion.d.ts.map +1 -0
- package/dist/esm/generated/packageVersion.js +2 -0
- package/dist/esm/generated/packageVersion.js.map +1 -0
- package/dist/esm/httpBatching.d.ts +4 -0
- package/dist/esm/httpBatching.d.ts.map +1 -0
- package/dist/esm/httpBatching.js +55 -0
- package/dist/esm/httpBatching.js.map +1 -0
- package/dist/esm/incrementalDeliveryPolyfill.d.ts +82 -0
- package/dist/esm/incrementalDeliveryPolyfill.d.ts.map +1 -0
- package/dist/esm/incrementalDeliveryPolyfill.js +38 -0
- package/dist/esm/incrementalDeliveryPolyfill.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internalErrorClasses.d.ts +28 -0
- package/dist/esm/internalErrorClasses.d.ts.map +1 -0
- package/dist/esm/internalErrorClasses.js +81 -0
- package/dist/esm/internalErrorClasses.js.map +1 -0
- package/dist/esm/internalPlugin.d.ts +9 -0
- package/dist/esm/internalPlugin.d.ts.map +1 -0
- package/dist/esm/internalPlugin.js +7 -0
- package/dist/esm/internalPlugin.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/plugin/cacheControl/index.d.ts +9 -0
- package/dist/esm/plugin/cacheControl/index.d.ts.map +1 -0
- package/dist/esm/plugin/cacheControl/index.js +220 -0
- package/dist/esm/plugin/cacheControl/index.js.map +1 -0
- package/dist/esm/plugin/disableSuggestions/index.d.ts +3 -0
- package/dist/esm/plugin/disableSuggestions/index.d.ts.map +1 -0
- package/dist/esm/plugin/disableSuggestions/index.js +19 -0
- package/dist/esm/plugin/disableSuggestions/index.js.map +1 -0
- package/dist/esm/plugin/disabled/index.d.ts +7 -0
- package/dist/esm/plugin/disabled/index.d.ts.map +1 -0
- package/dist/esm/plugin/disabled/index.js +23 -0
- package/dist/esm/plugin/disabled/index.js.map +1 -0
- package/dist/esm/plugin/drainHttpServer/index.d.ts +8 -0
- package/dist/esm/plugin/drainHttpServer/index.d.ts.map +1 -0
- package/dist/esm/plugin/drainHttpServer/index.js +16 -0
- package/dist/esm/plugin/drainHttpServer/index.js.map +1 -0
- package/dist/esm/plugin/drainHttpServer/stoppable.d.ts +10 -0
- package/dist/esm/plugin/drainHttpServer/stoppable.d.ts.map +1 -0
- package/dist/esm/plugin/drainHttpServer/stoppable.js +47 -0
- package/dist/esm/plugin/drainHttpServer/stoppable.js.map +1 -0
- package/dist/esm/plugin/inlineTrace/index.d.ts +8 -0
- package/dist/esm/plugin/inlineTrace/index.d.ts.map +1 -0
- package/dist/esm/plugin/inlineTrace/index.js +67 -0
- package/dist/esm/plugin/inlineTrace/index.js.map +1 -0
- package/dist/esm/plugin/landingPage/default/getEmbeddedHTML.d.ts +4 -0
- package/dist/esm/plugin/landingPage/default/getEmbeddedHTML.d.ts.map +1 -0
- package/dist/esm/plugin/landingPage/default/getEmbeddedHTML.js +138 -0
- package/dist/esm/plugin/landingPage/default/getEmbeddedHTML.js.map +1 -0
- package/dist/esm/plugin/landingPage/default/index.d.ts +9 -0
- package/dist/esm/plugin/landingPage/default/index.d.ts.map +1 -0
- package/dist/esm/plugin/landingPage/default/index.js +141 -0
- package/dist/esm/plugin/landingPage/default/index.js.map +1 -0
- package/dist/esm/plugin/landingPage/default/types.d.ts +56 -0
- package/dist/esm/plugin/landingPage/default/types.d.ts.map +1 -0
- package/dist/esm/plugin/landingPage/default/types.js +2 -0
- package/dist/esm/plugin/landingPage/default/types.js.map +1 -0
- package/dist/esm/plugin/schemaIsSubgraph.d.ts +3 -0
- package/dist/esm/plugin/schemaIsSubgraph.d.ts.map +1 -0
- package/dist/esm/plugin/schemaIsSubgraph.js +20 -0
- package/dist/esm/plugin/schemaIsSubgraph.js.map +1 -0
- package/dist/esm/plugin/schemaReporting/index.d.ts +10 -0
- package/dist/esm/plugin/schemaReporting/index.d.ts.map +1 -0
- package/dist/esm/plugin/schemaReporting/index.js +98 -0
- package/dist/esm/plugin/schemaReporting/index.js.map +1 -0
- package/dist/esm/plugin/schemaReporting/schemaReporter.d.ts +33 -0
- package/dist/esm/plugin/schemaReporting/schemaReporter.d.ts.map +1 -0
- package/dist/esm/plugin/schemaReporting/schemaReporter.js +143 -0
- package/dist/esm/plugin/schemaReporting/schemaReporter.js.map +1 -0
- package/dist/esm/plugin/subscriptionCallback/index.d.ts +12 -0
- package/dist/esm/plugin/subscriptionCallback/index.d.ts.map +1 -0
- package/dist/esm/plugin/subscriptionCallback/index.js +428 -0
- package/dist/esm/plugin/subscriptionCallback/index.js.map +1 -0
- package/dist/esm/plugin/traceTreeBuilder.d.ts +25 -0
- package/dist/esm/plugin/traceTreeBuilder.d.ts.map +1 -0
- package/dist/esm/plugin/traceTreeBuilder.js +196 -0
- package/dist/esm/plugin/traceTreeBuilder.js.map +1 -0
- package/dist/esm/plugin/usageReporting/defaultSendOperationsAsTrace.d.ts +3 -0
- package/dist/esm/plugin/usageReporting/defaultSendOperationsAsTrace.d.ts.map +1 -0
- package/dist/esm/plugin/usageReporting/defaultSendOperationsAsTrace.js +41 -0
- package/dist/esm/plugin/usageReporting/defaultSendOperationsAsTrace.js.map +1 -0
- package/dist/esm/plugin/usageReporting/durationHistogram.d.ts +16 -0
- package/dist/esm/plugin/usageReporting/durationHistogram.d.ts.map +1 -0
- package/dist/esm/plugin/usageReporting/durationHistogram.js +64 -0
- package/dist/esm/plugin/usageReporting/durationHistogram.js.map +1 -0
- package/dist/esm/plugin/usageReporting/index.d.ts +3 -0
- package/dist/esm/plugin/usageReporting/index.d.ts.map +1 -0
- package/dist/esm/plugin/usageReporting/index.js +2 -0
- package/dist/esm/plugin/usageReporting/index.js.map +1 -0
- package/dist/esm/plugin/usageReporting/iterateOverTrace.d.ts +7 -0
- package/dist/esm/plugin/usageReporting/iterateOverTrace.d.ts.map +1 -0
- package/dist/esm/plugin/usageReporting/iterateOverTrace.js +78 -0
- package/dist/esm/plugin/usageReporting/iterateOverTrace.js.map +1 -0
- package/dist/esm/plugin/usageReporting/operationDerivedDataCache.d.ts +12 -0
- package/dist/esm/plugin/usageReporting/operationDerivedDataCache.d.ts.map +1 -0
- package/dist/esm/plugin/usageReporting/operationDerivedDataCache.js +29 -0
- package/dist/esm/plugin/usageReporting/operationDerivedDataCache.js.map +1 -0
- package/dist/esm/plugin/usageReporting/options.d.ts +60 -0
- package/dist/esm/plugin/usageReporting/options.d.ts.map +1 -0
- package/dist/esm/plugin/usageReporting/options.js +2 -0
- package/dist/esm/plugin/usageReporting/options.js.map +1 -0
- package/dist/esm/plugin/usageReporting/plugin.d.ts +7 -0
- package/dist/esm/plugin/usageReporting/plugin.d.ts.map +1 -0
- package/dist/esm/plugin/usageReporting/plugin.js +487 -0
- package/dist/esm/plugin/usageReporting/plugin.js.map +1 -0
- package/dist/esm/plugin/usageReporting/stats.d.ts +96 -0
- package/dist/esm/plugin/usageReporting/stats.d.ts.map +1 -0
- package/dist/esm/plugin/usageReporting/stats.js +283 -0
- package/dist/esm/plugin/usageReporting/stats.js.map +1 -0
- package/dist/esm/plugin/usageReporting/traceDetails.d.ts +4 -0
- package/dist/esm/plugin/usageReporting/traceDetails.d.ts.map +1 -0
- package/dist/esm/plugin/usageReporting/traceDetails.js +60 -0
- package/dist/esm/plugin/usageReporting/traceDetails.js.map +1 -0
- package/dist/esm/preventCsrf.d.ts +4 -0
- package/dist/esm/preventCsrf.d.ts.map +1 -0
- package/dist/esm/preventCsrf.js +34 -0
- package/dist/esm/preventCsrf.js.map +1 -0
- package/dist/esm/requestPipeline.d.ts +9 -0
- package/dist/esm/requestPipeline.d.ts.map +1 -0
- package/dist/esm/requestPipeline.js +364 -0
- package/dist/esm/requestPipeline.js.map +1 -0
- package/dist/esm/runHttpQuery.d.ts +15 -0
- package/dist/esm/runHttpQuery.d.ts.map +1 -0
- package/dist/esm/runHttpQuery.js +221 -0
- package/dist/esm/runHttpQuery.js.map +1 -0
- package/dist/esm/standalone/index.d.ts +25 -0
- package/dist/esm/standalone/index.d.ts.map +1 -0
- package/dist/esm/standalone/index.js +91 -0
- package/dist/esm/standalone/index.js.map +1 -0
- package/dist/esm/utils/HeaderMap.d.ts +8 -0
- package/dist/esm/utils/HeaderMap.d.ts.map +1 -0
- package/dist/esm/utils/HeaderMap.js +16 -0
- package/dist/esm/utils/HeaderMap.js.map +1 -0
- package/dist/esm/utils/UnreachableCaseError.d.ts +4 -0
- package/dist/esm/utils/UnreachableCaseError.d.ts.map +1 -0
- package/dist/esm/utils/UnreachableCaseError.js +6 -0
- package/dist/esm/utils/UnreachableCaseError.js.map +1 -0
- package/dist/esm/utils/computeCoreSchemaHash.d.ts +2 -0
- package/dist/esm/utils/computeCoreSchemaHash.d.ts.map +1 -0
- package/dist/esm/utils/computeCoreSchemaHash.js +5 -0
- package/dist/esm/utils/computeCoreSchemaHash.js.map +1 -0
- package/dist/esm/utils/invokeHooks.d.ts +7 -0
- package/dist/esm/utils/invokeHooks.d.ts.map +1 -0
- package/dist/esm/utils/invokeHooks.js +31 -0
- package/dist/esm/utils/invokeHooks.js.map +1 -0
- package/dist/esm/utils/isDefined.d.ts +2 -0
- package/dist/esm/utils/isDefined.d.ts.map +1 -0
- package/dist/esm/utils/isDefined.js +4 -0
- package/dist/esm/utils/isDefined.js.map +1 -0
- package/dist/esm/utils/makeGatewayGraphQLRequestContext.d.ts +5 -0
- package/dist/esm/utils/makeGatewayGraphQLRequestContext.d.ts.map +1 -0
- package/dist/esm/utils/makeGatewayGraphQLRequestContext.js +93 -0
- package/dist/esm/utils/makeGatewayGraphQLRequestContext.js.map +1 -0
- package/dist/esm/utils/resolvable.d.ts +7 -0
- package/dist/esm/utils/resolvable.d.ts.map +1 -0
- package/dist/esm/utils/resolvable.js +12 -0
- package/dist/esm/utils/resolvable.js.map +1 -0
- package/dist/esm/utils/schemaInstrumentation.d.ts +16 -0
- package/dist/esm/utils/schemaInstrumentation.d.ts.map +1 -0
- package/dist/esm/utils/schemaInstrumentation.js +69 -0
- package/dist/esm/utils/schemaInstrumentation.js.map +1 -0
- package/dist/esm/utils/schemaManager.d.ts +31 -0
- package/dist/esm/utils/schemaManager.d.ts.map +1 -0
- package/dist/esm/utils/schemaManager.js +99 -0
- package/dist/esm/utils/schemaManager.js.map +1 -0
- package/dist/esm/utils/urlForHttpServer.d.ts +3 -0
- package/dist/esm/utils/urlForHttpServer.d.ts.map +1 -0
- package/dist/esm/utils/urlForHttpServer.js +12 -0
- package/dist/esm/utils/urlForHttpServer.js.map +1 -0
- package/dist/esm/validationRules/NoIntrospection.d.ts +3 -0
- package/dist/esm/validationRules/NoIntrospection.d.ts.map +1 -0
- package/dist/esm/validationRules/NoIntrospection.js +15 -0
- package/dist/esm/validationRules/NoIntrospection.js.map +1 -0
- package/dist/esm/validationRules/RecursiveSelectionsLimit.d.ts +4 -0
- package/dist/esm/validationRules/RecursiveSelectionsLimit.d.ts.map +1 -0
- package/dist/esm/validationRules/RecursiveSelectionsLimit.js +146 -0
- package/dist/esm/validationRules/RecursiveSelectionsLimit.js.map +1 -0
- package/dist/esm/validationRules/index.d.ts +3 -0
- package/dist/esm/validationRules/index.d.ts.map +1 -0
- package/dist/esm/validationRules/index.js +3 -0
- package/dist/esm/validationRules/index.js.map +1 -0
- package/errors/package.json +8 -0
- package/package.json +208 -0
- package/plugin/cacheControl/package.json +8 -0
- package/plugin/disableSuggestions/package.json +8 -0
- package/plugin/disabled/package.json +8 -0
- package/plugin/drainHttpServer/package.json +8 -0
- package/plugin/inlineTrace/package.json +8 -0
- package/plugin/landingPage/default/package.json +8 -0
- package/plugin/schemaReporting/package.json +8 -0
- package/plugin/subscriptionCallback/package.json +8 -0
- package/plugin/usageReporting/package.json +8 -0
- package/src/ApolloServer.ts +1456 -0
- package/src/cachePolicy.ts +33 -0
- package/src/determineApolloConfig.ts +95 -0
- package/src/errorNormalize.ts +114 -0
- package/src/errors/index.ts +33 -0
- package/src/externalTypes/constructor.ts +174 -0
- package/src/externalTypes/context.ts +18 -0
- package/src/externalTypes/graphql.ts +81 -0
- package/src/externalTypes/http.ts +44 -0
- package/src/externalTypes/incrementalDeliveryPolyfillAlpha2.ts +63 -0
- package/src/externalTypes/incrementalDeliveryPolyfillAlpha9.ts +82 -0
- package/src/externalTypes/index.ts +73 -0
- package/src/externalTypes/plugins.ts +222 -0
- package/src/externalTypes/requestPipeline.ts +123 -0
- package/src/generated/packageVersion.ts +1 -0
- package/src/httpBatching.ts +105 -0
- package/src/incrementalDeliveryPolyfill.ts +253 -0
- package/src/index.ts +4 -0
- package/src/internalErrorClasses.ts +123 -0
- package/src/internalPlugin.ts +42 -0
- package/src/plugin/cacheControl/index.ts +453 -0
- package/src/plugin/disableSuggestions/index.ts +23 -0
- package/src/plugin/disabled/index.ts +41 -0
- package/src/plugin/drainHttpServer/index.ts +42 -0
- package/src/plugin/drainHttpServer/stoppable.ts +109 -0
- package/src/plugin/inlineTrace/index.ts +156 -0
- package/src/plugin/landingPage/default/getEmbeddedHTML.ts +204 -0
- package/src/plugin/landingPage/default/index.ts +219 -0
- package/src/plugin/landingPage/default/types.ts +198 -0
- package/src/plugin/schemaIsSubgraph.ts +41 -0
- package/src/plugin/schemaReporting/generated/operations.d.ts +18359 -0
- package/src/plugin/schemaReporting/index.ts +198 -0
- package/src/plugin/schemaReporting/schemaReporter.ts +207 -0
- package/src/plugin/subscriptionCallback/index.ts +724 -0
- package/src/plugin/traceTreeBuilder.ts +356 -0
- package/src/plugin/usageReporting/defaultSendOperationsAsTrace.ts +74 -0
- package/src/plugin/usageReporting/durationHistogram.ts +87 -0
- package/src/plugin/usageReporting/index.ts +9 -0
- package/src/plugin/usageReporting/iterateOverTrace.ts +140 -0
- package/src/plugin/usageReporting/operationDerivedDataCache.ts +61 -0
- package/src/plugin/usageReporting/options.ts +414 -0
- package/src/plugin/usageReporting/plugin.ts +871 -0
- package/src/plugin/usageReporting/stats.ts +492 -0
- package/src/plugin/usageReporting/traceDetails.ts +96 -0
- package/src/preventCsrf.ts +99 -0
- package/src/requestPipeline.ts +821 -0
- package/src/runHttpQuery.ts +408 -0
- package/src/standalone/index.ts +155 -0
- package/src/utils/HeaderMap.ts +22 -0
- package/src/utils/UnreachableCaseError.ts +10 -0
- package/src/utils/computeCoreSchemaHash.ts +9 -0
- package/src/utils/invokeHooks.ts +53 -0
- package/src/utils/isDefined.ts +3 -0
- package/src/utils/makeGatewayGraphQLRequestContext.ts +197 -0
- package/src/utils/resolvable.ts +30 -0
- package/src/utils/schemaInstrumentation.ts +132 -0
- package/src/utils/schemaManager.ts +212 -0
- package/src/utils/urlForHttpServer.ts +21 -0
- package/src/validationRules/NoIntrospection.ts +27 -0
- package/src/validationRules/RecursiveSelectionsLimit.ts +198 -0
- package/src/validationRules/index.ts +5 -0
- package/standalone/package.json +8 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BaseContext,
|
|
3
|
+
GraphQLExperimentalFormattedInitialIncrementalExecutionResultAlpha2,
|
|
4
|
+
GraphQLExperimentalFormattedInitialIncrementalExecutionResultAlpha9,
|
|
5
|
+
GraphQLExperimentalFormattedSubsequentIncrementalExecutionResultAlpha2,
|
|
6
|
+
GraphQLExperimentalFormattedSubsequentIncrementalExecutionResultAlpha9,
|
|
7
|
+
GraphQLRequest,
|
|
8
|
+
HTTPGraphQLHead,
|
|
9
|
+
HTTPGraphQLRequest,
|
|
10
|
+
HTTPGraphQLResponse,
|
|
11
|
+
} from './externalTypes/index.js';
|
|
12
|
+
import {
|
|
13
|
+
type ApolloServer,
|
|
14
|
+
type ApolloServerInternals,
|
|
15
|
+
chooseContentTypeForSingleResultResponse,
|
|
16
|
+
internalExecuteOperation,
|
|
17
|
+
MEDIA_TYPES,
|
|
18
|
+
type SchemaDerivedData,
|
|
19
|
+
} from './ApolloServer.js';
|
|
20
|
+
import { type FormattedExecutionResult, Kind } from 'graphql';
|
|
21
|
+
import { BadRequestError } from './internalErrorClasses.js';
|
|
22
|
+
import Negotiator from 'negotiator';
|
|
23
|
+
import { HeaderMap } from './utils/HeaderMap.js';
|
|
24
|
+
import MIMEType from 'whatwg-mimetype';
|
|
25
|
+
|
|
26
|
+
function fieldIfString(
|
|
27
|
+
o: Record<string, unknown>,
|
|
28
|
+
fieldName: string,
|
|
29
|
+
): string | undefined {
|
|
30
|
+
const value = o[fieldName];
|
|
31
|
+
if (typeof value === 'string') {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function searchParamIfSpecifiedOnce(
|
|
38
|
+
searchParams: URLSearchParams,
|
|
39
|
+
paramName: string,
|
|
40
|
+
) {
|
|
41
|
+
const values = searchParams.getAll(paramName);
|
|
42
|
+
switch (values.length) {
|
|
43
|
+
case 0:
|
|
44
|
+
return undefined;
|
|
45
|
+
case 1:
|
|
46
|
+
return values[0];
|
|
47
|
+
default:
|
|
48
|
+
throw new BadRequestError(
|
|
49
|
+
`The '${paramName}' search parameter may only be specified once.`,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function jsonParsedSearchParamIfSpecifiedOnce(
|
|
55
|
+
searchParams: URLSearchParams,
|
|
56
|
+
fieldName: string,
|
|
57
|
+
): Record<string, unknown> | undefined {
|
|
58
|
+
const value = searchParamIfSpecifiedOnce(searchParams, fieldName);
|
|
59
|
+
if (value === undefined) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
let hopefullyRecord;
|
|
63
|
+
try {
|
|
64
|
+
hopefullyRecord = JSON.parse(value);
|
|
65
|
+
} catch {
|
|
66
|
+
throw new BadRequestError(
|
|
67
|
+
`The ${fieldName} search parameter contains invalid JSON.`,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
if (!isStringRecord(hopefullyRecord)) {
|
|
71
|
+
throw new BadRequestError(
|
|
72
|
+
`The ${fieldName} search parameter should contain a JSON-encoded object.`,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
return hopefullyRecord;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function fieldIfRecord(
|
|
79
|
+
o: Record<string, unknown>,
|
|
80
|
+
fieldName: string,
|
|
81
|
+
): Record<string, unknown> | undefined {
|
|
82
|
+
const value = o[fieldName];
|
|
83
|
+
if (isStringRecord(value)) {
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function isStringRecord(o: unknown): o is Record<string, unknown> {
|
|
90
|
+
return (
|
|
91
|
+
!!o && typeof o === 'object' && !Buffer.isBuffer(o) && !Array.isArray(o)
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function isNonEmptyStringRecord(o: unknown): o is Record<string, unknown> {
|
|
96
|
+
return isStringRecord(o) && Object.keys(o).length > 0;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function ensureQueryIsStringOrMissing(query: unknown) {
|
|
100
|
+
if (!query || typeof query === 'string') {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
// Check for a common error first.
|
|
104
|
+
if ((query as any).kind === Kind.DOCUMENT) {
|
|
105
|
+
throw new BadRequestError(
|
|
106
|
+
"GraphQL queries must be strings. It looks like you're sending the " +
|
|
107
|
+
'internal graphql-js representation of a parsed query in your ' +
|
|
108
|
+
'request instead of a request in the GraphQL query language. You ' +
|
|
109
|
+
'can convert an AST to a string using the `print` function from ' +
|
|
110
|
+
'`graphql`, or use a client like `apollo-client` which converts ' +
|
|
111
|
+
'the internal representation to a string for you.',
|
|
112
|
+
);
|
|
113
|
+
} else {
|
|
114
|
+
throw new BadRequestError('GraphQL queries must be strings.');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export async function runHttpQuery<TContext extends BaseContext>({
|
|
119
|
+
server,
|
|
120
|
+
httpRequest,
|
|
121
|
+
contextValue,
|
|
122
|
+
schemaDerivedData,
|
|
123
|
+
internals,
|
|
124
|
+
sharedResponseHTTPGraphQLHead,
|
|
125
|
+
}: {
|
|
126
|
+
server: ApolloServer<TContext>;
|
|
127
|
+
httpRequest: HTTPGraphQLRequest;
|
|
128
|
+
contextValue: TContext;
|
|
129
|
+
schemaDerivedData: SchemaDerivedData;
|
|
130
|
+
internals: ApolloServerInternals<TContext>;
|
|
131
|
+
sharedResponseHTTPGraphQLHead: HTTPGraphQLHead | null;
|
|
132
|
+
}): Promise<HTTPGraphQLResponse> {
|
|
133
|
+
let graphQLRequest: GraphQLRequest;
|
|
134
|
+
|
|
135
|
+
switch (httpRequest.method) {
|
|
136
|
+
case 'POST': {
|
|
137
|
+
if (!isNonEmptyStringRecord(httpRequest.body)) {
|
|
138
|
+
throw new BadRequestError(
|
|
139
|
+
'POST body missing, invalid Content-Type, or JSON object has no keys.',
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
ensureQueryIsStringOrMissing(httpRequest.body.query);
|
|
144
|
+
|
|
145
|
+
if (typeof httpRequest.body.variables === 'string') {
|
|
146
|
+
throw new BadRequestError(
|
|
147
|
+
'`variables` in a POST body should be provided as an object, not a recursively JSON-encoded string.',
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (typeof httpRequest.body.extensions === 'string') {
|
|
152
|
+
throw new BadRequestError(
|
|
153
|
+
'`extensions` in a POST body should be provided as an object, not a recursively JSON-encoded string.',
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (
|
|
158
|
+
'extensions' in httpRequest.body &&
|
|
159
|
+
httpRequest.body.extensions !== null &&
|
|
160
|
+
!isStringRecord(httpRequest.body.extensions)
|
|
161
|
+
) {
|
|
162
|
+
throw new BadRequestError(
|
|
163
|
+
'`extensions` in a POST body must be an object if provided.',
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (
|
|
168
|
+
'variables' in httpRequest.body &&
|
|
169
|
+
httpRequest.body.variables !== null &&
|
|
170
|
+
!isStringRecord(httpRequest.body.variables)
|
|
171
|
+
) {
|
|
172
|
+
throw new BadRequestError(
|
|
173
|
+
'`variables` in a POST body must be an object if provided.',
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (
|
|
178
|
+
'operationName' in httpRequest.body &&
|
|
179
|
+
httpRequest.body.operationName !== null &&
|
|
180
|
+
typeof httpRequest.body.operationName !== 'string'
|
|
181
|
+
) {
|
|
182
|
+
throw new BadRequestError(
|
|
183
|
+
'`operationName` in a POST body must be a string if provided.',
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
graphQLRequest = {
|
|
188
|
+
query: fieldIfString(httpRequest.body, 'query'),
|
|
189
|
+
operationName: fieldIfString(httpRequest.body, 'operationName'),
|
|
190
|
+
variables: fieldIfRecord(httpRequest.body, 'variables'),
|
|
191
|
+
extensions: fieldIfRecord(httpRequest.body, 'extensions'),
|
|
192
|
+
http: httpRequest,
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
case 'GET': {
|
|
199
|
+
const contentType = httpRequest.headers.get('content-type');
|
|
200
|
+
if (contentType !== undefined) {
|
|
201
|
+
const contentTypeParsed = MIMEType.parse(contentType);
|
|
202
|
+
if (
|
|
203
|
+
contentTypeParsed === null ||
|
|
204
|
+
contentTypeParsed.essence !== 'application/json'
|
|
205
|
+
) {
|
|
206
|
+
throw new BadRequestError(
|
|
207
|
+
'GET requests may not have a content-type header other than application/json.',
|
|
208
|
+
{ extensions: { http: newHTTPGraphQLHead(415) } },
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const searchParams = new URLSearchParams(httpRequest.search);
|
|
214
|
+
|
|
215
|
+
graphQLRequest = {
|
|
216
|
+
query: searchParamIfSpecifiedOnce(searchParams, 'query'),
|
|
217
|
+
operationName: searchParamIfSpecifiedOnce(
|
|
218
|
+
searchParams,
|
|
219
|
+
'operationName',
|
|
220
|
+
),
|
|
221
|
+
variables: jsonParsedSearchParamIfSpecifiedOnce(
|
|
222
|
+
searchParams,
|
|
223
|
+
'variables',
|
|
224
|
+
),
|
|
225
|
+
extensions: jsonParsedSearchParamIfSpecifiedOnce(
|
|
226
|
+
searchParams,
|
|
227
|
+
'extensions',
|
|
228
|
+
),
|
|
229
|
+
http: httpRequest,
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
default:
|
|
235
|
+
throw new BadRequestError(
|
|
236
|
+
'Apollo Server supports only GET/POST requests.',
|
|
237
|
+
{
|
|
238
|
+
extensions: {
|
|
239
|
+
http: {
|
|
240
|
+
status: 405,
|
|
241
|
+
headers: new HeaderMap([['allow', 'GET, POST']]),
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const graphQLResponse = await internalExecuteOperation(
|
|
249
|
+
{
|
|
250
|
+
server,
|
|
251
|
+
graphQLRequest,
|
|
252
|
+
internals,
|
|
253
|
+
schemaDerivedData,
|
|
254
|
+
sharedResponseHTTPGraphQLHead,
|
|
255
|
+
},
|
|
256
|
+
{ contextValue },
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
if (graphQLResponse.body.kind === 'single') {
|
|
260
|
+
if (!graphQLResponse.http.headers.get('content-type')) {
|
|
261
|
+
// If we haven't already set the content-type (via a plugin or something),
|
|
262
|
+
// decide which content-type to use based on the accept header.
|
|
263
|
+
const contentType = chooseContentTypeForSingleResultResponse(httpRequest);
|
|
264
|
+
if (contentType === null) {
|
|
265
|
+
throw new BadRequestError(
|
|
266
|
+
`An 'accept' header was provided for this request which does not accept ` +
|
|
267
|
+
`${MEDIA_TYPES.APPLICATION_JSON} or ${MEDIA_TYPES.APPLICATION_GRAPHQL_RESPONSE_JSON}`,
|
|
268
|
+
// Use 406 Not Accepted
|
|
269
|
+
{ extensions: { http: { status: 406 } } },
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
graphQLResponse.http.headers.set('content-type', contentType);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return {
|
|
276
|
+
...graphQLResponse.http,
|
|
277
|
+
body: {
|
|
278
|
+
kind: 'complete',
|
|
279
|
+
string: await internals.stringifyResult(
|
|
280
|
+
orderExecutionResultFields(graphQLResponse.body.singleResult),
|
|
281
|
+
),
|
|
282
|
+
},
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Note that incremental delivery is not yet part of the official GraphQL
|
|
287
|
+
// spec. We are implementing a proposed version of the spec, and require
|
|
288
|
+
// clients to explicitly state `deferSpec=20220824`. Once incremental delivery
|
|
289
|
+
// has been added to the GraphQL spec, we will support `accept` headers
|
|
290
|
+
// without `deferSpec` as well (perhaps with slightly different behavior if
|
|
291
|
+
// anything has changed).
|
|
292
|
+
const acceptHeader = httpRequest.headers.get('accept');
|
|
293
|
+
const negotiator = new Negotiator({ headers: { accept: acceptHeader } });
|
|
294
|
+
const preferredMediaType = negotiator.mediaType([
|
|
295
|
+
// mediaType() will return the first one that matches, so if the client
|
|
296
|
+
// doesn't include the deferSpec parameter it will match this one here,
|
|
297
|
+
// which isn't good enough.
|
|
298
|
+
MEDIA_TYPES.MULTIPART_MIXED_NO_DEFER_SPEC,
|
|
299
|
+
MEDIA_TYPES.MULTIPART_MIXED_EXPERIMENTAL_ALPHA_9,
|
|
300
|
+
MEDIA_TYPES.MULTIPART_MIXED_EXPERIMENTAL_ALPHA_2,
|
|
301
|
+
]);
|
|
302
|
+
|
|
303
|
+
if (
|
|
304
|
+
!acceptHeader ||
|
|
305
|
+
(preferredMediaType !== MEDIA_TYPES.MULTIPART_MIXED_EXPERIMENTAL_ALPHA_2 &&
|
|
306
|
+
preferredMediaType !== MEDIA_TYPES.MULTIPART_MIXED_EXPERIMENTAL_ALPHA_9)
|
|
307
|
+
) {
|
|
308
|
+
// The client ran an operation that would yield multiple parts, but didn't
|
|
309
|
+
// specify `accept: multipart/mixed`. We return an error.
|
|
310
|
+
throw new BadRequestError(
|
|
311
|
+
'Apollo server received an operation that uses incremental delivery ' +
|
|
312
|
+
'(@defer or @stream), but the client does not accept multipart/mixed ' +
|
|
313
|
+
'HTTP responses. To enable incremental delivery support, add the HTTP ' +
|
|
314
|
+
`header 'Accept: ${MEDIA_TYPES.MULTIPART_MIXED_EXPERIMENTAL_ALPHA_9}' ` +
|
|
315
|
+
'if your client supports the current incremental format or ' +
|
|
316
|
+
`'Accept: ${MEDIA_TYPES.MULTIPART_MIXED_EXPERIMENTAL_ALPHA_2}' if your ` +
|
|
317
|
+
'client supports the legacy incremental format',
|
|
318
|
+
// Use 406 Not Accepted
|
|
319
|
+
{ extensions: { http: { status: 406 } } },
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
graphQLResponse.http.headers.set(
|
|
324
|
+
'content-type',
|
|
325
|
+
`multipart/mixed; boundary="-"; ${preferredMediaType.replace('multipart/mixed; ', '')}`,
|
|
326
|
+
);
|
|
327
|
+
return {
|
|
328
|
+
...graphQLResponse.http,
|
|
329
|
+
body: {
|
|
330
|
+
kind: 'chunked',
|
|
331
|
+
asyncIterator: writeMultipartBody(
|
|
332
|
+
graphQLResponse.body.initialResult,
|
|
333
|
+
graphQLResponse.body.subsequentResults,
|
|
334
|
+
),
|
|
335
|
+
},
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
async function* writeMultipartBody(
|
|
340
|
+
initialResult:
|
|
341
|
+
| GraphQLExperimentalFormattedInitialIncrementalExecutionResultAlpha2
|
|
342
|
+
| GraphQLExperimentalFormattedInitialIncrementalExecutionResultAlpha9,
|
|
343
|
+
subsequentResults: AsyncIterable<
|
|
344
|
+
| GraphQLExperimentalFormattedSubsequentIncrementalExecutionResultAlpha2
|
|
345
|
+
| GraphQLExperimentalFormattedSubsequentIncrementalExecutionResultAlpha9
|
|
346
|
+
>,
|
|
347
|
+
): AsyncGenerator<string> {
|
|
348
|
+
// Note: we assume in this function that every result other than the last has
|
|
349
|
+
// hasNext=true and the last has hasNext=false. That is, we choose which kind
|
|
350
|
+
// of delimiter to place at the end of each block based on the contents of the
|
|
351
|
+
// message, not the structure of the async iterator. This makes sense because
|
|
352
|
+
// we want to write the delimiter as soon as each block is done (so the client
|
|
353
|
+
// can parse it immediately) but we may not know whether a general async
|
|
354
|
+
// iterator is finished until we do async work.
|
|
355
|
+
|
|
356
|
+
yield `\r\n---\r\ncontent-type: application/json; charset=utf-8\r\n\r\n${JSON.stringify(
|
|
357
|
+
initialResult,
|
|
358
|
+
)}\r\n---${initialResult.hasNext ? '' : '--'}\r\n`;
|
|
359
|
+
|
|
360
|
+
for await (const result of subsequentResults) {
|
|
361
|
+
yield `content-type: application/json; charset=utf-8\r\n\r\n${JSON.stringify(
|
|
362
|
+
result,
|
|
363
|
+
)}\r\n---${result.hasNext ? '' : '--'}\r\n`;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// See https://github.com/facebook/graphql/pull/384 for why
|
|
368
|
+
// errors comes first.
|
|
369
|
+
function orderExecutionResultFields(
|
|
370
|
+
result: FormattedExecutionResult,
|
|
371
|
+
): FormattedExecutionResult {
|
|
372
|
+
return {
|
|
373
|
+
errors: result.errors,
|
|
374
|
+
data: result.data,
|
|
375
|
+
extensions: result.extensions,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// The result of a curl does not appear well in the terminal, so we add an extra new line
|
|
380
|
+
export function prettyJSONStringify(value: FormattedExecutionResult) {
|
|
381
|
+
return JSON.stringify(value) + '\n';
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export function newHTTPGraphQLHead(status?: number): HTTPGraphQLHead {
|
|
385
|
+
return {
|
|
386
|
+
status,
|
|
387
|
+
headers: new HeaderMap(),
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// Updates `target` with status code and headers from `source`. For now let's
|
|
392
|
+
// consider it undefined what happens if both have a status code set or both set
|
|
393
|
+
// the same header.
|
|
394
|
+
export function mergeHTTPGraphQLHead(
|
|
395
|
+
target: HTTPGraphQLHead,
|
|
396
|
+
source: HTTPGraphQLHead,
|
|
397
|
+
) {
|
|
398
|
+
if (source.status) {
|
|
399
|
+
target.status = source.status;
|
|
400
|
+
}
|
|
401
|
+
if (source.headers) {
|
|
402
|
+
for (const [name, value] of source.headers) {
|
|
403
|
+
// If source.headers contains non-lowercase header names, this will
|
|
404
|
+
// catch that case as long as target.headers is a HeaderMap.
|
|
405
|
+
target.headers.set(name, value);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { WithRequired } from '@apollo/utils.withrequired';
|
|
2
|
+
import cors from 'cors';
|
|
3
|
+
import bodyParser from 'body-parser';
|
|
4
|
+
import { parse as parseContentType } from 'content-type';
|
|
5
|
+
import http, { type IncomingMessage, type ServerResponse } from 'http';
|
|
6
|
+
import type { ListenOptions } from 'net';
|
|
7
|
+
import { parse as urlParse } from 'url';
|
|
8
|
+
import type { ApolloServer } from '../ApolloServer.js';
|
|
9
|
+
import type {
|
|
10
|
+
BaseContext,
|
|
11
|
+
ContextFunction,
|
|
12
|
+
HTTPGraphQLRequest,
|
|
13
|
+
} from '../externalTypes/index.js';
|
|
14
|
+
import { ApolloServerPluginDrainHttpServer } from '../plugin/drainHttpServer/index.js';
|
|
15
|
+
import { urlForHttpServer } from '../utils/urlForHttpServer.js';
|
|
16
|
+
import { HeaderMap } from '../utils/HeaderMap.js';
|
|
17
|
+
import finalhandler from 'finalhandler';
|
|
18
|
+
|
|
19
|
+
export interface StandaloneServerContextFunctionArgument {
|
|
20
|
+
req: IncomingMessage;
|
|
21
|
+
res: ServerResponse;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface StartStandaloneServerOptions<TContext extends BaseContext> {
|
|
25
|
+
context?: ContextFunction<
|
|
26
|
+
[StandaloneServerContextFunctionArgument],
|
|
27
|
+
TContext
|
|
28
|
+
>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// according to RFC8259, only UTF-8 is allowed in JSON text
|
|
32
|
+
// (see https://datatracker.ietf.org/doc/html/rfc8259#section-8.1)
|
|
33
|
+
// RFC 7159 also specifies that JSON could be UTF-16 or UTF-32,
|
|
34
|
+
// so we allow for that, too
|
|
35
|
+
const validCharset = /^utf-(8|((16|32)(le|be)?))$/i;
|
|
36
|
+
|
|
37
|
+
export async function startStandaloneServer(
|
|
38
|
+
server: ApolloServer<BaseContext>,
|
|
39
|
+
options?: StartStandaloneServerOptions<BaseContext> & {
|
|
40
|
+
listen?: ListenOptions;
|
|
41
|
+
},
|
|
42
|
+
): Promise<{ url: string }>;
|
|
43
|
+
export async function startStandaloneServer<TContext extends BaseContext>(
|
|
44
|
+
server: ApolloServer<TContext>,
|
|
45
|
+
options: WithRequired<StartStandaloneServerOptions<TContext>, 'context'> & {
|
|
46
|
+
listen?: ListenOptions;
|
|
47
|
+
},
|
|
48
|
+
): Promise<{ url: string }>;
|
|
49
|
+
export async function startStandaloneServer<TContext extends BaseContext>(
|
|
50
|
+
server: ApolloServer<TContext>,
|
|
51
|
+
options?: StartStandaloneServerOptions<TContext> & { listen?: ListenOptions },
|
|
52
|
+
): Promise<{ url: string }> {
|
|
53
|
+
const context = options?.context ?? (async () => ({}) as TContext);
|
|
54
|
+
const corsHandler = cors();
|
|
55
|
+
const jsonHandler = bodyParser.json({
|
|
56
|
+
verify(req) {
|
|
57
|
+
const charset = parseContentType(req).parameters.charset || 'utf-8';
|
|
58
|
+
if (!charset.match(validCharset)) {
|
|
59
|
+
throw Object.assign(
|
|
60
|
+
new Error(`unsupported charset "${charset.toUpperCase()}"`),
|
|
61
|
+
{
|
|
62
|
+
status: 415,
|
|
63
|
+
name: 'UnsupportedMediaTypeError',
|
|
64
|
+
charset,
|
|
65
|
+
type: 'charset.unsupported',
|
|
66
|
+
},
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
limit: '50mb',
|
|
71
|
+
});
|
|
72
|
+
const httpServer = http.createServer((req, res) => {
|
|
73
|
+
const errorHandler = finalhandler(req, res, {
|
|
74
|
+
// Use the same onerror as Express.
|
|
75
|
+
onerror(err) {
|
|
76
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
77
|
+
console.error(err.stack || err.toString());
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
corsHandler(req, res, (err) => {
|
|
83
|
+
if (err) {
|
|
84
|
+
errorHandler(err);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
jsonHandler(req, res, (err) => {
|
|
88
|
+
if (err) {
|
|
89
|
+
errorHandler(err);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const headers = new HeaderMap();
|
|
94
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
95
|
+
if (value !== undefined) {
|
|
96
|
+
// Node headers can be an array or a single value. We join
|
|
97
|
+
// multi-valued headers with `, ` just like the Fetch API's `Headers`
|
|
98
|
+
// does. We assume that keys are already lower-cased (as per the Node
|
|
99
|
+
// docs on IncomingMessage.headers) and so we don't bother to lower-case
|
|
100
|
+
// them or combine across multiple keys that would lower-case to the
|
|
101
|
+
// same value.
|
|
102
|
+
headers.set(key, Array.isArray(value) ? value.join(', ') : value);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const httpGraphQLRequest: HTTPGraphQLRequest = {
|
|
107
|
+
// Note that method and url are guaranteed to exist for IncomingMessages coming from Servers.
|
|
108
|
+
method: req.method!.toUpperCase(),
|
|
109
|
+
headers,
|
|
110
|
+
search: urlParse(req.url!).search ?? '',
|
|
111
|
+
body: 'body' in req ? req.body : undefined,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
server
|
|
115
|
+
.executeHTTPGraphQLRequest({
|
|
116
|
+
httpGraphQLRequest,
|
|
117
|
+
context: () => context({ req, res }),
|
|
118
|
+
})
|
|
119
|
+
.then(async (httpGraphQLResponse) => {
|
|
120
|
+
for (const [key, value] of httpGraphQLResponse.headers) {
|
|
121
|
+
res.setHeader(key, value);
|
|
122
|
+
}
|
|
123
|
+
res.statusCode = httpGraphQLResponse.status || 200;
|
|
124
|
+
|
|
125
|
+
if (httpGraphQLResponse.body.kind === 'complete') {
|
|
126
|
+
res.end(httpGraphQLResponse.body.string);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
for await (const chunk of httpGraphQLResponse.body.asyncIterator) {
|
|
131
|
+
res.write(chunk);
|
|
132
|
+
}
|
|
133
|
+
res.end();
|
|
134
|
+
})
|
|
135
|
+
.catch((err) => {
|
|
136
|
+
errorHandler(err);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
server.addPlugin(
|
|
143
|
+
ApolloServerPluginDrainHttpServer({ httpServer: httpServer }),
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
await server.start();
|
|
147
|
+
|
|
148
|
+
const listenOptions = options?.listen ?? { port: 4000 };
|
|
149
|
+
// Wait for server to start listening
|
|
150
|
+
await new Promise<void>((resolve) => {
|
|
151
|
+
httpServer.listen(listenOptions, resolve);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
return { url: urlForHttpServer(httpServer) };
|
|
155
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class HeaderMap extends Map<string, string> {
|
|
2
|
+
// In order for TypeScript to prevent a standard `Map` from being compatible
|
|
3
|
+
// with a `HeaderMap`, we need some additional property on the class.
|
|
4
|
+
// @ts-ignore (this is just unused)
|
|
5
|
+
private __identity = Symbol('HeaderMap');
|
|
6
|
+
|
|
7
|
+
override set(key: string, value: string): this {
|
|
8
|
+
return super.set(key.toLowerCase(), value);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
override get(key: string) {
|
|
12
|
+
return super.get(key.toLowerCase());
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
override delete(key: string) {
|
|
16
|
+
return super.delete(key.toLowerCase());
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
override has(key: string) {
|
|
20
|
+
return super.has(key.toLowerCase());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throw this in places that should be unreachable (because all other cases have
|
|
3
|
+
* been handled, reducing the type of the argument to `never`). TypeScript will
|
|
4
|
+
* complain if in fact there is a valid type for the argument.
|
|
5
|
+
*/
|
|
6
|
+
export class UnreachableCaseError extends Error {
|
|
7
|
+
constructor(val: never) {
|
|
8
|
+
super(`Unreachable case: ${val}`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createHash } from '@apollo/utils.createhash';
|
|
2
|
+
|
|
3
|
+
// This hash function is used in both the schema reporting and usage reporting
|
|
4
|
+
// plugins. Making sure we use the same hash function hypothetically allows the
|
|
5
|
+
// two reporting features to work well together, though in practice nothing on
|
|
6
|
+
// the Studio side currently correlates this ID across both features.
|
|
7
|
+
export function computeCoreSchemaHash(schema: string): string {
|
|
8
|
+
return createHash('sha256').update(schema).digest('hex');
|
|
9
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { isDefined } from './isDefined.js';
|
|
2
|
+
|
|
3
|
+
type AsyncDidEndHook<TArgs extends any[]> = (...args: TArgs) => Promise<void>;
|
|
4
|
+
type SyncDidEndHook<TArgs extends any[]> = (...args: TArgs) => void;
|
|
5
|
+
|
|
6
|
+
export async function invokeDidStartHook<T, TEndHookArgs extends unknown[]>(
|
|
7
|
+
targets: T[],
|
|
8
|
+
hook: (t: T) => Promise<AsyncDidEndHook<TEndHookArgs> | undefined | void>,
|
|
9
|
+
): Promise<AsyncDidEndHook<TEndHookArgs>> {
|
|
10
|
+
const didEndHooks = (
|
|
11
|
+
await Promise.all(targets.map((target) => hook(target)))
|
|
12
|
+
).filter(isDefined);
|
|
13
|
+
|
|
14
|
+
didEndHooks.reverse();
|
|
15
|
+
|
|
16
|
+
return async (...args: TEndHookArgs) => {
|
|
17
|
+
for (const didEndHook of didEndHooks) {
|
|
18
|
+
didEndHook(...args);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Almost all hooks are async, but as a special case, willResolveField is sync
|
|
24
|
+
// due to performance concerns.
|
|
25
|
+
export function invokeSyncDidStartHook<T, TEndHookArgs extends unknown[]>(
|
|
26
|
+
targets: T[],
|
|
27
|
+
hook: (t: T) => SyncDidEndHook<TEndHookArgs> | undefined | void,
|
|
28
|
+
): SyncDidEndHook<TEndHookArgs> {
|
|
29
|
+
const didEndHooks: SyncDidEndHook<TEndHookArgs>[] = targets
|
|
30
|
+
.map((target) => hook(target))
|
|
31
|
+
.filter(isDefined);
|
|
32
|
+
|
|
33
|
+
didEndHooks.reverse();
|
|
34
|
+
|
|
35
|
+
return (...args: TEndHookArgs) => {
|
|
36
|
+
for (const didEndHook of didEndHooks) {
|
|
37
|
+
didEndHook(...args);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function invokeHooksUntilDefinedAndNonNull<T, TOut>(
|
|
43
|
+
targets: T[],
|
|
44
|
+
hook: (t: T) => Promise<TOut | null | undefined>,
|
|
45
|
+
): Promise<TOut | null> {
|
|
46
|
+
for (const target of targets) {
|
|
47
|
+
const value = await hook(target);
|
|
48
|
+
if (value != null) {
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|