gql

GitHub release (latest by date) GitHub Workflow Status Codecov

Universal GraphQL HTTP middleware for Deno.

Examples

Vanilla

import { serve } from 'https://deno.land/std@0.90.0/http/server.ts'
import { GraphQLHTTP } from 'https://deno.land/x/gql/mod.ts'
import { GraphQLSchema, GraphQLString, GraphQLObjectType } from 'https://deno.land/x/graphql_deno@v15.0.0/mod.ts'

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'Query',
    fields: {
      hello: {
        type: GraphQLString,
        resolve() {
          return 'Hello World!'
        }
      }
    }
  })
})

for await (const req of serve({ port: 3000 })) {
  await GraphQLHTTP({ schema })(req)
}

tinyhttp

import { App } from 'https://deno.land/x/tinyhttp/mod.ts'
import { GraphQLHTTP } from 'https://deno.land/x/gql/mod.ts'
import { GraphQLSchema, GraphQLString, GraphQLObjectType } from 'https://deno.land/x/graphql_deno@v15.0.0/mod.ts'

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'Query',
    fields: {
      hello: {
        type: GraphQLString,
        resolve() {
          return 'Hello World!'
        }
      }
    }
  })
})

const app = new App()

app.post('/graphql', GraphQLHTTP({ schema }))

app.listen(3000, () => console.log(`☁  Started on http://localhost:3000`))

Then run:

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

PayPal ko-fi Qiwi Yandex Money Bitcoin Ethereu,