Sunny’s GSOC Adventure: The Technical

Fetching Single Document

Sunny Tarawade

--

Prerequisites: Kindly make sure that you have read the blog explaining basic data fetching in our API. You can read it here.

We will continue using article index to explain the code.

  1. Fetching single document: As soon as our ArticleSchema receives a request from query about fetching a single document (through article query), our resolve_article resolver will call resolve_single_article which will call resolve_single_document helper with appropriate arguments.

Note: resolve_some_articles uses DataLoader. Currently optimisation using DataLoader is work in progress and hence documentation for it will be written later.

Note: Only the functions which are defined inside a Schema and which start with “resolve” are resolver functions.

resolve_article: This is our resolver function for fetching single a single document (here document of article index). It takes the argument “id” whose value is a string which specifies which document to fetch. We don’t do any data fetching here, because resolver is supposed to be a pure function. Hence it calls resolve_single_article function.

resolve_single_article:

This is a function which calls the helper fuction resolve_single_document and returns the fetched single (article) document to the resolver. To resolve_single_document helper function, we pass 3 arguments. First: name of index, second: the value of “id” argument, third: an array of the primary keys of article index. Because in article index for instance we have “pmcId” as primary index key, and “pubmedId” as alternate key.

resolve_single_document:

Next up: resolve_with_join function

--

--