diff --git a/ReadMe.md b/ReadMe.md index ba91636c..aab7457b 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -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:** @@ -22,7 +32,7 @@ testing GraphQL queries. Follow the step by step guide below to run & test the G Screen Shot 2021-12-24 at 3 25 55 AM -### Getting Started +### Development Setup This project is created and tested with `Python 3.8.10` #### Create & activate virtual environment. diff --git a/scheduler/meeting_scheduler/mutations.py b/scheduler/meeting_scheduler/mutations.py index c8c09d07..ba799158 100644 --- a/scheduler/meeting_scheduler/mutations.py +++ b/scheduler/meeting_scheduler/mutations.py @@ -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: @@ -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() @@ -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() diff --git a/scheduler/meeting_scheduler/schema.py b/scheduler/meeting_scheduler/schema.py index 8201cf62..f86a8616 100644 --- a/scheduler/meeting_scheduler/schema.py +++ b/scheduler/meeting_scheduler/schema.py @@ -7,7 +7,7 @@ from .mutations import ( CreateBooking, CreateAvailability, DeleteAvailability, UpdateAvailability, ) -from .nodes import AvailabilityNode, BookingNode +from .types import AvailabilityType, BookingType class BookingQuery(graphene.ObjectType): @@ -15,7 +15,7 @@ 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), @@ -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" )) diff --git a/scheduler/meeting_scheduler/nodes.py b/scheduler/meeting_scheduler/types.py similarity index 91% rename from scheduler/meeting_scheduler/nodes.py rename to scheduler/meeting_scheduler/types.py index 6d230120..b8d586e8 100644 --- a/scheduler/meeting_scheduler/nodes.py +++ b/scheduler/meeting_scheduler/types.py @@ -1,7 +1,6 @@ """ Custom scheduler app nodes """ - import graphene from graphene_django import DjangoObjectType @@ -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() @@ -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) diff --git a/scheduler/settings.py b/scheduler/settings.py index cd2eb278..41bf8cba 100644 --- a/scheduler/settings.py +++ b/scheduler/settings.py @@ -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", @@ -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',