Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
braidn committed Aug 12, 2019
0 parents commit aaf3f5d
Show file tree
Hide file tree
Showing 7 changed files with 296 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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Simplest GraphQl Server

Sometimes these things don't really have to be super complicated.
Has anyone seen the amount of modules that Apollo brings with it?
Yeah... Perhaps great for a gateway but,
overkill for something dead simple.

This repo explores making the tiniest GraphQl server possible.
Some use cases (maybe):

- Quick Lambda functions
- Intermediary service/api layer between two rest APIs
- Building something _FAST_
23 changes: 23 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import polka from 'polka'
import bp from 'body-parser'
const { json } = bp
import send from '@polka/send-type'
import * as gql from 'graphql'
import * as taskDefs from './src/schema'
import resolvers from './src/resolvers'
const { graphql, buildSchema } = gql
const { port=3000 } = process.env

const serverSchema = buildSchema(taskDefs.schema)

polka()
.use(json())
.post('/', async (req, res) => {
let { query } = req.body
const data = await graphql(serverSchema, query, resolvers)
send(res, 200, data)
})
.listen(port, err => {
if (err) throw err
console.log(`🚀 on port: ${port}`)
})
212 changes: 212 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "polka-simple-gql",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@polka/send-type": "^0.5.2",
"body-parser": "^1.19.0",
"graphql": "^14.4.2",
"polka": "^0.5.2"
}
}
16 changes: 16 additions & 0 deletions src/resolvers.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default {
tasks: () => {
return [
{ id:"CB031B56-420C-440B-B09C-857CDC3FDBC4", name:'Go to Market', complete:false },
{ id:"27F08563-47F9-4EB6-9A3C-1ACD07FB68F7", name:'Walk the dog', complete:true },
{ id:"F5A5C82B-F919-4551-A0F0-DEFA11B04FA2", name:'Take a nap', complete:false }
]
},
task: (args) => {
return [
{ id:"CB031B56-420C-440B-B09C-857CDC3FDBC4", name:'Go to Market', complete:false },
{ id:"27F08563-47F9-4EB6-9A3C-1ACD07FB68F7", name:'Walk the dog', complete:true },
{ id:"F5A5C82B-F919-4551-A0F0-DEFA11B04FA2", name:'Take a nap', complete:false }
].find(o => o.id === args.id)
}
}
14 changes: 14 additions & 0 deletions src/schema.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const schema = `
interface Node {
id: ID
}
type Task implements Node {
id: ID!
name: String!
complete: Boolean!
}
type Query {
tasks: [Task]
task(id: ID): Task
}
`

0 comments on commit aaf3f5d

Please sign in to comment.