-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit aaf3f5d
Showing
7 changed files
with
296 additions
and
0 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 @@ | ||
node_modules |
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,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_ |
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,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}`) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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" | ||
} | ||
} |
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,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) | ||
} | ||
} |
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,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 | ||
} | ||
` |