Skip to content

Hivemind Backend Overview

Joe Peterson edited this page Sep 7, 2021 · 14 revisions

This Wiki should provide information to the Hivemind frontend team sufficient to clarify the expected structure of requests, as well as the current response structure.

All requests should be POST requests directed to https://hivemind-backend.herokuapp.com/graphql

Queries

Get all posts

Sample request query

query {
  posts {
    id
    title
    imageUrls
    upvotes
    downvotes
    createdAt
    user {
      id
      username
      avatar
    }
  }
}

Sample response

{
  "data": {
    "posts": [
      {
        "id": "58",
        "title": "Charnel tentacles dank blasphemous fungus gibbous gibbering stench.",
        "imageUrls": [
          "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBKZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--49f6156925b69df42934d2004286f6f2078b6a0b/test-image1.jpg"
        ],
        "upvotes": 7,
        "downvotes": 10,
        "createdAt": "2021-09-01T23:31:31Z",
        "user": {
          "id": "21",
          "username": "Wilibald Bolger",
          "avatar": "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--3d0ed00eaf7addd2df76acd5b397be3154442de2/test-image2.jpg"
        }
      },
      {
        "id": "57",
        "title": "Non-euclidean fainted abnormal gambrel unutterable madness unmentionable stench manuscript.",
        "imageUrls": [
          "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBKUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--e9bb9964258bdfe18f2167c68ee2aca1fc2f9ec4/test-image1.jpg"
        ],
        "upvotes": 2,
        "downvotes": 7,
        "createdAt": "2021-09-01T23:31:31Z",
        "user": {
          "id": "21",
          "username": "Wilibald Bolger",
          "avatar": "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--3d0ed00eaf7addd2df76acd5b397be3154442de2/test-image2.jpg"
        }
      },
      {
        "id": "56",
        "title": "Unmentionable antediluvian noisome mortal unnamable furtive.",
        "imageUrls": [
          "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBKQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--e7419be05c2ec07663b1806b4feefd824db60462/test-image1.jpg"
        ],
        "upvotes": 4,
        "downvotes": 10,
        "createdAt": "2021-09-01T23:31:31Z",
        "user": {
          "id": "21",
          "username": "Wilibald Bolger",
          "avatar": "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--3d0ed00eaf7addd2df76acd5b397be3154442de2/test-image2.jpg"
        }
      },
      {
        "id": "55",
        "title": "Spectral eldritch daemoniac comprehension gibbous ululate mortal.",
        "imageUrls": [
          "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBJUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--21d97e79df26d73fe9e2d072dcf65ad3771e2777/test-image1.jpg",
          "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBJZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--02ed9639c894e2256582ed746a5807b9e81640ca/test-image2.jpg",
          "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBJdz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--993725f650c6aa816d08e548a68f43eb523704c5/test-image3.jpg"
        ],
        "upvotes": 4,
        "downvotes": 3,
        "createdAt": "2021-09-01T23:31:30Z",
        "user": {
          "id": "21",
          "username": "Wilibald Bolger",
          "avatar": "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--3d0ed00eaf7addd2df76acd5b397be3154442de2/test-image2.jpg"
        }
      }
    ]
  }
}

Get a specific user's posts

Sample request query

query {
  userPosts(userId: 14) {
    id
    title
    imageUrls
    upvotes
    downvotes
    createdAt
    user {
      id
      username
      avatar
    }
  }
}

Sample response

{
  "data": {
    "userPosts": [
      {
        "id": "60",
        "title": "Non-euclidean lurk hideous swarthy ululate foetid eldritch amorphous squamous.",
        "imageUrls": [
          "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBLQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--38da58501535f6853c4002a2db6fc41ab09b7a32/test-image1.jpg"
        ],
        "upvotes": 5,
        "downvotes": 7,
        "createdAt": "2021-09-01T23:31:31Z",
        "user": {
          "id": "21",
          "username": "Wilibald Bolger",
          "avatar": "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--3d0ed00eaf7addd2df76acd5b397be3154442de2/test-image2.jpg"
        }
      },
      {
        "id": "59",
        "title": "Furtive effulgence cat amorphous.",
        "imageUrls": [
          "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBKdz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--4026d6a520e3a63d6b344d1e3d81aa54ba9c05c1/test-image1.jpg"
        ],
        "upvotes": 5,
        "downvotes": 3,
        "createdAt": "2021-09-01T23:31:31Z",
        "user": {
          "id": "21",
          "username": "Wilibald Bolger",
          "avatar": "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--3d0ed00eaf7addd2df76acd5b397be3154442de2/test-image2.jpg"
        }
      }
    ]
  }
}

Get post details

Sample request query

query {
  post(id: 125) {
    id
    title
    description
    imageUrls
    upvotes
    downvotes
    user {
      id
      username
      avatar
    }
    comments {
      id
      content
      upvotes
      downvotes
      user {
        id
        username
        avatar
      }
    }
  }
}

Sample response

