FSharp.Data.GraphQL icon indicating copy to clipboard operation
FSharp.Data.GraphQL copied to clipboard

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

Open njlr opened this issue 5 years ago • 0 comments

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?

njlr avatar Nov 12 '20 18:11 njlr