Skip to content

Commit fe7886e

Browse files
committed
better endpoint binding in documentation
1 parent ec5bc22 commit fe7886e

File tree

4 files changed

+10
-27
lines changed

4 files changed

+10
-27
lines changed

website/src/pages/docs/integrations/integration-with-deno.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ const yoga = createYoga({
4343

4444
serve(yoga, {
4545
onListen({ hostname, port }) {
46-
console.log(`Listening on http://${hostname}:${port}/graphql`)
46+
console.log(
47+
`Listening on http://${hostname}:${port}/${yoga.graphqlEndpoint}}`
48+
)
4749
}
4850
})
4951
```

website/src/pages/docs/integrations/integration-with-express.mdx

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,12 @@ const app = express()
2828

2929
const yoga = createYoga()
3030

31-
// Bind GraphQL Yoga to `/graphql` endpoint
32-
app.use('/graphql', yoga)
31+
// Bind GraphQL Yoga to the graphql endpoint to avoid rendering the playground on any path
32+
app.use(yoga.graphqlEndpoint, yoga)
3333

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

3939
> You can also check a full example on our GitHub repository [here](https://github.com/dotansimha/graphql-yoga/tree/v3/examples/express)
40-
41-
## Custom endpoint
42-
43-
By default, GraphQL Yoga will bind to the `/graphql` endpoint. You can change this behavior by passing a `graphqlEndpoint` option to the `createYoga` function.
44-
45-
```ts
46-
import express from 'express'
47-
import { createYoga } from 'graphql-yoga'
48-
49-
const app = express()
50-
51-
const yoga = createYoga({
52-
graphqlEndpoint: '/custom/endpoint'
53-
})
54-
55-
app.use('/custom/endpoint', yoga)
56-
57-
app.listen(4000, () => {
58-
console.log('Running a GraphQL API server at http://localhost:4000/graphql')
59-
})
60-
```

website/src/pages/docs/integrations/integration-with-fastify.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ const yoga = createYoga<{
9595
req: FastifyRequest
9696
reply: FastifyReply
9797
}>({
98-
graphqlEndpoint: '/custom/endpoint',
9998
// Integrate Fastify logger
10099
logging: {
101100
debug: (...args) => args.forEach((arg) => app.log.debug(arg)),
@@ -111,7 +110,8 @@ const yoga = createYoga<{
111110
* Learn more about `reply` https://www.fastify.io/docs/latest/Reply/
112111
**/
113112
app.route({
114-
url: '/custom/endpoint',
113+
// Bind to the Yoga's endpoint to avoid rendering on any path
114+
url: yoga.graphqlEndpoint,
115115
method: ['GET', 'POST', 'OPTIONS'],
116116
handler: async (req, reply) => {
117117
// Second parameter adds Fastify's `req` and `reply` to the GraphQL Context

website/src/pages/docs/integrations/integration-with-koa.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ app.use(async (ctx) => {
4141
})
4242

4343
app.listen(4000, () => {
44-
console.log('Running a GraphQL API server at http://localhost:4000')
44+
console.log(
45+
`Running a GraphQL API server at http://localhost:4000/${yoga.graphqlEndpoint}`
46+
)
4547
})
4648
```
4749

0 commit comments

Comments
 (0)