gql
Universal GraphQL HTTP middleware for Deno.
Features
- ✨ Works with
std/http
, tinyhttp and Opine out-of-the-box - ⚡ GraphQL Playground integration (via
graphiql: true
)
Get started
Vanilla
The simplest setup with std/http
:
import { serve } from 'https://deno.land/std@0.90.0/http/server.ts'
import { GraphQLHTTP } from 'https://deno.land/x/gql/mod.ts'
import { buildSchema } from 'https://deno.land/x/graphql_deno@v15.0.0/mod.ts'
const schema = buildSchema(`
type Query {
hello: String
}
`)
const s = serve({ port: 3000 })
for await (const req of s) {
req.url.startsWith('/graphql')
? await GraphQLHTTP({
schema,
rootValue: {
hello: () => 'Hello World!'
},
graphiql: true
})(req)
: req.respond({
status: 404
})
}
Then run:
$ curl -X POST localhost:3000/graphql -d '{ "query": "{ hello }" }'
{
"data": {
"hello": "Hello World!"
}
}
Or in GraphQL Playground (https://localhost:3000/graphql):