Skip to main content


nest badge GitHub Workflow Status Codecov

gql

Universal GraphQL HTTP middleware for Deno.

Features

Get started

The simplest setup with std/http:

import { serve } from 'https://deno.land/std@0.182.0/http/server.ts'
import { GraphQLHTTP } from 'https://deno.land/x/gql@1.2.2/mod.ts'
import { makeExecutableSchema } from 'https://esm.sh/@graphql-tools/schema@9.0.17?target=deno'
import { gql } from 'https://deno.land/x/graphql_tag@0.1.1/mod.ts'

const typeDefs = gql`
  type Query {
    hello: String
  }
`

const resolvers = {
  Query: {
    hello: () => `Hello World!`,
  },
}

const schema = makeExecutableSchema({ resolvers, typeDefs })

await serve(async (req) => {
  const { pathname } = new URL(req.url)

  return pathname === '/graphql'
    ? await GraphQLHTTP<Request>({
      schema,
      graphiql: true,
    })(req)
    : new Response('Not Found', { status: 404 })
}, {
  port: 3000,
  onListen: ({ hostname, port }) =>
    console.log(`☁  Started on http://${hostname}:${port}`),
})

Then run:

$ curl -X POST localhost:3000/graphql -d '{ "query": "{ hello }" }'
{
  "data": {
    "hello": "Hello World!"
  }
}

Or in GraphQL Playground:

image