GraphQL object fulfilled by querying two different data-stores; how to do this efficiently?

Open
#307 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
fsharp, graphql

Research direction

Start at the Define.Object("Book", ...) entry point mentioned in the issue and read the surrounding object and field-resolution documentation or examples. A solution is done when fast-only queries use fetchFastFields, queries requesting slow fields use fetchSlowFields, and neither function is called more than once per Book.

Written by the indexing model from the issue text.

Description

This is a question rather than an issue (although it could be turned into an issue if no good solution is found!)

Suppose I have a library of books:

type Book = {
  id : ID!
  title : String!
  author : String!
  datePublished : String!
  fullText : String!
  blurb : String!
} 

Some of these fields are "small", and they are stored in a fast data-store (e.g. MySQL, Postgres):

  • id
  • title
  • author
  • datePublished

The other fields are "big", and they are stored in a slow data-store (e.g. Amazon S3):

  • fullText
  • blurb

I have two functions for fetching the fields:

fetchFastFields : ID -> BookPropertiesFast
fetchSlowFields : ID -> BookPropertiesSlow

The behaviour I want on the back-end is:

  • If the query can be fulfilled with only "fast" fields, call fetchFastFields
  • If the query has one or more "slow" fields, call fetchSlowFields
  • For each Book in a query, do not call fetchFastFields or fetchSlowFields more than once.

How should I write my Define.Object("Book", ... code to achieve this?

Dominant language
F#
Stars
406
Forks
74
Avg merge
1d 8h
Merged PRs (30d)
14

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fsprojects/FSharp.Data.GraphQL

All issues in fsprojects/FSharp.Data.GraphQL

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.