Skip to content

Commit d3ecacd

Browse files
authored
Merge pull request #1331 from MichalLytek/graphql-v16
Upgrade codebase to GraphQL v16
2 parents 55ecf06 + fdd4ad8 commit d3ecacd

File tree

125 files changed

+48779
-23646
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+48779
-23646
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
strategy:
1616
matrix:
17-
node-version: [10.13, 10.x, 11.x, 12.x, 13.x, 14.x, 15.x]
17+
node-version: [14.x, 16.x, 18.x]
1818

1919
steps:
2020
- uses: actions/checkout@v1

CHANGELOG.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22

33
## Unreleased
44
<!-- here goes all the unreleased changes descriptions -->
5-
### Fixes
6-
- support overwriting fields of extended types (#1109)
7-
- properly execute args validation for nullable items array (#1328)
8-
9-
## v1.2.0-rc.1
105
### Features
116
- **Breaking Change**: `AuthChecker` type is now "function or class" - update to `AuthCheckerFn` if the function form is needed in the code
7+
- **Breaking Change**: update `graphql-js` peer dependency to `^16.6.0`
128
- support class-based auth checker, which allows for dependency injection
139
- allow defining directives for interface types and theirs fields, with inheritance for object types fields (#744)
1410
- allow deprecating input fields and args (#794)
@@ -21,8 +17,11 @@
2117
- fix throwing error when schema with dynamic default value was built again (#787)
2218
- fix converting inputs with fields of nested array type (#801)
2319
- disable broken exposing input types fields under a changed name via `@Field({ name: "..." })`
20+
- support overwriting fields of extended types (#1109)
21+
- properly execute args validation for nullable items array (#1328)
2422
### Others
25-
- **Breaking Change**: update `graphql-js` peer dependency to `^15.5.0`
23+
- **Breaking Change**: update `class-validator` peer dependency to `>=0.14.0`
24+
- **Breaking Change**: change build config to ES2019 - drop support for Node.js < 14.5
2625

2726
## v1.1.1
2827
### Fixes

babel.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
presets: [["@babel/preset-env", { targets: { node: "current" } }], "@babel/preset-typescript"],
3+
plugins: [
4+
"babel-plugin-transform-typescript-metadata",
5+
["@babel/plugin-syntax-decorators", { legacy: true }],
6+
],
7+
};

docs/authorization.md

+2
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ const server = new ApolloServer({
157157
},
158158
});
159159

160+
await server.start();
161+
160162
// Mount a jwt or other authentication middleware that is run before the GraphQL execution
161163
app.use(
162164
path,

docs/bootstrap.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ async function bootstrap() {
8888
// ... Building schema here
8989

9090
// Create the GraphQL server
91-
const server = new ApolloServer({
92-
schema,
93-
playground: true,
94-
});
91+
const server = new ApolloServer({ schema });
9592

9693
// Start the server
9794
const { url } = await server.listen(PORT);

docs/complexity.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ async function bootstrap() {
4141
// Create a plugin that will allow for query complexity calculation for every request
4242
plugins: [
4343
{
44-
requestDidStart: () => ({
45-
didResolveOperation({ request, document }) {
44+
requestDidStart: async () => ({
45+
async didResolveOperation({ request, document }) {
4646
/**
4747
* This provides GraphQL query analysis to be able to react on complex queries to your GraphQL server.
4848
* This can be used to protect your GraphQL servers against resource exhaustion and DoS attacks.

docs/dependency-injection.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const server = new ApolloServer({
122122
123123
We also have to dispose the container after the request has been handled and the response is ready. Otherwise, there would be a huge memory leak as the new instances of services and resolvers have been created for each request but they haven't been cleaned up.
124124
125-
Apollo Server since version 2.2.0 has a [plugins](https://www.apollographql.com/docs/apollo-server/integrations/plugins/) feature that supports [`willSendResponse`](https://www.apollographql.com/docs/apollo-server/integrations/plugins/#willsendresponse) lifecycle event. We can leverage it to clean up the container after handling the request.
125+
Apollo Server has a [plugins](https://www.apollographql.com/docs/apollo-server/integrations/plugins/) feature that supports [`willSendResponse`](https://www.apollographql.com/docs/apollo-server/integrations/plugins/#willsendresponse) lifecycle event. We can leverage it to clean up the container after handling the request.
126126
127127
Example using `TypeDI` and `apollo-server` with plugins approach:
128128
@@ -134,8 +134,8 @@ const server = new ApolloServer({
134134
// ... schema and context here
135135
plugins: [
136136
{
137-
requestDidStart: () => ({
138-
willSendResponse(requestContext) {
137+
requestDidStart: async () => ({
138+
async willSendResponse(requestContext) {
139139
// remember to dispose the scoped container to prevent memory leaks
140140
Container.reset(requestContext.context.requestId);
141141
},

docs/examples.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ All examples have an `examples.gql` file with sample queries/mutations/subscript
4141
- [Typegoose](https://github.com/MichalLytek/type-graphql/tree/master/examples/typegoose)
4242
- [Apollo federation](https://github.com/MichalLytek/type-graphql/tree/master/examples/apollo-federation)
4343
- [Apollo Cache Control](https://github.com/MichalLytek/type-graphql/tree/master/examples/apollo-cache)
44-
- [Apollo Client state](https://github.com/MichalLytek/type-graphql/tree/master/examples/apollo-client)
45-
- [GraphQL Modules](https://github.com/MichalLytek/type-graphql/tree/master/examples/graphql-modules)
44+
- [Apollo Client local state](https://github.com/MichalLytek/type-graphql/tree/master/examples/apollo-client)
4645

4746
_\* Note that we need to edit the TypeORM example's `index.ts` with the credentials of our local database_

docs/installation.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ It's important to set these options in the `tsconfig.json` file of our project:
3939
}
4040
```
4141

42-
`TypeGraphQL` is designed to work with Node.js LTS (10.3+, 12+) and the latest stable releases. It uses features from ES2018 so we should set our `tsconfig.json` file appropriately:
42+
`TypeGraphQL` is designed to work with Node.js LTS and the latest stable releases. It uses features from ES2019 so we should set our `tsconfig.json` file appropriately:
4343

4444
```js
4545
{
46-
"target": "es2018" // or newer if your node.js version supports this
46+
"target": "es2019" // or newer if your node.js version supports this
4747
}
4848
```
4949

5050
Due to using the `graphql-subscription` dependency that relies on an `AsyncIterator`, we may also have to provide the `esnext.asynciterable` to the `lib` option:
5151

5252
```json
5353
{
54-
"lib": ["es2018", "esnext.asynciterable"]
54+
"lib": ["es2019", "esnext.asynciterable"]
5555
}
5656
```
5757

@@ -60,9 +60,9 @@ All in all, the minimal `tsconfig.json` file example looks like this:
6060
```json
6161
{
6262
"compilerOptions": {
63-
"target": "es2018",
63+
"target": "es2019",
6464
"module": "commonjs",
65-
"lib": ["es2018", "esnext.asynciterable"],
65+
"lib": ["es2019", "esnext.asynciterable"],
6666
"experimentalDecorators": true,
6767
"emitDecoratorMetadata": true
6868
}

docs/subscriptions.md

+2-15
Original file line numberDiff line numberDiff line change
@@ -178,21 +178,8 @@ const schema = await buildSchema({
178178

179179
The [bootstrap guide](bootstrap.md) and all the earlier examples used [`apollo-server`](https://github.com/apollographql/apollo-server) to create an HTTP endpoint for our GraphQL API.
180180

181-
Fortunately, to make subscriptions work, we don't need to manually provide a transport layer that doesn't have constraints of HTTP and can do a push-based communication (WebSockets).
182-
The `apollo-server` package has built-in subscriptions support using websockets, so it works out of the box without any changes to our bootstrap config. However, if we want, we can provide the `subscriptions` property of the config object:
183-
184-
```typescript
185-
// Create GraphQL server
186-
const server = new ApolloServer({
187-
schema,
188-
subscriptions: {
189-
path: "/subscriptions",
190-
// other options and hooks, like `onConnect`
191-
},
192-
});
193-
```
194-
195-
And it's done! We have a working GraphQL subscription server on `/subscriptions`, along with the normal HTTP GraphQL server.
181+
However, beginning in Apollo Server 3, subscriptions are not supported by the "batteries-included" apollo-server package. To enable subscriptions, you need to follow the guide on their docs page:
182+
https://www.apollographql.com/docs/apollo-server/data/subscriptions/#enabling-subscriptions
196183

197184
## Examples
198185

examples/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ All examples has a `examples.gql` file with sample queries/mutations/subscriptio
4141
- [Typegoose](./typegoose)
4242
- [Apollo federation](./apollo-federation)
4343
- [Apollo Cache Control](./apollo-cache)
44-
- [Apollo Client state](./apollo-client)
45-
- [GraphQL Modules](./graphql-modules)
44+
- [Apollo Client local state](./apollo-client)
4645

4746
_\* Note that you need to edit the TypeORM examples `index.ts` with credentials to your local database_

examples/apollo-cache/cache-control.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CacheHint } from "apollo-cache-control";
1+
import type { CacheHint } from "apollo-server-types";
22
import { Directive } from "../../src";
33

44
export function CacheControl({ maxAge, scope }: CacheHint) {

examples/apollo-cache/index.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import "reflect-metadata";
22
import { ApolloServer } from "apollo-server";
3+
import { ApolloServerPluginCacheControl } from "apollo-server-core";
34
import responseCachePlugin from "apollo-server-plugin-response-cache";
45
import { buildSchema } from "../../src";
56

@@ -12,11 +13,12 @@ async function bootstrap() {
1213

1314
const server = new ApolloServer({
1415
schema,
15-
tracing: true,
16-
// turn on cache headers
17-
cacheControl: true,
18-
// add in-memory cache plugin
19-
plugins: [responseCachePlugin()],
16+
plugins: [
17+
// turn on cache headers
18+
ApolloServerPluginCacheControl(),
19+
// add in-memory cache plugin
20+
responseCachePlugin(),
21+
],
2022
});
2123

2224
const { url } = await server.listen(4000);
17.5 MB
Binary file not shown.
8.08 KB
Binary file not shown.

examples/apollo-client/.parcelrc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "@parcel/config-default",
3+
"transformers": {
4+
"*.{ts,tsx}": [
5+
"@parcel/transformer-typescript-tsc"
6+
]
7+
}
8+
}

0 commit comments

Comments
 (0)