Skip to content

Commit

Permalink
update readme example
Browse files Browse the repository at this point in the history
  • Loading branch information
v1rtl committed Aug 1, 2023
1 parent aa37961 commit 7aa18c2
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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:
Expand Down

0 comments on commit 7aa18c2

Please sign in to comment.