refactor: schema modularization
This commit is contained in:
parent
d9e3a9e61f
commit
82b5db6908
35 changed files with 2423 additions and 685 deletions
24
lib/new-admin/graphql/resolvers/transaction.resolver.js
Normal file
24
lib/new-admin/graphql/resolvers/transaction.resolver.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
const DataLoader = require('dataloader')
|
||||
const { parseAsync } = require('json2csv')
|
||||
|
||||
const transactions = require('../../modules/transactions')
|
||||
const anonymous = require('../../../constants').anonymousCustomer
|
||||
|
||||
const transactionsLoader = new DataLoader(ids => transactions.getCustomerTransactionsBatch(ids))
|
||||
|
||||
const resolvers = {
|
||||
Customer: {
|
||||
transactions: parent => transactionsLoader.load(parent.id)
|
||||
},
|
||||
Transaction: {
|
||||
isAnonymous: parent => (parent.customerId === anonymous.uuid)
|
||||
},
|
||||
Query: {
|
||||
transactions: (...[, { from, until, limit, offset }]) =>
|
||||
transactions.batch(from, until, limit, offset),
|
||||
transactionsCsv: (...[, { from, until, limit, offset }]) =>
|
||||
transactions.batch(from, until, limit, offset).then(parseAsync)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = resolvers
|
||||
Loading…
Add table
Add a link
Reference in a new issue