Name: serverless-graphql-blog
Owner: Serverless
Description: A Serverless Blog leveraging GraphQL to offer a REST API with only 1 endpoint using Serverless v0.5
Created: 2016-01-19 01:53:44.0
Updated: 2018-05-21 06:03:35.0
Pushed: 2017-08-18 16:08:55.0
Size: 251
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Please note this project uses Serverless version 0.5
This Serverless Framework Project creates a REST API for a basic blog structure, including Posts, Authors and Comments utilizing GraphQL and DynamoDB for persistent storage. What's unique about this implementation is the entire REST API consists of only 1 endpoint.
Note: This project automatically creates 3 DynamoDB tables upon serverless project install
. They are defined in s-project.json
.
Enjoy,
Kevin Old (Twitter)
Make sure you have the most recent version of the Serverless Framework (0.5.x and higher) and you are using NodeV4 or greater.
install serverless -g
Install this Serverless Project:
erless project install serverless-graphql-blog
Install (top level) npm dependencies
install
View project summary:
erless dash summary
Deploy the project's Function and Endpoint:
erless dash deploy
The graphql-js endpoint provided in this Serverless Project is compatible with GraphiQL, a query visualization tool used with graphql-js.
Usage with GraphiQL.app (an Electron wrapper around GraphiQL) is recommended and is shown below:
-XPOST -d '{"query": "{ authors { name } }"}' <endpoint>/dev/blog/graphql
ata":{
"authors":[
{"name":"Kevin"}
]
-XPOST -d '{"query": "{ posts { id, title } }"}' <endpoint>/dev/blog/graphql
ata": {
"posts": [
{ "id":"1",
"title":"First Post Title"
}
]
-XPOST -d '{"query": "{ posts { id, title, author { name } } }"}' <endpoint>/dev/blog/graphql
ata": {
"posts": [
{ "id":"1",
"title":"First Post Title",
"author":{
"name":"Kevin"
}
}
]
-XPOST -d '{"query": "{ posts { id, title, author { id, name }, comments { id, content, author { name } } } }"}' <endpoint>/dev/blog/graphql
ata":{
"posts":[
{
"id":"1",
"title":"First Post Title",
"author":{
"id":"1",
"name":"Kevin"
},
"comments":[]
}
]
-XPOST -d '{"query": "mutation createNewPost { post: createPost (id: \"5\", title: \"Fifth post!\", bodyContent: \"Test content\", author: \"1\") { id, title } }"}' <endpoint>/dev/blog/graphql
ata":{
"post":{
"id":"5",
"title":"Fifth post!"
}
Validations defined using graphql-custom-types in blog/lib/schema.js
-XPOST -d '{"query": "mutation createNewPost { post: createPost (id: \"8\", title: \"123456789\", bodyContent: \"Test content 5\") { id, title } }"}' <endpoint>/dev/blog/graphql
rrors":[
"message":"Query error: String not long enough"}
-XPOST -d '{"query": "{__schema { queryType { name, fields { name, description} }}}"}' <endpoint>/dev/blog/graphql
Returns:
ata":{
"__schema":{
"queryType":{
"name":"BlogSchema",
"fields":[
{
"name":"posts",
"description":"List of posts in the blog"
},
{
"name":"authors",
"description":"List of Authors"
},
{
"name":"author",
"description":"Get Author by id"
}
]
}
}