Awesome Open Source
Awesome Open Source


nest badge GitHub Workflow Status Codecov

gql

Universal GraphQL HTTP middleware for Deno.

Features

Donate

DEV

🎁 FIRST 10 PATRONS WILL RECEIVE BONUS 5 DEV 🎁

Reward status: waiting for gas fees to get at least to 20-25 gwei

  • 0xB3ebEe9d3E0bad437B75f4678D390c0d9608daF5 [pending]
  • 0xAb0658c66670d93BF47B4b8D5797edD0a60F43A0 [pending]

The best way to support the project is to do staking on stakes.social. Note that you also get rewarded by staking, as well as the project author.

Get started

Vanilla

The simplest setup with std/http:

import { Server } from 'https://deno.land/[email protected]/http/server.ts'
import { GraphQLHTTP } from '../mod.ts'
import { makeExecutableSchema } from 'https://deno.land/x/[email protected]/mod.ts'
import { gql } from 'https://deno.land/x/[email protected]/mod.ts'

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

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

const s = new Server({
  handler: async (req) => {
    const { pathname } = new URL(req.url)

    return pathname === '/graphql'
      ? await GraphQLHTTP<Request>({
          schema: makeExecutableSchema({ resolvers, typeDefs }),
          graphiql: true
        })(req)
      : new Response('Not Found', { status: 404 })
  },
  addr: ':3000'
})

s.listenAndServe()

Then run:

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

Or in GraphQL Playground:

image


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Typescript (247,336
Graphql (8,126
Deno (1,408
Graphql Server (563
Graphql Api (241
Related Projects