Skip to content

Commit

Permalink
document express customization of express endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
EmrysMyrddin committed Apr 28, 2023
1 parent 39714eb commit 1992460
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/express/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function buildApp(app: ReturnType<typeof express>) {
logging: false,
})

app.use('/graphql', graphQLServer)
app.use(graphQLServer)

return app
}
39 changes: 36 additions & 3 deletions website/src/pages/docs/integrations/integration-with-express.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description: Express is the most popular web framework for Node.js. It is a minimalist framework that provides a robust set of features to handle HTTP on Node.js applications.
---

import { PackageCmd } from '@theguild/components'
import { PackageCmd, Callout } from '@theguild/components'

# Integration with Express

Expand All @@ -28,12 +28,45 @@ const app = express()

const yoga = createYoga()

// Bind GraphQL Yoga to `/graphql` endpoint
app.use('/graphql', yoga)
app.use(yoga)

app.listen(4000, () => {
console.log('Running a GraphQL API server at http://localhost:4000/graphql')
})
```

> You can also check a full example on our GitHub repository [here](https://github.com/dotansimha/graphql-yoga/tree/v3/examples/express)
## Custom endpoint

By default, GraphQL Yoga will bind to the `/graphql` endpoint. You can change this behavior by passing a `graphqlEndpoint` option to the `createYoga` function.

```ts
import express from 'express'
import { createYoga } from 'graphql-yoga'

const app = express()

const yoga = createYoga({
graphqlEndpoint: '/custom/endpoint'
})

app.use(yoga)

app.listen(4000, () => {
console.log('Running a GraphQL API server at http://localhost:4000/graphql')
})
```

<Callout>
Always provide this option even when using express's router.

```ts
const yoga = createYoga({
graphqlEndpoint: '/custom/endpoint'
})

app.use('/custom/endpoint', yoga)
```

</Callout>

0 comments on commit 1992460

Please sign in to comment.