{
  "data": {
    "post": {
      "id": "105",
      "title": "Hideous stench gibbering decadent mortal lurk.",
      "description": "Fainted tenebrous decadent effulgence. Iridescence unutterable immemorial. Gibbering tentacles daemoniac unnamable unmentionable gambrel. Stench effulgence tentacles.",
      "imageUrls": [
        "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBldz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--496b761a31307334900d6ad71f3554d16cb1ef75/test-image5.jpg"
      ],
      "upvotes": 1,
      "downvotes": 6,
      "user": {
        "id": "32",
        "username": "Sagroth",
        "avatar": "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBiUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--c42ed047cc433842922d489f6e99a68cb8577604/test-image4.jpg"
      },
      "comments": [
        {
          "id": "284",
          "content": "Repression makes a religion flourish.",
          "upvotes": 5,
          "downvotes": 9,
          "user": {
            "id": "35",
            "username": "Ar-Sakalthôr",
            "avatar": "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBjQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--8ead6b14acd6ea455aa401abe850e27a12abc124/test-image4.jpg"
          }
        },
        {
          "id": "285",
          "content": "They tried and died.",
          "upvotes": 10,
          "downvotes": 7,
          "user": {
            "id": "35",
            "username": "Ar-Sakalthôr",
            "avatar": "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBjQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--8ead6b14acd6ea455aa401abe850e27a12abc124/test-image4.jpg"
          }
        }
      ]
    }
  }
}

Get user details

Sample request query

query {
  user(id: 1) {
    id
    username
    region
    biography
    avatar
  }
}

Sample response

{
  "data": {
    "user": {
      "id": "1",
      "username": "Caranthir",
      "region": "Isle of Meneltarma",
      "biography": "Sing all ye joyful!",
      "avatar": "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBCZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--096e8e25879c68232c5fada3f1364db0b081ad7c/test-image4.jpg"
      }
   }
}

Mutations

Create a direct upload

Sample request mutation

mutation createDirectUpload {
  createDirectUpload(input: {
    attributes: {
      filename: "image.jpg"
      contentType: "image/jpeg"
      checksum: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAB9QAAAPg..."
      byteSize: 2019
    }
  } ) { 
    directUpload {
      signedBlobId
    }
  }
}

Sample response

{
  "data": {
    "createDirectUpload": {
      "directUpload": {
        "signedBlobId": "eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBWXM9IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--c2f1caa750c8523d127dd239987ce20656499bd3"
      }
    }
  }
}

Create a new post

Sample request mutation

mutation createPost($input: CreatePostInput!) {
  createPost(
    input: $input
  ) {
    id
    title
    description
    imageUrls
    upvotes
    downvotes
    createdAt
    updatedAt
    user {
      id
      username
      avatar
    }   
  }
}

And the $input variable should look like (JSON):

{"input": {
  "title": "Help! A swarm!",
  "description": "Holy swarmoly, I could use a hand here!",
  "imageIds": ["FSDDsknfaldA235RFsbfwgd08", "NNEDJDKsdf362DSFKJBSDnkdjfhsdf934"],
  "userId": 14
}}

NOTE: The imageIds here will need to be an array of signed_ids that we've sent back from the createDirectUpload mutation

Sample response

{
  "data": {
    "createPost": {
      "id": "32",
      "title": "Help! A swarm!",
      "description": "Holy swarmoly, I could use a hand here!",
      "imageUrls": [
        "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBldz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--496b761a31307334900d6ad71f3554d16cb1ef75/test-image5.jpg",
        "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBldz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--496b761a31307334900d6ad71f3554d16cb1ef75/test-image5.jpg"
      ],
      "upvotes": null,
      "downvotes": null,
      "createdAt": "2021-08-28T21:10:57Z",
      "updatedAt": "2021-08-28T21:10:57Z",
      "user": {
        "id": "14",
        "username": "Halfred Greenhand",
        "avatar": "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBldz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--496b761a31307334900d6ad71f3554d16cb1ef75/test-image5.jpg"
      }
    }
  }
}

Create a new comment on a post

Sample request mutation

mutation createComment{
  createComment(input:{
    content: "Bzzzz I'm a bee!"
    userId: 1
    postId: 1
    }
  ){
    content
    upvotes
    downvotes
    user {
      id
      username
      avatar
    }
  }
}

Sample response

{
  "data": {
    "createComment": {
      "content": "Bzzzz I'm a bee!",
      "upvotes": null,
      "downvotes": null,
      "user": {
        "id": "1",
        "username": "Moro Burrows",
        "avatar": "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBldz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--496b761a31307334900d6ad71f3554d16cb1ef75/test-image5.jpg"
      }
    }
  }
}

Create a new user

Sample request mutation

mutation createUser {
  createUser(input: {
    username: "testusername",
  }) {
    id
    username
  }
}

Sample response

{
  "data": {
    "createUser": {
      "id": "1",
      "username": "testusername"
    }
  }
}