Skip to content

Commit 41eff56

Browse files
committed
feat(core,apollo): add middleware support
1 parent 4f5677f commit 41eff56

29 files changed

+1629
-826
lines changed

Writerside/deepkit-graphql.tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
<toc-element topic="utility-types.md"/>
1717
<toc-element topic="scalars.md"/>
1818
<toc-element topic="resolvers.md">
19-
<toc-element topic="context.md"/>
19+
<toc-element topic="Middleware.md"/>
20+
<toc-element topic="context.md"/>
2021
<toc-element topic="parent.md"/>
2122
</toc-element>
2223
<toc-element topic="query.md"/>

Writerside/topics/Middleware.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# InternalMiddleware
2+
3+
Start typing here...

Writerside/topics/query.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Query
1+
# Queries
22

3-
Start typing here...
3+
Start typing here...

Writerside/topics/types-inline.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ In TypeScript, an inline type refers to a type definition declared directly at t
44

55
The names of GraphQL object types corresponding to TypeScript inline types are generated by excluding any non-alphanumeric characters.
66
<tip>
7-
For comparison, see <a href="types-referenced.md">referenced types</a> if you want to use a custom name.
7+
For comparison, see <a href="types-referenced.md">referenced types</a>.
88
</tip>
99

1010
## Example
@@ -36,6 +36,9 @@ type Query {
3636
}
3737
```
3838
This ensures that the generated name is compatible with the GraphQL naming requirements.
39+
<tip>
40+
See <a href="types-referenced.md">referenced types</a> if you want to use a custom name.
41+
</tip>
3942

4043

4144

package.json

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,25 @@
5151
},
5252
"dependencies": {
5353
"@apollo/server": "4.9.3",
54-
"@deepkit/app": "1.0.1-alpha.98",
55-
"@deepkit/broker": "^1.0.1-alpha.97",
56-
"@deepkit/bson": "^1.0.1-alpha.97",
57-
"@deepkit/core": "1.0.1-alpha.97",
58-
"@deepkit/core-rxjs": "^1.0.1-alpha.97",
59-
"@deepkit/crypto": "^1.0.1-alpha.89",
60-
"@deepkit/event": "^1.0.1-alpha.97",
61-
"@deepkit/framework": "^1.0.1-alpha.99",
62-
"@deepkit/http": "^1.0.1-alpha.98",
63-
"@deepkit/injector": "^1.0.1-alpha.97",
64-
"@deepkit/logger": "^1.0.1-alpha.97",
65-
"@deepkit/orm": "1.0.1-alpha.98",
66-
"@deepkit/rpc": "1.0.1-alpha.97",
67-
"@deepkit/rpc-tcp": "^1.0.1-alpha.97",
68-
"@deepkit/sql": "^1.0.1-alpha.98",
69-
"@deepkit/stopwatch": "^1.0.1-alpha.97",
70-
"@deepkit/template": "^1.0.1-alpha.97",
71-
"@deepkit/type": "1.0.1-alpha.97",
72-
"@deepkit/type-compiler": "1.0.1-alpha.97",
73-
"@deepkit/workflow": "^1.0.1-alpha.97",
54+
"@deepkit/app": "1.0.1-alpha.105",
55+
"@deepkit/broker": "1.0.1-alpha.105",
56+
"@deepkit/bson": "1.0.1-alpha.105",
57+
"@deepkit/core": "1.0.1-alpha.105",
58+
"@deepkit/core-rxjs": "1.0.1-alpha.105",
59+
"@deepkit/event": "1.0.1-alpha.105",
60+
"@deepkit/framework": "1.0.1-alpha.106",
61+
"@deepkit/http": "1.0.1-alpha.105",
62+
"@deepkit/injector": "1.0.1-alpha.105",
63+
"@deepkit/logger": "1.0.1-alpha.105",
64+
"@deepkit/orm": "~1.0.1-alpha.105",
65+
"@deepkit/rpc": "~1.0.1-alpha.105",
66+
"@deepkit/rpc-tcp": "1.0.1-alpha.105",
67+
"@deepkit/sql": "1.0.1-alpha.105",
68+
"@deepkit/stopwatch": "1.0.1-alpha.105",
69+
"@deepkit/template": "1.0.1-alpha.105",
70+
"@deepkit/type": "1.0.1-alpha.105",
71+
"@deepkit/type-compiler": "1.0.1-alpha.105",
72+
"@deepkit/workflow": "1.0.1-alpha.105",
7473
"graphql": "^16.8.0",
7574
"graphql-request": "^6.1.0",
7675
"graphql-scalars": "^1.22.2",
@@ -82,12 +81,12 @@
8281
"pnpm": "8.7.4",
8382
"node": "20.4.0"
8483
},
84+
"nx": {
85+
"includedScripts": []
86+
},
8587
"pnpm": {
8688
"patchedDependencies": {
87-
"@deepkit/type-compiler@1.0.1-alpha.97": "patches/@deepkit__type-compiler@1.0.1-alpha.97.patch"
89+
"@deepkit/type-compiler@1.0.1-alpha.105": "patches/@deepkit__type-compiler@1.0.1-alpha.105.patch"
8890
}
89-
},
90-
"nx": {
91-
"includedScripts": []
9291
}
9392
}

packages/apollo/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
},
1515
"peerDependencies": {
1616
"@deepkit-graphql/core": "*",
17-
"@deepkit/app": "*",
18-
"@deepkit/http": "*",
19-
"@deepkit/framework": "*",
17+
"@deepkit/app": "^1.0.1-alpha.105",
18+
"@deepkit/http": "^1.0.1-alpha.105",
19+
"@deepkit/framework": "^1.0.1-alpha.106",
2020
"graphql": "^16.8.0"
2121
},
2222
"publishConfig": {
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { ApolloServerOptionsWithSchema } from '@apollo/server';
22

3-
export class ApolloGraphQLConfig
4-
implements
5-
Pick<
6-
ApolloServerOptionsWithSchema<{}>,
7-
| 'introspection'
8-
| 'nodeEnv'
9-
| 'allowBatchedHttpRequests'
10-
| 'csrfPrevention'
11-
| 'includeStacktraceInErrorResponses'
12-
| 'apollo'
13-
| 'stopOnTerminationSignals'
14-
| 'persistedQueries'
15-
> {}
3+
export type ApolloServerOptions = Pick<
4+
ApolloServerOptionsWithSchema<{}>,
5+
| 'introspection'
6+
| 'nodeEnv'
7+
| 'allowBatchedHttpRequests'
8+
| 'csrfPrevention'
9+
| 'includeStacktraceInErrorResponses'
10+
| 'apollo'
11+
| 'stopOnTerminationSignals'
12+
| 'persistedQueries'
13+
>;
14+
15+
export class ApolloGraphQLConfig implements ApolloServerOptions {}

packages/apollo/src/lib/apollo-graphql-driver.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
WebWorker,
1111
} from '@deepkit/framework';
1212
import { HttpBadRequestError, httpWorkflow } from '@deepkit/http';
13-
import { Driver } from '@deepkit-graphql/core';
13+
import { Driver, GraphQLHttpContext } from '@deepkit-graphql/core';
1414

1515
import { ApolloGraphQLConfig } from './apollo-graphql-config';
1616
import { ApolloServerPlugins } from './plugins';
@@ -53,9 +53,14 @@ export class ApolloDriver extends Driver {
5353
body: JSON.parse(await event.request.readBodyText()),
5454
};
5555

56+
const context: GraphQLHttpContext = {
57+
request: event.request,
58+
response: event.response,
59+
};
60+
5661
const response = await this.server!.executeHTTPGraphQLRequest({
5762
httpGraphQLRequest,
58-
context: async () => ({}),
63+
context: async () => context,
5964
});
6065
if (!response) {
6166
throw new HttpBadRequestError(JSON.stringify(httpGraphQLRequest));

packages/apollo/src/lib/apollo-graphql.module.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,37 @@ import { GraphQLModule } from '@deepkit-graphql/core';
33
import { ApolloServerPlugin } from '@apollo/server/dist/esm/externalTypes/plugins';
44

55
import { ApolloDriver } from './apollo-graphql-driver';
6-
import { ApolloGraphQLConfig } from './apollo-graphql-config';
6+
import {
7+
ApolloGraphQLConfig,
8+
ApolloServerOptions,
9+
} from './apollo-graphql-config';
710
import { ApolloServerPlugins } from './plugins';
811

12+
export interface ApolloGraphQLModuleOptions extends ApolloServerOptions {
13+
readonly plugins?: readonly ApolloServerPlugin[];
14+
}
15+
916
export class ApolloGraphQLModule extends createModule({
1017
config: ApolloGraphQLConfig,
1118
forRoot: true,
1219
}) {
13-
readonly plugins = new ApolloServerPlugins();
20+
readonly plugins: ApolloServerPlugins;
21+
22+
constructor({ plugins, ...options }: ApolloGraphQLModuleOptions) {
23+
super(options);
24+
this.plugins = new ApolloServerPlugins(plugins);
25+
}
1426

1527
process() {
1628
this.addProvider({
1729
provide: ApolloServerPlugins,
1830
useValue: this.plugins,
1931
});
20-
this.addModuleImport(
21-
new GraphQLModule(ApolloDriver),
22-
);
32+
this.addImport(new GraphQLModule(ApolloDriver));
2333
}
2434

2535
addPlugin(plugin: ApolloServerPlugin): this {
2636
this.plugins.add(plugin);
2737
return this;
2838
}
2939
}
30-

packages/core/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
"tslib": "2.6.2"
1414
},
1515
"peerDependencies": {
16-
"graphql": "16.8.0",
17-
"@deepkit/core": "^1.0.1-alpha.97",
18-
"@deepkit/type": "^1.0.1-alpha.97",
19-
"@deepkit/injector": "^1.0.1-alpha.97"
16+
"graphql": "^16.8.0",
17+
"@deepkit/core": "^1.0.1-alpha.105",
18+
"@deepkit/http": "^1.0.1-alpha.105",
19+
"@deepkit/type": "^1.0.1-alpha.105",
20+
"@deepkit/injector": "^1.0.1-alpha.105"
2021
},
2122
"publishConfig": {
2223
"access": "public"

0 commit comments

Comments
 (0)