dlebee / post-api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A JSON Placeholder GraphQL API

A simple GraphQL endpoint wrapping the AWESOME JSONPlaceholder, a fake online REST API for testing and prototyping

json-placeholder-graphql

This codebase and free tier Heroku deplyment offers the GraphiQL ui as a simple sandbox to try all of the specific GET queries offered by JSONPlaceholder. The "Good Stuff" is in the Schema.js file.

Example Queries, (Only GET has been implemented)

All Graphql queries are entered into the GraphiQL ui:

{
  post(id:1){
    userId
    id
    title
    body
  }
}
{
  comment(id: 1) {
    postId
    id
    name
    email
    body
  }
}
{
  album(id: 1) {
    userId
    id
    title
  }
}
{
  photo(id: 1) {
    albumId
    id
    title
    url
    thumbnailUrl
  }
}
{
  todo(id: 1) {
    userId
    id
    title
    completed
  }
}
{
  user(id: 1) {
    id
    username
    email
    phone
    website
  }
}

Here's the list of available nested routes:

{
  comments(postId: 1) {
    postId
    id
    name
    email
    body
  }
}
  • (also experiment tunneling down into post and user, revealing the possibilities via a GraphQL Api...)
{
  comments(postId: 1) {
    postId
    post {
      title
      user {
        name
      }
    }
    id
    name
    email
    body
  }
}
{
  photos(albumId:1){
    albumId
    id
    title
    url
    thumbnailUrl
  }  
}
{
  albums(userId: 1) {
    userId
    id
    title
  }
}
{
  todos(userId: 1) {
    userId
    id
    title
    completed
  }
}
  • (Experiment with completed criteria and accessing the User data as well, GraphQL good stuff)
{
  todos(userId: 1,completed:true) {
    user{
      name
    }
    id
    title
    completed
  }
}
{
  posts(userId: 1) {
    userId
    id
    title
    body
  }
}

//TODO

This is intended to be an available Sandbox and learning tool, built off of the existing awesome learning tool, JSON Placeholder. Improvements would be to:

  • Add front end to support an ad, to bump up the Heroku service level from the free tier
  • Embed the GraphiQL ui in an iframe into the front end.
  • Inject sample queries via frontend UI
  • More Examples, along the lines of: https://www.howtographql.com/advanced/2-more-graphql-concepts/
  • Implement the POST, PUT, PATCH, DELETE Restful API/ GraphQL mutations.
  • Refactor the Schema into sub schemas

About

License:MIT License


Languages

Language:JavaScript 100.0%