Code Monkey home page Code Monkey logo

graphkt's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

lsafer-meemer

graphkt's Issues

Lazily evaluated fields for bulk operations

Thoughts

Sometimes database (or any) operations can be merged into one (or at least fewer) operations

Like, in queries, instead of getting a whole document (or row) just to return a few fields
or getting the same related document of multiple documents with multiple queries.
It all can be merged into one query.

Or, in mutations, instead of updating a document multiple times, it can be merged into a single operation.

Proposed Solution

Fields can return a lazily evaluated values that can be merged together after request execution.

Syntax

The library would expose an interface for lazily evaluated values.

interface LazyEvaluatedValue<T>

An adapter implements those interfaces

data class DatabaseGetOperation<T>(
    val collectionName: String,
    val filter: DatabaseFilter,  // made up class name
    val field: String
) :  LazyEvaluatedValue<T>

data class DatabaseSetOperation<T>(
   val collectionName: String,
   val filter: DatabaseFilter, // made up class name
   val field: String,
   val value: DatabaseValue // made up class name
) : LazyEvaluatedValue<T>

A graphql configuration variable can be set

graphql {
    engine {
        lazyValueEvaluator<DatabaseGetOperation> { values: List<DatabaseGetOperation> ->
              databaseClient.performOperations(values) // made up function name
        }
        lazyValueEvaluator<DatabaseSetOperation> { values: List<DatabaseSetOperation> ->
              databaseClient.performOperations(values) // made up function name
        }
    }
}

now the fields would look like:

field("getMyField") {
    //...

    getLazyEvaluatedValue {
        DatabaseGetOperation(
           collectionName ="myCollection",
           filter = DatabaseFilter("id=${instance.id}"),
           field = "myField"
        )       
    }
}
field("setMyField") {
   val arg = argument { /*...*/ }

   getLazyEvaluatedValue {
        val argValue = arg()

      DatabaseSetOperation(
          collectionName = "myCollection",
           filter = DatabaseFilter("id=${instance.id}"),
           field = "myField",
           value = DatabaseValue(argValue)
      )
   }
}

Feature - more getter related customizations

Overview

It is good to be able to add code to all the getters.
It would make plugins more powerful
It would make directives more useful

Suggested Solution

  1. Add Schema.onGet and Schema.onGetBlocking
  2. Add Directive.onGet and Directive.onGetBlocking ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.