npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

serverless-graphql-blog

v0.0.2

Published

A Serverless GraphQL blog.

Downloads

8

Readme

Serverless GraphQL Blog AWS Lambda API Gateway

serverless

#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.

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.

npm install serverless -g

Install this Serverless Project:

serverless project install serverless-graphql-blog

Install (top level) npm dependencies

npm install

View project summary:

serverless dash summary

Deploy the project's Function and Endpoint:

serverless dash deploy

Serverless GraphQL Blog Video Walkthrough

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:

GraphiQL.app demo

Sample GraphQL queries

List of author names

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

Results

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

List of posts with id and title

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

Results

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

List of posts with id, title and nested author name

curl -XPOST -d '{"query": "{ posts { id, title, author { name } } }"}' <endpoint>/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:[])

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

Results

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

Sample GraphQL Mutations

Create Post

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

Results

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

Mutation Validation

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

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

Results

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

Introspection Query

curl -XPOST -d '{"query": "{__schema { queryType { name, fields { name, description} }}}"}' <endpoint>/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"
          }
        ]
      }
    }
  }
}