Skip to content

Latest commit

 

History

History
146 lines (133 loc) · 2.24 KB

README.md

File metadata and controls

146 lines (133 loc) · 2.24 KB

Sample Blogging APP using GraphQL and Compojure.

This project provides the sample blogging app to try GraphQL with Lacinia and Compojure in Clojure.

Prerequisites

To run this project, Java 8 and Leiningen needs to be installed.

Running

  1. Build the jar
lein uberjar
  1. Start the GraphQL server
java -jar target/blogging-graphql-0.1.0-standalone.jar
  1. Open GraphiQL IDE using http://localhost:7000/graphiql in your browser.

Using GraphiQL IDE

  1. Queries - Fetch Resources
{
  blogs: getBlogs {
    id
    author {
      id
    }
    comments {
      body
    }
  }
  authors: getAllAuthors {
    id
    email
    name
  }
}
  1. Mutations - Create or Update Resources
mutation {
  createAuthor(email: "random@mail.com", name: "Random Author") {
    id
    name
    email
  }
}
  1. Fragments - Reusable Units
fragment author_fields on author {
  id
  email
  name
}
fragment comment_fields on comment {
  id
  body
  author {
    ...author_fields
  }
}
fragment blog_fields on blog {
  id
  body
  author {
    ...author_fields
  }
  comments {
    ...comment_fields
  }
}
{
  getBlogs {
    ...blog_fields
  }
}
  1. Variables - Pass Dynamic Values to Queries.
    Pass below as query
query queries($blogID: String!, $first: Int!, $skip: Int!) {
  blog: getBlog(id: $blogID) {
    id
    comments(first: $first) {
      id
    }
  }
  authors: getAllAuthors {
    id
  }
  blogs: getBlogs(first: $first) {
    id
    comments {
      id
    }
  }
  comments: getComments(blogID: $blogID, first: $first, skip: $skip) {
    id
  }
}

and this as a query variables(change the blogID value accordingly)

{
  "blogID": "40bcb0b5-fe8b-4486-af4a-5f2f395ca75c",
  "first": 5,
  "skip": 0
}
  1. Schema Introspection - Inspect Schema
{
  __schema{
  types{
    name
    description
  }
  queryType{
    name
    description
    fields{
      name
      description
      }
    }
    mutationType{
      name
      description
      fields{
        name
        description
      }
    }
  }
}