Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade codebase to GraphQL v16 #1331

Merged
merged 11 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

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

steps:
- uses: actions/checkout@v1
Expand Down
11 changes: 5 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

## Unreleased
<!-- here goes all the unreleased changes descriptions -->
### Fixes
- support overwriting fields of extended types (#1109)
- properly execute args validation for nullable items array (#1328)

## v1.2.0-rc.1
### Features
- **Breaking Change**: `AuthChecker` type is now "function or class" - update to `AuthCheckerFn` if the function form is needed in the code
- **Breaking Change**: update `graphql-js` peer dependency to `^16.6.0`
- support class-based auth checker, which allows for dependency injection
- allow defining directives for interface types and theirs fields, with inheritance for object types fields (#744)
- allow deprecating input fields and args (#794)
Expand All @@ -21,8 +17,11 @@
- fix throwing error when schema with dynamic default value was built again (#787)
- fix converting inputs with fields of nested array type (#801)
- disable broken exposing input types fields under a changed name via `@Field({ name: "..." })`
- support overwriting fields of extended types (#1109)
- properly execute args validation for nullable items array (#1328)
### Others
- **Breaking Change**: update `graphql-js` peer dependency to `^15.5.0`
- **Breaking Change**: update `class-validator` peer dependency to `>=0.14.0`
- **Breaking Change**: change build config to ES2019 - drop support for Node.js < 14.5

## v1.1.1
### Fixes
Expand Down
7 changes: 7 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
presets: [["@babel/preset-env", { targets: { node: "current" } }], "@babel/preset-typescript"],
plugins: [
"babel-plugin-transform-typescript-metadata",
["@babel/plugin-syntax-decorators", { legacy: true }],
],
};
2 changes: 2 additions & 0 deletions docs/authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ const server = new ApolloServer({
},
});

await server.start();

// Mount a jwt or other authentication middleware that is run before the GraphQL execution
app.use(
path,
Expand Down
5 changes: 1 addition & 4 deletions docs/bootstrap.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ async function bootstrap() {
// ... Building schema here

// Create the GraphQL server
const server = new ApolloServer({
schema,
playground: true,
});
const server = new ApolloServer({ schema });

// Start the server
const { url } = await server.listen(PORT);
Expand Down
4 changes: 2 additions & 2 deletions docs/complexity.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ async function bootstrap() {
// Create a plugin that will allow for query complexity calculation for every request
plugins: [
{
requestDidStart: () => ({
didResolveOperation({ request, document }) {
requestDidStart: async () => ({
async didResolveOperation({ request, document }) {
/**
* This provides GraphQL query analysis to be able to react on complex queries to your GraphQL server.
* This can be used to protect your GraphQL servers against resource exhaustion and DoS attacks.
Expand Down
6 changes: 3 additions & 3 deletions docs/dependency-injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const server = new ApolloServer({

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.

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.
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.

Example using `TypeDI` and `apollo-server` with plugins approach:

Expand All @@ -134,8 +134,8 @@ const server = new ApolloServer({
// ... schema and context here
plugins: [
{
requestDidStart: () => ({
willSendResponse(requestContext) {
requestDidStart: async () => ({
async willSendResponse(requestContext) {
// remember to dispose the scoped container to prevent memory leaks
Container.reset(requestContext.context.requestId);
},
Expand Down
3 changes: 1 addition & 2 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ All examples have an `examples.gql` file with sample queries/mutations/subscript
- [Typegoose](https://github.com/MichalLytek/type-graphql/tree/master/examples/typegoose)
- [Apollo federation](https://github.com/MichalLytek/type-graphql/tree/master/examples/apollo-federation)
- [Apollo Cache Control](https://github.com/MichalLytek/type-graphql/tree/master/examples/apollo-cache)
- [Apollo Client state](https://github.com/MichalLytek/type-graphql/tree/master/examples/apollo-client)
- [GraphQL Modules](https://github.com/MichalLytek/type-graphql/tree/master/examples/graphql-modules)
- [Apollo Client local state](https://github.com/MichalLytek/type-graphql/tree/master/examples/apollo-client)

_\* Note that we need to edit the TypeORM example's `index.ts` with the credentials of our local database_
10 changes: 5 additions & 5 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ It's important to set these options in the `tsconfig.json` file of our project:
}
```

`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:
`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:

```js
{
"target": "es2018" // or newer if your node.js version supports this
"target": "es2019" // or newer if your node.js version supports this
}
```

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:

```json
{
"lib": ["es2018", "esnext.asynciterable"]
"lib": ["es2019", "esnext.asynciterable"]
}
```

Expand All @@ -60,9 +60,9 @@ All in all, the minimal `tsconfig.json` file example looks like this:
```json
{
"compilerOptions": {
"target": "es2018",
"target": "es2019",
"module": "commonjs",
"lib": ["es2018", "esnext.asynciterable"],
"lib": ["es2019", "esnext.asynciterable"],
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
Expand Down
17 changes: 2 additions & 15 deletions docs/subscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,8 @@ const schema = await buildSchema({

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.

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).
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:

```typescript
// Create GraphQL server
const server = new ApolloServer({
schema,
subscriptions: {
path: "/subscriptions",
// other options and hooks, like `onConnect`
},
});
```

And it's done! We have a working GraphQL subscription server on `/subscriptions`, along with the normal HTTP GraphQL server.
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:
https://www.apollographql.com/docs/apollo-server/data/subscriptions/#enabling-subscriptions

## Examples

Expand Down
3 changes: 1 addition & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ All examples has a `examples.gql` file with sample queries/mutations/subscriptio
- [Typegoose](./typegoose)
- [Apollo federation](./apollo-federation)
- [Apollo Cache Control](./apollo-cache)
- [Apollo Client state](./apollo-client)
- [GraphQL Modules](./graphql-modules)
- [Apollo Client local state](./apollo-client)

_\* Note that you need to edit the TypeORM examples `index.ts` with credentials to your local database_
2 changes: 1 addition & 1 deletion examples/apollo-cache/cache-control.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CacheHint } from "apollo-cache-control";
import type { CacheHint } from "apollo-server-types";
import { Directive } from "../../src";

export function CacheControl({ maxAge, scope }: CacheHint) {
Expand Down
12 changes: 7 additions & 5 deletions examples/apollo-cache/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "reflect-metadata";
import { ApolloServer } from "apollo-server";
import { ApolloServerPluginCacheControl } from "apollo-server-core";
import responseCachePlugin from "apollo-server-plugin-response-cache";
import { buildSchema } from "../../src";

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

const server = new ApolloServer({
schema,
tracing: true,
// turn on cache headers
cacheControl: true,
// add in-memory cache plugin
plugins: [responseCachePlugin()],
plugins: [
// turn on cache headers
ApolloServerPluginCacheControl(),
// add in-memory cache plugin
responseCachePlugin(),
],
});

const { url } = await server.listen(4000);
Expand Down
Binary file added examples/apollo-client/.parcel-cache/data.mdb
Binary file not shown.
Binary file added examples/apollo-client/.parcel-cache/lock.mdb
Binary file not shown.
8 changes: 8 additions & 0 deletions examples/apollo-client/.parcelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@parcel/config-default",
"transformers": {
"*.{ts,tsx}": [
"@parcel/transformer-typescript-tsc"
]
}
}
Loading