Skip to content

Book Rating Django application. GraphQL API with User Auth and Likes

Notifications You must be signed in to change notification settings

stacykutyepov/CFG-GraphQL-API-books

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Run Backend

pipenv shell
pipenv install
cd app
python manage.py runserver

Execute Queries and Mutations:

  1. go to http://localhost:8000/graphql/
  2. explore the "Docs" on the right (Queries, Mutations)
  3. Write your first query:

QUERIS

-> GET BOOKS

GET BOOKS:

query getBooks {
  books {
    id
    author
    description
    url
 }
}

-> CREATE A USER & LOG IN

CREATE A NEW USER:

mutation {
  createUser(email: "VALID_EMAIL", password: "VALID_PASSWORD", username: "USERNAME"){
    user {
      id
      email
      username
    }
  }
}

example -> createUser(email: "[email protected]", password: "1234567890", username: "test_123")

After creating a user profile, you can login

1. GET THE AUTH TOKEN

Enter your username and password you've just provided. After executing the query copy the auth token

mutation {
  tokenAuth(username:"USERNAME", password: "VALID_PASSWORD") {
    token
  }
}

2. LOG IN

Enter your Auth Token in REQUEST HEADERS TAB app-preview

{
"Authorization": "JWT {YOUR TOKEN}"
}

3. GET INFO ABOUT THE USER YOU HAVE CREATED:

{
  me {
    id
    username
    email
  }
}


BOOKS QUERIES AND MUTATIONS

CREATE A BOOK

mutation {
  createBook(author:"cool author", description: "some desct", url: "9599", title: "titlre"){
    book {
      id
      title
      description
      author
      url
      createdAt
    }
  }
}

UPDATE A BOOK

mutation {
  updateBook(bookId: 8, author:"Unknown Author"){
    book{
      id
      author
      description
    }
  }
}

DELETE A BOOK

mutation {
  deleteBook(bookId: 8){
    bookId
  }
}

LIKE A BOOK

mutation {
  createLike(bookId: 8) {
   user {
    id
    username
  }
  }
}

CHECK HOW MANY LIKES ARE ON BOOKS

query {
  books {
    id
    title
    description
    likes {
      id
      user {
        id
        username
      }
    }
  }
}

SEARCH A BOOK

query{
  books(search: "python") {
    id
    title
    author
    description
  }
}

About

Book Rating Django application. GraphQL API with User Auth and Likes

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages