You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/plugins/graphql-yoga.md
+33Lines changed: 33 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,6 +52,39 @@ optional: you can install custom version of optional peer dependencies as well:
52
52
bun add graphql graphql-yoga
53
53
```
54
54
55
+
## Resolver
56
+
Elysia use [Mobius](https://github.com/saltyaom/mobius) to infers type from **typeDefs** field automatically, allowing you to get full type-safety and auto-complete when typing **resolver** types.
57
+
58
+
## Context
59
+
You can add custom context to resolver function by adding **context**
60
+
```ts
61
+
import { Elysia } from'elysia'
62
+
import { yoga } from'@elysiajs/graphql-yoga'
63
+
64
+
const app =newElysia()
65
+
.use(
66
+
yoga({
67
+
typeDefs: /* GraphQL */`
68
+
type Query {
69
+
hi: String
70
+
}
71
+
`,
72
+
context: {
73
+
name: 'Mobius'
74
+
},
75
+
// If context is a function on this doesn't present
76
+
// for some reason it won't infer context type
77
+
useContext(_) {}
78
+
resolvers: {
79
+
Query: {
80
+
hi: async (parent, args, context) =>context.name
81
+
}
82
+
}
83
+
})
84
+
)
85
+
.listen(8080)
86
+
```
87
+
55
88
## Config
56
89
This plugin extends [GraphQL Yoga's createYoga options, please refers to the GraphQL Yoga documentation](https://the-guild.dev/graphql/yoga-server/docs) with inlining `schema` config to root.
0 commit comments