Bot releases are hidden (Show)
Full Changelog: https://github.com/deno-libs/gql/compare/2.0.2...3.0.1
Published by talentlessguy 12 months ago
A re-write of gql to fully comply with GraphQL-over-HTTP spec, based on graphql-http.
runHttpQuery
is removed. Query handling logic is now handled fully by graphql-http.GQLParams
is removed. Use graphql-http Request
type instead.text/plain
is no longer a valid. Use application/json
insteadvalidationRules
) is now available for gql.GraphQLHTTP
function argument - reqCtx
. Use it to modify the request context for GraphQL Request
object.Example:
import { GraphQLHTTP } from 'https://deno.land/x/[email protected]/mod.ts'
import { makeExecutableSchema } from 'npm:@graphql-tools/[email protected]'
import { gql } from 'https://deno.land/x/[email protected]/mod.ts'
import type { Request as GQLRequest } from 'npm:[email protected]'
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 })
})
Published by talentlessguy about 1 year ago
Published by talentlessguy about 3 years ago
v1.1 adds a new option to configure GraphQL Playground:
const app = GraphQLHTTP({
graphiql: true,
schema,
rootValue,
playgroundOptions: {
cdnUrl: 'https://unpkg.com'
}
})
Published by talentlessguy about 3 years ago
The v1 version now supports new std/http
API which is based on native HTTP server.
Published by talentlessguy about 3 years ago
You can now set custom HTTP headers for GraphQLHTTP handler:
GraphQLHTTP({ schema, headers: { Key: 'Value' } })