Sunny’s GSOC Adventure: The Technical

In our previous post we saw the basic setup for our django project. If not you can read about it here. In this post we shall explore our graphql_api app in detail…

Note: We shall see the detailed explanation of the contents of each file in the subsequent blog posts. This post only gives a brief overview.

Files:

  1. urls.py: Contains the urls of graphql_api. There is only one url which handles requests and responses of our main GraphQL Schema.
  2. tests.py: Contains the unit and integration tests.
  3. tasks.py: We are using celery as our response is going to be asynchrous. Hence this file contains our celery tasks.
  4. schema.py: Contains our main GraphQL Schema.
  5. routing.py: Contains the web socket routes for our GraphQL Schema.

The other files are empty or not needed.

Folders:

  1. grapheneObjects: This is the only subfolder in our graphql_api app. It contains subschema details as folders which map to our database indices. Eg. Look at the subfolder “article”.

Files inside grapheneObjects subfolder:

  1. errors.py : Contains error and exception messages relevant to our API.
  2. constants.py : Contains constants used by our code.
  3. helpers.py : Contains functions which are used by resolvers to fetch data.
  4. commonFieldObjects.py : Certain fields have similar structure (eg. a field with “text” and “ontologyTerms” subfields. Hence this file contains the common field graphene objects (ObjectType).
  5. commonInputFieldObjects.py: Similar to commonFieldObjects.py above except instead of having graphene objects (ObjectType) it has graphene input objects (InputObjectType).

Subfolders inside grapheneObjects subfolder:

Every subfolder inside grapheneObjects subfolder maps to an index. Also all these subfolders have the same file structure. Hence let us take an example of article subfolder.

Let us look at what the files and folders inside this folder represent:

Files inside article subfolder:

  1. schema.py : It contains GraphQL schema for the particular index (In this case ArticleSchema). Along with ArticleSchema it also includes the classes ArticleNode and ArticleConnection (as we are using Relay specification).
  2. fieldObjects.py : Contains the definition for all the fields for the article index which are of ObjectType.
  3. dataloader.py : It contains the dataloader which can help to batch and cache DB results, so that performance can be optimized. This file contains the dataloader instance specific to article index.
  4. arguments -> filter.py : Inside the sole subfolder arguments there is only one file called filter.py. This file includes the definition of all the arguments of the ArticleSchema.

Next up : Fetching single document.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store