Code Monkey home page Code Monkey logo

lorem's Introduction


Lorem is a fake GraphQL API for testing and prototyping similar to that of JSONPlaceholder

Getting started

Install dependencies

npm install

Running the server

npm run dev # running development server
# or
npm start # running the server on normal mode

Execute tests

npm test

Usage

Head over to http://localhost:8000/graphql to access GraphiQL


Sample Query

// get the album with id of 1
{
  albums(id: 1){ // *removing id parameter will return a list of all the albums
    userId
    id
    title
    photos{
      albumId
      id
      title
      url
      thumbnailUrl
    }
  }
}

Additional fields (see graphiql documentation explorer for more detailed info)

  • comments(id: Int): [Comment]
  • photos(id: Int): [Photo]
  • posts(id: Int): [Post]
  • todos(id: Int): [Todo]
  • users(id: Int): [User]

Sample Mutation

// adding a new todo item
mutation {
  addTodo(userId: 8, title: "Todo", completed: false) {
    userId
    id
    title
    completed
  }
}

Additional fields (see graphiql documentation explorer for more detailed info)

  • addAlbum(userId: Int!, title: String!): Album
  • addComment(postId: Int!, name: String!, email: String!, body: String!): Comment
  • addPhoto(albumId: Int!, title: String!, url: String!, thumbnailUrl: String): Photo
  • addPost(userId: Int!, title: String!, body: String!): Post
  • addUser(input: UserInput!): User

Making http requests

Using fetch

const query = `
{
  albums(id: 1){
    userId
    id
    title
    photos{
      albumId
      id
      title
      url
      thumbnailUrl
    }
  }
}
`
fetch('http://localhost:8000/graphql', {
    method: 'post',
    body: JSON.stringify({ query }),
    headers: { 'Content-Type': 'application/json' }
})
    .then(res => res.json())
    .then(data => console.log(data))
    .catch(err => console.log(err))

Using axios

const query = `
{
  albums(id: 1){
    userId
    id
    title
    photos{
      albumId
      id
      title
      url
      thumbnailUrl
    }
  }
}
`
axios.post('http://localhost:8000/graphql', { query })
    .then(res => console.log(res))
    .catch(err => console.log(err))

Useful Resources

License

MIT

lorem's People

Contributors

dependabot[bot] avatar iamkentleom avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.