Skip to content

Commit

Permalink
update dependencies, add Abc example
Browse files Browse the repository at this point in the history
  • Loading branch information
v1rtl committed Apr 28, 2021
1 parent da326b2 commit 25bd427
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
34 changes: 34 additions & 0 deletions examples/abc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Application } from 'https://deno.land/x/[email protected]/mod.ts'
import { GraphQLHTTP } from '../mod.ts'
import { makeExecutableSchema } from 'https://deno.land/x/graphql_tools/mod.ts'
import { gql } from 'https://deno.land/x/graphql_tag/mod.ts'

const app = new Application()

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

const resolvers = {
Query: {
hello: (_root: undefined, _args: unknown, ctx: { request: Request }, info: { fieldName: string }) => {
return `Hello World from ${ctx.request.url}!. You have called ${info.fieldName}`
}
}
}

const schema = makeExecutableSchema({ resolvers, typeDefs })

console.log(`☁ Started on http://localhost:3000`)

app
.use((next) => {
return async (ctx) => {
if (ctx.request.url.startsWith('/graphql')) {
return await GraphQLHTTP({ schema, graphiql: true })(ctx.request)
} else next(ctx)
}
})
.start({ port: 3000 })
13 changes: 10 additions & 3 deletions examples/opine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { opine } from 'https://deno.land/x/opine@1.2.0/mod.ts'
import { opine, Request } from 'https://deno.land/x/opine@1.3.3/mod.ts'
import { GraphQLHTTP } from '../mod.ts'
import { makeExecutableSchema } from 'https://deno.land/x/graphql_tools/mod.ts'
import { gql } from 'https://deno.land/x/graphql_tag/mod.ts'
Expand All @@ -11,12 +11,19 @@ const typeDefs = gql`

const resolvers = {
Query: {
hello: () => `Hello World!`
hello: (_root: undefined, _args: unknown, ctx: { request: Request }, info: { fieldName: string }) => {
return `Hello World from ${ctx.request.originalUrl}!. You have called ${info.fieldName}`
}
}
}

const schema = makeExecutableSchema({ resolvers, typeDefs })

const app = opine()

app.use('/graphql', GraphQLHTTP({ schema })).listen(3000, () => console.log(`☁ Started on http://localhost:3000`))
app
.use(
'/graphql',
GraphQLHTTP<Request>({ schema, context: (request) => ({ request }), graphiql: true })
)
.listen(3000, () => console.log(`☁ Started on http://localhost:3000`))
2 changes: 1 addition & 1 deletion examples/tinyhttp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App } from 'https://deno.land/x/tinyhttp/mod.ts'
import { App } from 'https://deno.land/x/tinyhttp@0.1.0/mod.ts'
import { GraphQLHTTP } from '../mod.ts'
import { makeExecutableSchema } from 'https://deno.land/x/graphql_tools/mod.ts'
import { gql } from 'https://deno.land/x/graphql_tag/mod.ts'
Expand Down
3 changes: 2 additions & 1 deletion http.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Request } from './types.ts'
import { runHttpQuery, GraphQLOptions } from './common.ts'
import { readAll } from 'https://deno.land/[email protected]/io/util.ts'

const dec = new TextDecoder()

Expand Down Expand Up @@ -35,7 +36,7 @@ export function GraphQLHTTP<Req extends Request = Request, Ctx extends { request
body: 'Method Not Allowed'
})
} else {
const body = await Deno.readAll(request.body)
const body = await readAll(request.body)

try {
const result = await runHttpQuery<Req, Ctx>(JSON.parse(dec.decode(body)), options, { request })
Expand Down
2 changes: 1 addition & 1 deletion types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ServerRequest } from 'https://deno.land/std@0.90.0/http/server.ts'
import { ServerRequest } from 'https://deno.land/std@0.95.0/http/server.ts'

/**
* Request type with only required properties
Expand Down

0 comments on commit 25bd427

Please sign in to comment.