honojs-middleware/README.md

50 lines
637 B
Markdown
Raw Normal View History

2022-07-21 08:43:43 +08:00
# GraphQL Server Middleware
## Requirements
This middleware depends on [GraphQL.js](https://www.npmjs.com/package/graphql).
```sh
npm i @honojs/graphql-server
2022-07-21 08:43:43 +08:00
```
or
```plain
yarn add @honojs/graphql-server
2022-07-21 08:43:43 +08:00
```
## Usage
index.js:
```js
import { Hono } from 'hono'
2022-08-11 21:04:08 +08:00
import { graphqlServer } from '@honojs/graphql-server'
2022-07-21 08:43:43 +08:00
import { buildSchema } from 'graphql'
export const app = new Hono()
const schema = buildSchema(`
type Query {
hello: String
}
`)
const rootResolver = (ctx) => {
return {
hello: () => 'Hello Hono!',
}
2022-07-21 08:43:43 +08:00
}
app.use(
'/graphql',
graphqlServer({
schema,
rootResolver,
2022-07-21 08:43:43 +08:00
})
)
app.fire()
```