-
-
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.
- Loading branch information
v1rtl
committed
Aug 1, 2023
1 parent
aa37961
commit 7aa18c2
Showing
1 changed file
with
8 additions
and
10 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 |
---|---|---|
|
@@ -30,10 +30,9 @@ Universal [GraphQL](https://www.graphql.com/) HTTP middleware for Deno. | |
The simplest setup with `std/http`: | ||
|
||
```ts | ||
import { serve } from 'https://deno.land/[email protected]/http/server.ts' | ||
import { GraphQLHTTP } from 'https://deno.land/x/[email protected]/mod.ts' | ||
import { makeExecutableSchema } from 'https://esm.sh/@graphql-tools/schema@9.0.17?target=deno' | ||
import { gql } from 'https://deno.land/x/[email protected].1/mod.ts' | ||
import { makeExecutableSchema } from 'npm:@graphql-tools/schema@10.0.0' | ||
import { gql } from 'https://deno.land/x/[email protected].2/mod.ts' | ||
|
||
const typeDefs = gql` | ||
type Query { | ||
|
@@ -49,21 +48,20 @@ const resolvers = { | |
|
||
const schema = makeExecutableSchema({ resolvers, typeDefs }) | ||
|
||
await serve(async (req) => { | ||
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>({ | ||
schema, | ||
graphiql: true, | ||
})(req) | ||
: new Response('Not Found', { status: 404 }) | ||
}, { | ||
port: 3000, | ||
onListen: ({ hostname, port }) => | ||
console.log(`☁ Started on http://${hostname}:${port}`), | ||
}) | ||
|
||
``` | ||
|
||
Then run: | ||
|