@nestjs/apollo 14.0.0-next.0 → 14.0.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/dist/drivers/apollo-base.driver.d.ts +1 -0
- package/dist/drivers/apollo-base.driver.d.ts.map +1 -1
- package/dist/drivers/apollo-base.driver.js +58 -20
- package/dist/drivers/apollo-federation.driver.js +1 -1
- package/dist/drivers/apollo-gateway.driver.js +1 -1
- package/dist/interfaces/apollo-driver-config.interface.d.ts +14 -0
- package/dist/interfaces/apollo-driver-config.interface.d.ts.map +1 -1
- package/package.json +14 -14
|
@@ -15,6 +15,7 @@ export declare abstract class ApolloBaseDriver<T extends Record<string, any> = A
|
|
|
15
15
|
protected registerFastify(options: T, { preStartHook }?: {
|
|
16
16
|
preStartHook?: () => void;
|
|
17
17
|
}): Promise<void>;
|
|
18
|
+
private createRequestLifecycleHooksPlugin;
|
|
18
19
|
private createPreserveHttpStatusPlugin;
|
|
19
20
|
private wrapFormatErrorFn;
|
|
20
21
|
private createTransformHttpErrorFn;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apollo-base.driver.d.ts","sourceRoot":"","sources":["../../lib/drivers/apollo-base.driver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAUhE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAKxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAU5D,8BAAsB,gBAAgB,CACpC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,kBAAkB,CAClD,SAAQ,qBAAqB,CAAC,CAAC,CAAC;IAChC,SAAS,CAAC,YAAY,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC;IAElD,IAAI,QAAQ,IAAI,YAAY,CAAC,WAAW,CAAC,CAExC;IAEY,KAAK,CAAC,aAAa,EAA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C7B,OAAO,EAAE,CAAC,EACV,EAAE,YAAY,EAAE,GAAE;QAAE,YAAY,CAAC,EAAE,MAAM,IAAI,CAAA;KAAO;IAwCtD,OAAO,CAAC,iCAAiC;IAyCzC,OAAO,CAAC,8BAA8B;IA4BtC,OAAO,CAAC,iBAAiB;IAuBzB,OAAO,CAAC,0BAA0B;IA0ClC,OAAO,CAAC,mBAAmB;IA8B3B,OAAO,CAAC,iBAAiB;CAgB1B"}
|
|
@@ -42,22 +42,20 @@ export class ApolloBaseDriver extends AbstractGraphQLDriver {
|
|
|
42
42
|
fieldResolverEnhancers: [],
|
|
43
43
|
stopOnTerminationSignals: false,
|
|
44
44
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
// `graphiql` wins over the deprecated `playground` alias; when neither is
|
|
46
|
+
// set, GraphiQL is enabled outside of production.
|
|
47
|
+
const useGraphiQL = options.graphiql ??
|
|
48
|
+
options.playground ??
|
|
49
|
+
process.env.NODE_ENV !== 'production';
|
|
50
50
|
if (useGraphiQL) {
|
|
51
|
-
const graphiQlPlaygroundOpts = typeof
|
|
51
|
+
const graphiQlPlaygroundOpts = typeof useGraphiQL === 'object' ? { ...useGraphiQL } : {};
|
|
52
52
|
graphiQlPlaygroundOpts.url ??= options.path;
|
|
53
53
|
defaults = {
|
|
54
54
|
...defaults,
|
|
55
55
|
plugins: [new GraphiQLPlaygroundPlugin(graphiQlPlaygroundOpts)],
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
-
else
|
|
59
|
-
process.env.NODE_ENV === 'production') ||
|
|
60
|
-
options.playground === false) {
|
|
58
|
+
else {
|
|
61
59
|
defaults = {
|
|
62
60
|
...defaults,
|
|
63
61
|
plugins: [ApolloServerPluginLandingPageDisabled()],
|
|
@@ -68,12 +66,16 @@ export class ApolloBaseDriver extends AbstractGraphQLDriver {
|
|
|
68
66
|
this.normalizeSubscriptionsPath(options);
|
|
69
67
|
this.wrapContextResolver(options);
|
|
70
68
|
this.wrapFormatErrorFn(options);
|
|
71
|
-
if (options.
|
|
69
|
+
if (options.preserveHttpStatusForExecutionErrors !== false) {
|
|
72
70
|
options.plugins = [
|
|
73
71
|
...(options.plugins || []),
|
|
74
72
|
this.createPreserveHttpStatusPlugin(),
|
|
75
73
|
];
|
|
76
74
|
}
|
|
75
|
+
options.plugins = [
|
|
76
|
+
...(options.plugins || []),
|
|
77
|
+
this.createRequestLifecycleHooksPlugin(),
|
|
78
|
+
];
|
|
77
79
|
return options;
|
|
78
80
|
}
|
|
79
81
|
normalizeSubscriptionsPath(options) {
|
|
@@ -81,21 +83,23 @@ export class ApolloBaseDriver extends AbstractGraphQLDriver {
|
|
|
81
83
|
if (!subscriptions) {
|
|
82
84
|
return;
|
|
83
85
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
]
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
config
|
|
91
|
-
|
|
86
|
+
// Rewrite a copy: the caller's configuration object may be reused across
|
|
87
|
+
// applications, and prefixing it in place compounds on every merge.
|
|
88
|
+
const normalized = { ...subscriptions };
|
|
89
|
+
const config = normalized['graphql-ws'];
|
|
90
|
+
if (config && typeof config === 'object' && config.path) {
|
|
91
|
+
normalized['graphql-ws'] = {
|
|
92
|
+
...config,
|
|
93
|
+
path: this.applyGlobalPrefix(config.path, options),
|
|
94
|
+
};
|
|
92
95
|
}
|
|
96
|
+
options.subscriptions = normalized;
|
|
93
97
|
}
|
|
94
98
|
subscriptionWithFilter(instanceRef, filterFn, createSubscribeContext) {
|
|
95
99
|
return (...args) => createAsyncIterator(createSubscribeContext()(...args), (payload) => filterFn.call(instanceRef, payload, args[1], args[2]));
|
|
96
100
|
}
|
|
97
101
|
async registerExpress(options, { preStartHook } = {}) {
|
|
98
|
-
const { expressMiddleware } = await loadPackage('@as-integrations/express5', 'GraphQLModule', () =>
|
|
102
|
+
const { expressMiddleware } = await loadPackage('@as-integrations/express5', 'GraphQLModule', () => import('@as-integrations/express5'));
|
|
99
103
|
const { path, typeDefs, resolvers, schema } = options;
|
|
100
104
|
const httpAdapter = this.httpAdapterHost.httpAdapter;
|
|
101
105
|
// Workaround: the landing page requires body to be present
|
|
@@ -128,7 +132,7 @@ export class ApolloBaseDriver extends AbstractGraphQLDriver {
|
|
|
128
132
|
this.apolloServer = server;
|
|
129
133
|
}
|
|
130
134
|
async registerFastify(options, { preStartHook } = {}) {
|
|
131
|
-
const { fastifyApolloDrainPlugin, fastifyApolloHandler } = await loadPackage('@as-integrations/fastify', 'GraphQLModule', () =>
|
|
135
|
+
const { fastifyApolloDrainPlugin, fastifyApolloHandler } = await loadPackage('@as-integrations/fastify', 'GraphQLModule', () => import('@as-integrations/fastify'));
|
|
132
136
|
const httpAdapter = this.httpAdapterHost.httpAdapter;
|
|
133
137
|
const app = httpAdapter.getInstance();
|
|
134
138
|
const { path, typeDefs, resolvers, schema } = options;
|
|
@@ -153,6 +157,40 @@ export class ApolloBaseDriver extends AbstractGraphQLDriver {
|
|
|
153
157
|
});
|
|
154
158
|
this.apolloServer = server;
|
|
155
159
|
}
|
|
160
|
+
createRequestLifecycleHooksPlugin() {
|
|
161
|
+
// Exposes the "request start"/"request end" hooks registered through the
|
|
162
|
+
// `ResolverDecoratorHost` so that consumers can instrument (and measure)
|
|
163
|
+
// the entire lifecycle of a single GraphQL operation.
|
|
164
|
+
const resolverDecoratorHost = () => this.resolverDecoratorHost;
|
|
165
|
+
return {
|
|
166
|
+
async requestDidStart(requestContext) {
|
|
167
|
+
const host = resolverDecoratorHost();
|
|
168
|
+
if (!host?.hasRequestHooks()) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const hookContext = {
|
|
172
|
+
query: requestContext.request?.query,
|
|
173
|
+
operationName: requestContext.request?.operationName,
|
|
174
|
+
variables: requestContext.request?.variables,
|
|
175
|
+
context: requestContext.contextValue,
|
|
176
|
+
};
|
|
177
|
+
const state = host.onRequestStart(hookContext);
|
|
178
|
+
return {
|
|
179
|
+
async willSendResponse(endRequestContext) {
|
|
180
|
+
const body = endRequestContext.response?.body;
|
|
181
|
+
const errors = endRequestContext.errors ??
|
|
182
|
+
(body?.kind === 'single' ? body.singleResult?.errors : undefined);
|
|
183
|
+
host.onRequestEnd({
|
|
184
|
+
...hookContext,
|
|
185
|
+
operationName: endRequestContext.operationName ?? hookContext.operationName,
|
|
186
|
+
errors,
|
|
187
|
+
state,
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
}
|
|
156
194
|
createPreserveHttpStatusPlugin() {
|
|
157
195
|
// When a resolver throws an error whose `extensions.http.status` is set
|
|
158
196
|
// (either directly via GraphQLError or transitively via NestJS HTTP
|
|
@@ -17,7 +17,7 @@ let ApolloFederationDriver = class ApolloFederationDriver extends ApolloBaseDriv
|
|
|
17
17
|
async start(options) {
|
|
18
18
|
options.plugins = extend(options.plugins || [], this.pluginsExplorerService.explore(options));
|
|
19
19
|
if (options.definitions && options.definitions.path) {
|
|
20
|
-
const { printSubgraphSchema } = await loadPackage('@apollo/subgraph', 'ApolloFederation', () =>
|
|
20
|
+
const { printSubgraphSchema } = await loadPackage('@apollo/subgraph', 'ApolloFederation', () => import('@apollo/subgraph'));
|
|
21
21
|
await this.graphQlFactory.generateDefinitions(printSubgraphSchema(options.schema), options);
|
|
22
22
|
}
|
|
23
23
|
await super.start(options);
|
|
@@ -16,7 +16,7 @@ let ApolloGatewayDriver = class ApolloGatewayDriver extends ApolloBaseDriver {
|
|
|
16
16
|
async start(options) {
|
|
17
17
|
options.server ??= {};
|
|
18
18
|
options.server.plugins = extend(options.server.plugins || [], this.pluginsExplorerService.explore(options));
|
|
19
|
-
const { ApolloGateway } = await loadPackage('@apollo/gateway', 'ApolloGateway', () =>
|
|
19
|
+
const { ApolloGateway } = await loadPackage('@apollo/gateway', 'ApolloGateway', () => import('@apollo/gateway'));
|
|
20
20
|
const { server: serverOpts = {}, gateway: gatewayOpts = {}, transformSchema, } = options;
|
|
21
21
|
const gateway = new ApolloGateway(gatewayOpts);
|
|
22
22
|
await super.start({
|
|
@@ -38,6 +38,20 @@ export interface ApolloDriverConfig extends Omit<ApolloServerOptionsWithTypeDefs
|
|
|
38
38
|
* @default true
|
|
39
39
|
*/
|
|
40
40
|
autoTransformHttpErrors?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Controls whether the Apollo Server plugin that preserves HTTP status codes
|
|
43
|
+
* for execution errors is injected. When enabled, execution errors (errors that
|
|
44
|
+
* occur during resolver execution) will have their HTTP status reset to 200,
|
|
45
|
+
* ensuring the response maintains a stable {data, errors} shape. When disabled,
|
|
46
|
+
* HTTP status codes from extensions.http.status will be preserved in the response.
|
|
47
|
+
*
|
|
48
|
+
* This flag is independent of autoTransformHttpErrors and provides granular
|
|
49
|
+
* control over HTTP status handling for high-throughput APIs that need to
|
|
50
|
+
* distinguish between execution errors and request-level errors.
|
|
51
|
+
* @default true
|
|
52
|
+
* @see https://github.com/nestjs/graphql/issues/3997
|
|
53
|
+
*/
|
|
54
|
+
preserveHttpStatusForExecutionErrors?: boolean;
|
|
41
55
|
}
|
|
42
56
|
export type ApolloDriverConfigFactory = GqlOptionsFactory<ApolloDriverConfig>;
|
|
43
57
|
export type ApolloDriverAsyncConfig = GqlModuleAsyncOptions<ApolloDriverConfig>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apollo-driver-config.interface.d.ts","sourceRoot":"","sources":["../../lib/interfaces/apollo-driver-config.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,sDAAsD,CAAC;AAEvF;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,kBACf,SAAQ,IAAI,CACR,+BAA+B,CAAC,GAAG,CAAC,EACpC,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,CAChD,EACD,kBAAkB,EAClB,gBAAgB;IAClB;;OAEG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAC;IAEtC;;OAEG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;IAEnC;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,eAAe,CAAC;IAErC;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"apollo-driver-config.interface.d.ts","sourceRoot":"","sources":["../../lib/interfaces/apollo-driver-config.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,sDAAsD,CAAC;AAEvF;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,kBACf,SAAQ,IAAI,CACR,+BAA+B,CAAC,GAAG,CAAC,EACpC,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,CAChD,EACD,kBAAkB,EAClB,gBAAgB;IAClB;;OAEG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAC;IAEtC;;OAEG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;IAEnC;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,eAAe,CAAC;IAErC;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC;;;;;;;;;;;;OAYG;IACH,oCAAoC,CAAC,EAAE,OAAO,CAAC;CAChD;AAED,MAAM,MAAM,yBAAyB,GAAG,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;AAC9E,MAAM,MAAM,uBAAuB,GAAG,qBAAqB,CAAC,kBAAkB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/apollo",
|
|
3
|
-
"version": "14.0.0
|
|
3
|
+
"version": "14.0.0",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@apollo)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,17 +32,17 @@
|
|
|
32
32
|
"url": "https://github.com/nestjs/graphql/issues"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@apollo/gateway": "2.
|
|
36
|
-
"@apollo/server": "5.5.
|
|
35
|
+
"@apollo/gateway": "2.14.4",
|
|
36
|
+
"@apollo/server": "5.5.1",
|
|
37
37
|
"@apollo/server-plugin-response-cache": "5.0.0",
|
|
38
|
-
"@apollo/subgraph": "2.
|
|
38
|
+
"@apollo/subgraph": "2.14.4",
|
|
39
39
|
"@as-integrations/express5": "^1.1.2",
|
|
40
40
|
"@as-integrations/fastify": "3.1.0",
|
|
41
|
-
"@nestjs/common": "
|
|
42
|
-
"@nestjs/core": "
|
|
43
|
-
"@nestjs/platform-express": "
|
|
44
|
-
"@nestjs/platform-fastify": "
|
|
45
|
-
"@nestjs/testing": "
|
|
41
|
+
"@nestjs/common": "12.0.1",
|
|
42
|
+
"@nestjs/core": "12.0.1",
|
|
43
|
+
"@nestjs/platform-express": "12.0.1",
|
|
44
|
+
"@nestjs/platform-fastify": "12.0.1",
|
|
45
|
+
"@nestjs/testing": "12.0.1",
|
|
46
46
|
"apollo-cache-inmemory": "1.6.6",
|
|
47
47
|
"apollo-client": "2.6.10"
|
|
48
48
|
},
|
|
@@ -56,10 +56,10 @@
|
|
|
56
56
|
"@apollo/server": "^5.0.0",
|
|
57
57
|
"@apollo/subgraph": "^2.0.0",
|
|
58
58
|
"@as-integrations/fastify": "^2.1.1 || ^3.0.0",
|
|
59
|
-
"@nestjs/common": "
|
|
60
|
-
"@nestjs/core": "
|
|
61
|
-
"@nestjs/graphql": "^
|
|
62
|
-
"graphql": "^16.10.0"
|
|
59
|
+
"@nestjs/common": "^12.0.0",
|
|
60
|
+
"@nestjs/core": "^12.0.0",
|
|
61
|
+
"@nestjs/graphql": "^14.0.0",
|
|
62
|
+
"graphql": "^16.10.0 || ^17.0.0"
|
|
63
63
|
},
|
|
64
64
|
"peerDependenciesMeta": {
|
|
65
65
|
"@apollo/gateway": {
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"optional": true
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "92a4e4be1509e00a30edf70e8402764b16e7101c"
|
|
79
79
|
}
|