Skip to content

2.0.0

Compare
Choose a tag to compare
@talentlessguy talentlessguy released this 09 Nov 12:38
· 8 commits to master since this release
f308841

A re-write of gql to fully comply with GraphQL-over-HTTP spec, based on graphql-http.

Breaking Changes

  • runHttpQuery is removed. Query handling logic is now handled fully by graphql-http.
  • GQLParams is removed. Use graphql-http Request type instead.
  • request type text/plain is no longer a valid. Use application/json instead

New Features

  • All of the configuration for GraphQL-over-HTTP (for example validationRules) is now available for gql.
  • New GraphQLHTTP function argument - reqCtx. Use it to modify the request context for GraphQL Request object.

Example:

import { GraphQLHTTP } from 'https://deno.land/x/gql@2.0.0/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'
import type { Request as GQLRequest } from 'npm:graphql-http@1.22.0'

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

type ReqContext = {
  request: Request
  isRequestContext: boolean
}

type Context = {
  request: Request
  originalReq: GQLRequest<Request, ReqContext>
}

const resolvers = {
  Query: {
    hello: (_root: unknown, _args: unknown, ctx: Context) => {
      return `Hello from request context: ${ctx.originalReq.context.isRequestContext}`
    },
  },
}

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, Context, ReqContext>({
      schema,
      graphiql: true,
      context: (request) => ({ request: req, originalReq: request }),
    }, () => ({ request: req, isRequestContext: true }))(req)
    : new Response('Not Found', { status: 404 })
})

Misc

  • Added GraphQL-over-HTTP compliance tests (100% compliance)
  • Bumped GraphQL from 16.6 to 16.8.1