Skip to content

Commit

Permalink
add deprecation changeset for graphqlSchema in extendHttpServer
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Feb 15, 2024
1 parent 544fb20 commit e1b90ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/less-extend-http-server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
----
'@keystone-6/core': patch
----

Deprecates `extendHttpServer`'s third argument, the graphqlSchema. Use `context.graphql.schema`
21 changes: 8 additions & 13 deletions docs/pages/docs/config/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export default config<TypeInfo>({
port: 3000,
maxFileSize: 200 * 1024 * 1024,
extendExpressApp: async (app, commonContext) => { /* ... */ },
extendHttpServer: async (httpServer, commonContext, graphQLSchema) => { /* ... */ },
extendHttpServer: async (httpServer, commonContext) => { /* ... */ },
},
/* ... */
});
Expand Down Expand Up @@ -276,7 +276,7 @@ You could also use it to add custom REST endpoints to your server, by creating a
```ts
export default config<TypeInfo>({
server: {
extendExpressApp: (app, commonContext) => {
extendExpressApp: (app, commonContext) => {
app.get('/api/users', async (req, res) => {
const context = await commonContext.withRequest(req, res);
const users = await context.query.User.findMany();
Expand All @@ -299,7 +299,6 @@ The function is passed in 3 arguments:

- `server` - this is the HTTP server that you can then extend
- `context`: A Keystone Context
- `graphqlSchema` - this is the keystone graphql schema that can be used in a WebSocket GraphQL server for subscriptions

For example, this function could be used to listen for `'upgrade'` requests for a WebSocket server when adding support for GraphQL subscriptions

Expand All @@ -309,13 +308,13 @@ import { useServer as wsUseServer } from 'graphql-ws/lib/use/ws';

export default config<TypeInfo>({
server: {
extendHttpServer: (httpServer, commonContext, graphqlSchema) => {
extendHttpServer: (httpServer, commonContext) => {
const wss = new WebSocketServer({
server: httpServer,
path: '/api/graphql',
});

wsUseServer({ schema: graphqlSchema }, wss);
wsUseServer({ schema: commonContext.graphql.schema }, wss);
},
},
});
Expand Down Expand Up @@ -383,25 +382,21 @@ export default config<TypeInfo>({

## extendGraphqlSchema

```ts
import type { ExtendGraphqlSchema } from '@keystone-6/core/types';
```

The `extendGraphqlSchema` config option allows you to extend the GraphQL API which is generated by Keystone based on your schema definition.
It has a TypeScript type of `ExtendGraphqlSchema`.

`extendGraphqlSchema` expects a function that takes the GraphQL Schema generated by Keystone and returns a valid GraphQL Schema

```typescript
import { config, graphql } from '@keystone-6/core';
import type { GraphQLSchema } from 'graphql'
import { config, graphql } from '@keystone-6/core'

export default config<TypeInfo>({
extendGraphqlSchema: keystoneSchema => {
extendGraphqlSchema: (keystoneSchema: GraphQLSchema) => {
/* ... */
return newExtendedSchema
}
/* ... */
});
})
```

See the [schema extension guide](../guides/schema-extension) for more details and tooling options on how to extend your GraphQL API.
Expand Down

0 comments on commit e1b90ec

Please sign in to comment.