skhaz / graphqlgram

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

To run, just run

make run

Wait some time while docker is pulling the image of mongodb and building the container.

After this step, open the GraphQL Playground at: http://localhost:3000/graphql

First of all, create an user:

mutation {
  createUser(
    data: { email: "user@example.com", password: "secret", name: "User", image: "https://github.com/user.png" }
  ) {
    email
    name
    image
  }
}

Then, do the logIn:

mutation {
  logIn(email: "user@example.com", password: "secret")
}

You should receive a token as result of the call, grab the token and on the bottom of the playgraoud there is a button named "HTTP Headers", paste the token as the following

{
  "Authorization": "your token here"
}

With the HTTP headers set, try to create a new Post:

mutation {
  createPost(data: { image: "https://bucket/image.jpg", title: "Some image", description: "Some description" }) {
    image
    title
    description
    author
  }
}

Listing all Posts is simple, just do:

query {
  allPosts {
    id
    image
    title
    description
    author
  }
}

Remember, you have to set the HTTP headers with the token in order to see the posts.

Updating a post that user owns:

mutation {
  updatePost(
    id: "post-id"
    data: { image: "https://bucket/image2.jpg", title: "Updated title", description: "Updated description" }
  ) {
    id
    image
    title
    description
    author
  }
}

Deleting a post:

mutation {
  deletePost(id: "post-id")
}

About


Languages

Language:TypeScript 83.0%Language:JavaScript 7.5%Language:Dockerfile 4.6%Language:Makefile 4.1%Language:Shell 0.9%