百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

serverless-graphql-blog

> 编程语言
开源

一个不需要服务器的博客利用 GraphQL 提供仅包含 1 个端点的 REST API,使用 Serverless v0.5

779 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

一个不需要服务器的博客利用 GraphQL 提供仅包含 1 个端点的 REST API,使用 Serverless v0.5

Please note this project uses Serverless version 0.5

#serverless-graphql-blog

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.

  • Blog Post
  • Video Walkthrough
  • Email Updates
  • Gitter Chat Room
  • Serverless Documentation
  • Twitter

Enjoy,

Kevin Old (Twitter)

Install & Deploy

Make sure you have the most recent version of the Serverless Framework (0.5.x and higher) and you are using NodeV4 or greater.

bash
npm install serverless -g

Install this Serverless Project:

serverless project install serverless-graphql-blog

Install (top level) npm dependencies

bash
npm install

View project summary:

serverless dash summary

Deploy the project's Function and Endpoint:

serverless dash deploy

Querying with GraphiQL

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:

Sample GraphQL queries

List of author names

bash
curl -XPOST -d '{"query": "{ authors { name } }"}' /dev/blog/graphql

Results

{
  "data":{
    "authors":[
      {"name":"Kevin"}
    ]
  }
}

List of posts with id and title

bash
curl -XPOST -d '{"query": "{ posts { id, title } }"}' /dev/blog/graphql

Results

{
  "data": {
    "posts": [
      { "id":"1",
        "title":"First Post Title"
      }
    ]
  }
}

List of posts with id, title and nested author name

bash
curl -XPOST -d '{"query": "{ posts { id, title, author { name } } }"}' /dev/blog/graphql

Results

{
  "data": {
    "posts": [
      { "id":"1",
        "title":"First Post Title",
        "author":{
          "name":"Kevin"
        }
      }
    ]
  }
}

List of posts with post, author and comments information (for a Post with no comments, i.e. comments:[])

bash
curl -XPOST -d '{"query": "{ posts { id, title, author { id, name }, comments { id, content, author { name } } } }"}' /dev/blog/graphql

Results

{
  "data":{
    "posts":[
    {
      "id":"1",
        "title":"First Post Title",
        "author":{
          "id":"1",
          "name":"Kevin"
        },
        "comments":[]
    }
    ]
  }
}

Sample GraphQL Mutations

Create Post

bash
curl -XPOST -d '{"query": "mutation createNewPost { post: createPost (id: \"5\", title: \"Fifth post!\", bodyContent: \"Test content\", author: \"1\") { id, title } }"}' /dev/blog/graphql

Results

{
  "data":{
    "post":{
      "id":"5",
      "title":"Fifth post!"
    }
  }
}

Mutation Validation

Validations defined using graphql-custom-types in blog/lib/schema.js

bash
curl -XPOST -d '{"query": "mutation createNewPost { post: createPost (id: \"8\", title: \"123456789\", bodyContent: \"Test content 5\") { id, title } }"}' /dev/blog/graphql

Results

{
  "errors":[
  {
    "message":"Query error: String not long enough"}
  ]
}

Introspection Query

bash
curl -XPOST -d '{"query": "{__schema { queryType { name, fields { name, description} }}}"}' /dev/blog/graphql

Returns:

{
  "data":{
    "__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"
          }
        ]
      }
    }
  }
}

Issues· 8 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言