1.0.7 • Published 4 years ago

nicedataloader v1.0.7

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

About

nicedataloader is designed as a wrapper for dataloader. It will help pass parameters to graphQL resolver when using dataloader.

example

resolvers.js

const NiceDataLoader = require('nicedataloader').NiceDataLoader;
const pricesLoader = new NiceDataLoader(productResolver.getPrices);

const resolvers = {
    Query: {
        Products: (obj, args, context, info) 
                => productResolver.getProducts( args, context, info),
    },
    Products: {
        Prices: (parent, args, context, info) 
                    => pricesLoader.get(parent.id, args, context, info),
    .
    .
    .
    
    

ProductResolver.js

const getPrices = async (keys, args, context, info) => {
    const mysqlPool = context.mysqlPool;
    const customerType = args.customerType;
    return new Promise((resolve, reject) => {
        productModel.getPrices(mysqlPool, keys, customerType).then((result) => {
        resolve(result);
    }).catch((error) => {
        reject(error);
    });
};

API

functiondescriptionexample
constructor(_function, cache = false)Pass resolver function and set Dataloader cache
get(key, args, context, info)Pass key, args, context, info to resolver returns results from resolver
clear()performs clearAll(), on the dataloader, and sets parameters to null
1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago