Install Necessary Dependencies
ican2 is a Rails GraphQL API serving queries for a PostgreSQL database comprised of users who can have connections to each other in the form of mentee to mentor. These connections are also able to have conversations and messages sent between the two users.
- Rails (5.2.4)
- GraphQL (1.10.3)
- RSpec (3.9.0
- PostgreSQL (11.5)
BackEnd Repo: here
FrontEnd Repo: here
BackEnd Heroku : Find our heroku app here
FrontEnd Heroku : Find our front end app here
Note: This project is built on Rails. For more information about installing Rails, see here.
Instal necessary dependencies using
bundle install
To generate rspec files:
rails generate rspec:install
This project uses a PostgreSQL database. Database names are specified in the database.yml To create, migrate and seed run the following commands:
rails db:create
rails db:migrate
rails db:seed
To run locally, simply use the command rails server
or rails s
for short.
With rspec installed the simply command rspec
will run the entire test suite
Tests can be run singularly by running rspec
followed by the test file path
Create a heroku app with a PostgreSQL add-on. Set your heroku remote to your heroku app.
git push heroku master
heroku run rake db:migrate
heroku run rake db:seed
heroku open
Being a grahpql api we have one endpoint to serve all requests, that endpoint being:
/api/v1/graphql
Get a single user with name and email attributes:
POST request to /api/v1/graphql
Headers:
{ 'Content-Type': 'application/json' }
Body:
JSON.stringify({
query: " query($email: String!) {\n users(email: $email) {\n name\n email\n mentor\n profile {\n gender\n aboutMe\n image\n fieldOfInterest\n }\n mentorProfile {\n fieldOfKnowledge\n experienceLevel\n workDayQuestion\n enjoymentQuestion\n teachingPointsQuestion\n adviceQuestion\n}\n location {\n city\n state\n }\n }\n }",
variables: {"email":"[email protected]"}
})
Response:
{
"data": {
"users": {
"name": "Kayla",
"email": "[email protected]",
"mentor": true,
"profile": {
"gender": "She/Her",
"aboutMe": "I want to learn more about software development.",
"image": "https://i.imgur.com/xZ6ZMc5.jpg",
"fieldOfInterest": "Software Development"
},
"mentorProfile": {
"fieldOfKnowledge": "Software Development",
"experienceLevel": "Intermediate",
"workDayQuestion": "My typical day is awesome!",
"enjoymentQuestion": "I enjoy teaching and sharing my knowledge!",
"teachingPointsQuestion": "I want to teach React Native!",
"adviceQuestion": "Just keep swimming!"
},
"location": {
"city": "Denver",
"state": "CO"
}
}
}
}
Get all mentors with name city and state:
POST request to /api/v1/graphql
Headers:
{ 'Content-Type': 'application/json' }
Body:
JSON.stringify({
query: " query{\n mentors {\n name\n email\n }\n }\n \n\n",
variables: {}
})
Response:
{
"data": {
"mentors": [
{
"name": "Mary",
"email": "[email protected]",
"location": {
"city": "Boulder",
"state": "CO"
}
},
{
"name": "Kayla",
"email": "[email protected]",
"location": {
"city": "Denver",
"state": "CO"
}
},
{
"name": "Ben",
"email": "[email protected]",
"location": {
"city": "Golden",
"state": "CO"
}
},
{
"name": "Alice",
"email": "[email protected]",
"location": {
"city": "New York",
"state": "NY"
}
},
{
"name": "John",
"email": "[email protected]",
"location": {
"city": "Brooklyn",
"state": "NY"
}
},
{
"name": "Ryan",
"email": "[email protected]",
"location": {
"city": "Bronx",
"state": "NY"
}
},
{
"name": "Michael",
"email": "[email protected]",
"location": {
"city": "Los Angeles",
"state": "CA"
}
},
{
"name": "Heather",
"email": "[email protected]",
"location": {
"city": "Los Angeles",
"state": "CA"
}
},
{
"name": "Trisha",
"email": "[email protected]",
"location": {
"city": "Santa Monica",
"state": "CA"
}
},
{
"name": "Fenton",
"email": "[email protected]",
"location": {
"city": "Torrance",
"state": "CA"
}
},
{
"name": "Scott",
"email": "[email protected]",
"location": {
"city": "Miami",
"state": "FL"
}
},
{
"name": "Dustin",
"email": "[email protected]",
"location": {
"city": "Hialeah",
"state": "FL"
}
},
{
"name": "Allie",
"email": "[email protected]",
"location": {
"city": "Homestead",
"state": "FL"
}
},
{
"name": "David",
"email": "[email protected]",
"location": {
"city": "Austin",
"state": "TX"
}
},
{
"name": "Brian",
"email": "[email protected]",
"location": {
"city": "San Antonio",
"state": "TX"
}
},
{
"name": "Raisa",
"email": "[email protected]",
"location": {
"city": "San Marcos",
"state": "TX"
}
},
{
"name": "mmmvmvm",
"email": "[email protected]",
"location": {
"city": "Alamosa",
"state": "Colorado"
}
},
{
"name": "bruce",
"email": "[email protected]",
"location": {
"city": "Abbeville",
"state": "Alabama"
}
},
{
"name": "WhittiB",
"email": "[email protected]",
"location": {
"city": "Avon-by-the-Sea",
"state": "New Jersey"
}
},
{
"name": "Pepper",
"email": "[email protected]",
"location": {
"city": "Aetna",
"state": "Arkansas"
}
},
{
"name": "Pep",
"email": "[email protected]",
"location": {
"city": "A and F Trailer Park",
"state": "Arizona"
}
},
{
"name": "name",
"email": "email@.",
"location": {
"city": "Acebedo",
"state": "California"
}
},
{
"name": "avas",
"email": "dva",
"location": {
"city": "Abco",
"state": "Arkansas"
}
},
{
"name": "Travis",
"email": "[email protected]",
"location": {
"city": "Byers",
"state": "Colorado"
}
}
]
}
}
Get all conversations by user_id:
POST request to /api/v1/graphql
Headers:
{ 'Content-Type': 'application/json' }
Body:
{ "query": "conversations("user_id")": { "id" "senderId" "recipientId" } }
Get a single conversation by sender and recipient id:
POST request to /api/v1/graphql
Headers:
{ 'Content-Type': 'application/json' }
Body:
{ "query": "messages("sender", "recipient")": { "body" "read"} }
Create a user by entering wanted profile information:
POST request to /api/v1/graphql
Headers:
{ 'Content-Type': 'application/json' }
Body:
mutation {
createUser(input: {
name: "Matt",
email: "[email protected]"
passwordDigest: "lalala"
mentor: true
gender: "Male"
fieldOfInterest: "Software"
aboutMe: "I love vegetables"
image: "this is an image string"
city: "Denver"
state: "CO"
zipCode: "90210"
fieldOfKnowledge: "Software Development"
experienceLevel: "Intermediate"
workDayQuestion: "My typical day is awesome!"
enjoymentQuestion: "I enjoy teaching and sharing my knowledge!"
teachingPointsQuestion: "I want to teach React Native!"
adviceQuestion: "Just keep swimming!"
}) {
user {
id
name
email
}
errors
}
}
Response:
{
"data": {
"createUser": {
"user": {
"id": 45,
"name": "Matt",
"email": "[email protected]",
"mentor": true,
"profile": {
"gender": "Male",
"aboutMe": "I love vegetables",
"image": "this is an image string",
"fieldOfInterest": "Software"
},
"mentorProfile": {
"fieldOfKnowledge": "Software Development",
"experienceLevel": "Intermediate",
"workDayQuestion": "My typical day is awesome!",
"enjoymentQuestion": "I enjoy teaching and sharing my knowledge!",
"teachingPointsQuestion": "I want to teach React Native!",
"adviceQuestion": "Just keep swimming!"
},
"location": {
"city": "Denver",
"state": "CO"
}
},
"errors": []
}
}
}
Create a connection between mentor and mentee by their emails:
POST request to /api/v1/graphql
Headers:
{ 'Content-Type': 'application/json' }
Body:
{ "query": "createConnection("menteeEmail", "mentorEmail")": { "message"} }
Create a conversation and message between mentor and mentee by their ids:
POST request to /api/v1/graphql
Headers:
{ 'Content-Type': 'application/json' }
Body:
{ "query": "createConversation("senderId", "recipientId")": { "message"} }
Update a user by modifying their profile data:
POST request to /api/v1/graphql
Headers:
{ 'Content-Type': 'application/json' }
Body:
{ "query": "updateUser("city", "state", "zipCode")": { "city" "state" "zip"} }
Update a message from unread to read:
POST request to /api/v1/graphql
Headers:
{ 'Content-Type': 'application/json' }
Body:
{ "query": "updateMessage("read")": { "read" } }
Destroy a user by their emails:
POST request to /api/v1/graphql
Headers:
{ 'Content-Type': 'application/json' }
Body:
{ "query": "destroyUser("email")": { "message" } }
Destroy a connection by mentor and mentee email:
POST request to /api/v1/graphql
Headers:
{ 'Content-Type': 'application/json' }
Body:
{ "query": "destroyConnection("menteeEmail" "mentorEmail")": { "message" } }
Destroy a message by the message id:
POST request to /api/v1/graphql
Headers:
{ 'Content-Type': 'application/json' }
Body:
{ "query": "destroyMessage("id")": { "message" } }
Get all conversations for one user
POST request to /api/v1/graphql
Headers:
{ 'Content-Type': 'application/json' }
Body:
query($userId: String!) {
conversations(userId: $userId){
id
senderId
recipientId
}
}
Response:
{
"data": {
"conversations": [
{
"id": 1,
"senderId": 1,
"recipientId": 6
},
{
"id": 2,
"senderId": 1,
"recipientId": 7
},
{
"id": 3,
"senderId": 1,
"recipientId": 8
},
{
"id": 5,
"senderId": 1,
"recipientId": 2
}
]
}
}
Get all messages between two users
POST request to /api/v1/graphql
Headers:
{ 'Content-Type': 'application/json' }
Body:
query($sender: String!, $recipient: String!) {
messages(sender: $sender, recipient: $recipient){
body
read
}
}
Response:
{
"data": {
"messages": [
{
"body": "Hello. Let's start a conversation!",
"read": false
},
{
"body": "Hello, happy to chat!",
"read": false
},
{
"body": "Do you like music?",
"read": false
},
{
"body": "I LOVE MUSIC!!",
"read": false
}
]
}
}
Mary Lang @mcat56
Christopher Kelling @cjkelling