-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update dependencies, add Abc example
- Loading branch information
v1rtl
committed
Apr 28, 2021
1 parent
da326b2
commit 25bd427
Showing
5 changed files
with
48 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
|
@@ -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 }) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters