Skip to content

Commit

Permalink
simple koa implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaEvo committed Apr 19, 2020
0 parents commit ffa6704
Show file tree
Hide file tree
Showing 7 changed files with 723 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
28 changes: 28 additions & 0 deletions example/koa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Koa from "koa"
import { readFileSync } from "fs"
import { join, dirname } from "path"
import { fileURLToPath } from 'url'
import bodyParser from "koa-bodyparser"
import tools from 'graphql-tools'
const { makeExecutableSchema } = tools

import graphql from "../src/koa"

const dir = dirname(fileURLToPath(import.meta.url))

const app = new Koa()
.use(bodyParser())
.use(graphql({
schema: makeExecutableSchema({
typeDefs: readFileSync(join(dir, "schema.gql"), "utf-8"),
resolvers: {
Query: {
hello(root, { name }) {
return `Hello ${name} !`
}
}
}
})
}))

const server = app.listen(3000, () => console.log("Listening on ", server.address()))
16 changes: 16 additions & 0 deletions example/schema.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type Query {
hello(name: String!): String!
me: User
}

type User {
sayHello(to: String!): String!
}

type Mutation {
sendMessage(message: String!): String!
}

type Subscription {
onMessage: String
}
Loading

0 comments on commit ffa6704

Please sign in to comment.