Welcome to the backend repository for Unrated, a whiskey rating application developed by Unrated Limited Unlimited Ltd.
The backend tries to offer a robust platform for whiskey enthusiasts to review, and discover whiskeys based on a wide range of criteria.
The backend is being hosted at:
https://api.unrated.no/
Clone the repository:
git clone https://github.com/Unrated-Limited-Unlimited/ua-backend.git
cd ua-backend
Build the project:
./gradlew build
Run the application:
./gradlew run
The backend application can then be accessed via:
http://localhost:8000/
https://api.unrated.no/
http://localhost:8000/graphiql
https://api.unrated.no/graphiql
Refer to schema.graphqls
file in src/main/resources/
for the full GraphQL schema,
which includes definitions for queries, mutations, types, and inputs required for interacting with the application.
Or use the playground as stated above.
See OpenAPI documentation for further details. Overview:
Image Upload:
/img/profile
(uploads a profile image for the authenticated user)/img/whiskey/{id}
(uploads an image for a specific whiskey, admin access required)User Authentication:
/login
(Login user using username and password to generate a JWT token)/logout
(invalidates all created refresh tokens)/register
(registers a new user with email, username, and password)GraphQL
/graphql
(See schema.graphqls
or /graphiql
playground for details) Here are some example GraphQL queries and mutations:
# Retrieve a list of all whiskey ratings by a specific user
query {
getUser(name: "Jeff") {
ratings {
title
body
score
}
}
}
# Create a new user and return id, name and email
mutation {
createUser(user: {
name: "NewUser",
email: "newuser@example.com",
password: "SecureNP#x&t@4S2Password#!"
}) {
id
name
email
}
}
We use JWT tokens for authentication.
JWT tokens are stateless and are returned as set-cookie on /login
.
Bearer JWT tokens are also accepted.
All the mutations and query functions are first defined in schema.graphqls
.
The schema is parsed in GraphQLFactory
, where the definitions are linked to different fetcher functions.
The fetcher functions return different Jpa model objects, were the DataFetcher maps every field value of the object,
to the return type of the query/mutation function defined in the schema.
Example:
getWhiskey(id: ID!) : Whiskey
is first defined in schema.graphqls
.WhiskeyFetcher::getWhiskey()
inside GraphQLFactory
.DataFetcher<Whiskey>
.schema.graphqls
does not have a field called password for type UserData.)