feat: Customer transactions fetching with dataloader library
This commit is contained in:
parent
d5f3763e91
commit
0ec49159e4
4 changed files with 65 additions and 3 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue