Skip to main content

gql

GitHub release (latest by date) GitHub Workflow Status Codecov

Universal GraphQL HTTP middleware for Deno.

Features

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):

image

PayPal ko-fi Qiwi Yandex Money

Bitcoin Ethereum ChainLink