gql
I’m building Flash - a service to deploy websites and apps on the new decentralized stack.
Universal GraphQL HTTP middleware for Deno.
Features
- ✨ Works with
std/http
, Opine and oak - ⚡
GraphQL Playground
integration (via
graphiql: true
)
Get started
The simplest setup with std/http
:
import { GraphQLHTTP } from 'https://deno.land/x/gql@1.2.2/mod.ts'
import { makeExecutableSchema } from 'npm:@graphql-tools/schema@10.0.0'
import { gql } from 'https://deno.land/x/graphql_tag@0.1.2/mod.ts'
const typeDefs = gql`
type Query {
hello: String
}
`
const resolvers = {
Query: {
hello: () => `Hello World!`,
},
}
const schema = makeExecutableSchema({ resolvers, typeDefs })
Deno.serve({
port: 3000,
onListen({ hostname, port }) {
console.log(`☁ Started on http://${hostname}:${port}`)
},
}, async (req) => {
const { pathname } = new URL(req.url)
return pathname === '/graphql'
? await GraphQLHTTP<Request>({
schema,
graphiql: true,
})(req)
: new Response('Not Found', { status: 404 })
})
Then run:
$ curl -X POST localhost:3000/graphql -d '{ "query": "{ hello }" }'
{
"data": {
"hello": "Hello World!"
}
}
Or in GraphQL Playground: