Skip to content

Commit

Permalink
refactor: Sevaral refactoring in the app.
Browse files Browse the repository at this point in the history
1. Use Django sites.
2. Use django site model in the admin
3. Update docs.
  • Loading branch information
awaisdar001 committed Jan 17, 2022
1 parent 9de1c65 commit 98fa6e8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
24 changes: 17 additions & 7 deletions ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# Django Graphene (GraphQL) API
# Schedule Booking GraphQL API

Schedule Booking app is powered by a GraphQL API. GraphQL is a query language that allows clients to talk to an API server. Unlike REST, it gives the client control over how much or how little data they want to request about each object and allows relations within the object graph to be traversed easily.

To learn more about GraphQL language and its concepts, see the official [GraphQL website](https://graphql.org/).

The API endpoint is available at `/graphql/` and requires queries to be submitted using HTTP `POST` method and the `application/json` content type.

The API provides simple CURD operation. The application has simple data flow where
authenticated users can create their availabilities slots and other users can
book these slots. Other uses can also see all the bookings of a user.
CURD operations are provided on authenticated availability endpoint using `JWT` authentication
mechanism. API provides both types of operations:

* Public (search & book slots in availability.)
* Private (create/update/delete availabilities)

This is simple application which provided CURD operation. The application has simple
data flow where authenticated users can create their availabilities slots and
other users can book these slots. Other uses can also see all the bookings of a user.
CURD ops are provided on authenticated availability endpoint using `JWT` authentication
mechanism.

**Project Requirements:**

Expand All @@ -22,7 +32,7 @@ testing GraphQL queries. Follow the step by step guide below to run & test the G

<img width="1371" alt="Screen Shot 2021-12-24 at 3 25 55 AM" src="https://user-images.githubusercontent.com/4252738/147296260-1f2f256b-3cb7-4fe7-88b3-bc6121cfe7f5.png">

### Getting Started
### Development Setup
This project is created and tested with `Python 3.8.10`

#### Create & activate virtual environment.
Expand Down
8 changes: 4 additions & 4 deletions scheduler/meeting_scheduler/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from .decorators import user_required
from .enums import Description
from .models import Booking, UserModel as User, Availability
from .nodes import BookingNode, AvailabilityNode
from .types import BookingType, AvailabilityType


class CreateBooking(graphene.Mutation):
"""
OTD mutation class for creating bookings with users.
"""
booking = graphene.Field(BookingNode)
booking = graphene.Field(BookingType)
success = graphene.Boolean()

class Arguments:
Expand Down Expand Up @@ -50,7 +50,7 @@ class CreateAvailability(graphene.Mutation):
"""
OTD mutation class for creating user availabilities.
"""
availability = graphene.Field(AvailabilityNode)
availability = graphene.Field(AvailabilityType)
success = graphene.Boolean()
error = graphene.String()

Expand Down Expand Up @@ -78,7 +78,7 @@ class UpdateAvailability(graphene.Mutation):
"""
OTD mutation class for updating user availabilities.
"""
availability = graphene.Field(AvailabilityNode)
availability = graphene.Field(AvailabilityType)
success = graphene.Boolean()
error = graphene.String()

Expand Down
8 changes: 4 additions & 4 deletions scheduler/meeting_scheduler/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
from .mutations import (
CreateBooking, CreateAvailability, DeleteAvailability, UpdateAvailability,
)
from .nodes import AvailabilityNode, BookingNode
from .types import AvailabilityType, BookingType


class BookingQuery(graphene.ObjectType):
"""
Describes entry point for fields to *read* data in the booking schema.
"""
bookings_by_user = graphene.List(
BookingNode,
BookingType,
username=graphene.String(required=True),
# Alternative
# username=graphene.Argument(graphene.String, description="Pass username of the user.", required=True),
Expand All @@ -31,8 +31,8 @@ class AvailabilityQuery(UserQuery, graphene.ObjectType):
"""
Describes entry point for fields to *read* data in the availability schema.
"""
availabilities = graphene.List(AvailabilityNode)
availability = graphene.Field(AvailabilityNode, id=graphene.Int(
availabilities = graphene.List(AvailabilityType)
availability = graphene.Field(AvailabilityType, id=graphene.Int(
required=True, description="ID of a availability to view"
))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Custom scheduler app nodes
"""

import graphene
from graphene_django import DjangoObjectType

Expand All @@ -16,7 +15,7 @@ class Meta:
fields = ("id", "username", "email")


class AvailabilityNode(DjangoObjectType):
class AvailabilityType(DjangoObjectType):
"""Availability Object Type Definition"""
id = graphene.ID()
interval_mints = graphene.String()
Expand All @@ -31,7 +30,7 @@ def resolve_interval_mints(cls, availability, info):
return availability.get_interval_mints_display()


class BookingNode(DjangoObjectType):
class BookingType(DjangoObjectType):
"""Booking Object Type Definition"""
id = graphene.ID()
user = graphene.Field(UserType)
Expand Down
4 changes: 4 additions & 0 deletions scheduler/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@
'graphql_jwt.refresh_token.apps.RefreshTokenConfig',
'graphql_auth',
'django_filters',
'django.contrib.sites',
]

SITE_ID = 1

GRAPHENE = {
"MIDDLEWARE": [
"graphql_jwt.middleware.JSONWebTokenMiddleware",
Expand All @@ -65,6 +68,7 @@
}
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sites.middleware.CurrentSiteMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand Down

0 comments on commit 98fa6e8

Please sign in to comment.