feat: Customer transactions fetching with dataloader library

This commit is contained in:
Cesar 2020-12-01 14:32:21 +00:00 committed by Josh Harvey
parent d5f3763e91
commit 0ec49159e4
4 changed files with 65 additions and 3 deletions

View file

@ -3,6 +3,7 @@ const { parseAsync } = require('json2csv')
const { GraphQLDateTime } = require('graphql-iso-date')
const { GraphQLJSON, GraphQLJSONObject } = require('graphql-type-json')
const got = require('got')
const DataLoader = require('dataloader')
const machineLoader = require('../../machine-loader')
const customers = require('../../customers')
@ -265,6 +266,8 @@ const typeDefs = gql`
}
`
const transactionsLoader = new DataLoader(ids => transactions.getCustomerTransactionsBatch(ids))
const notify = () => got.post('http://localhost:3030/dbChange')
.catch(e => console.error('Error: lamassu-server not responding'))
@ -273,7 +276,7 @@ const resolvers = {
JSONObject: GraphQLJSONObject,
Date: GraphQLDateTime,
Customer: {
transactions: parent => transactions.getCustomerTransactions(parent.id)
transactions: parent => transactionsLoader.load(parent.id)
},
Query: {
countries: () => countries,