Skip to content

Commit 37d9eea

Browse files
committed
feat: add resolver to outgoing/incoming payments
1 parent 2de1304 commit 37d9eea

File tree

10 files changed

+174
-12
lines changed

10 files changed

+174
-12
lines changed

packages/backend/src/graphql/resolvers/asset.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ describe('Asset Resolvers', (): void => {
296296
withdrawalThreshold
297297
liquidityThreshold
298298
createdAt
299+
tenant {
300+
id
301+
}
299302
}
300303
}
301304
`,
@@ -319,7 +322,11 @@ describe('Asset Resolvers', (): void => {
319322
liquidity: '0',
320323
withdrawalThreshold: asset.withdrawalThreshold.toString(),
321324
liquidityThreshold: asset.liquidityThreshold?.toString(),
322-
createdAt: new Date(+asset.createdAt).toISOString()
325+
createdAt: new Date(+asset.createdAt).toISOString(),
326+
tenant: {
327+
__typename: 'Tenant',
328+
id: asset.tenantId
329+
}
323330
})
324331

325332
await accountingService.createDeposit({
@@ -336,7 +343,11 @@ describe('Asset Resolvers', (): void => {
336343
liquidity: '100',
337344
withdrawalThreshold: asset.withdrawalThreshold.toString(),
338345
liquidityThreshold: asset.liquidityThreshold?.toString(),
339-
createdAt: new Date(+asset.createdAt).toISOString()
346+
createdAt: new Date(+asset.createdAt).toISOString(),
347+
tenant: {
348+
__typename: 'Tenant',
349+
id: asset.tenantId
350+
}
340351
})
341352
})
342353

packages/backend/src/graphql/resolvers/combined_payments.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ describe('Payment', (): void => {
104104
state
105105
metadata
106106
createdAt
107+
tenant {
108+
id
109+
}
107110
}
108111
cursor
109112
}
@@ -139,7 +142,10 @@ describe('Payment', (): void => {
139142
client: combinedOutgoingPayment.client,
140143
state: combinedOutgoingPayment.state,
141144
createdAt: combinedOutgoingPayment.createdAt.toISOString(),
142-
liquidity: '0'
145+
liquidity: '0',
146+
tenant: {
147+
id: combinedOutgoingPayment.tenantId
148+
}
143149
})
144150

145151
const combinedIncomingPayment = toCombinedPayment(
@@ -154,7 +160,10 @@ describe('Payment', (): void => {
154160
client: combinedIncomingPayment.client,
155161
state: combinedIncomingPayment.state,
156162
createdAt: combinedIncomingPayment.createdAt.toISOString(),
157-
liquidity: '0'
163+
liquidity: '0',
164+
tenant: {
165+
id: combinedIncomingPayment.tenantId
166+
}
158167
})
159168
})
160169

packages/backend/src/graphql/resolvers/incoming_payment.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,35 @@ describe('Incoming Payment Resolver', (): void => {
551551
__typename: 'IncomingPayment'
552552
})
553553
})
554+
555+
test('with tenant', async (): Promise<void> => {
556+
const query = await appContainer.apolloClient
557+
.query({
558+
query: gql`
559+
query IncomingPayment($paymentId: String!) {
560+
incomingPayment(id: $paymentId) {
561+
id
562+
tenant {
563+
id
564+
}
565+
}
566+
}
567+
`,
568+
variables: {
569+
paymentId: payment.id
570+
}
571+
})
572+
.then((query): IncomingPayment => query.data?.incomingPayment)
573+
574+
expect(query).toEqual({
575+
id: payment.id,
576+
tenant: {
577+
__typename: 'Tenant',
578+
id: payment.tenantId
579+
},
580+
__typename: 'IncomingPayment'
581+
})
582+
})
554583
})
555584

556585
test('not found', async (): Promise<void> => {

packages/backend/src/graphql/resolvers/incoming_payment.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@ import {
44
MutationResolvers,
55
IncomingPayment as SchemaIncomingPayment,
66
QueryResolvers,
7-
IncomingPaymentFilter
7+
IncomingPaymentFilter,
8+
IncomingPaymentResolvers
89
} from '../generated/graphql'
910
import { IncomingPayment } from '../../open_payments/payment/incoming/model'
1011
import { IncomingPaymentInitiationReason } from '../../open_payments/payment/incoming/types'
1112
import {
1213
isIncomingPaymentError,
1314
errorToCode,
14-
errorToMessage
15+
errorToMessage,
16+
IncomingPaymentError
1517
} from '../../open_payments/payment/incoming/errors'
1618
import { ForTenantIdContext, TenantedApolloContext } from '../../app'
1719
import { getPageInfo } from '../../shared/pagination'
1820
import { Pagination, SortOrder } from '../../shared/baseModel'
1921
import { GraphQLError } from 'graphql'
2022
import { GraphQLErrorCode } from '../errors'
2123
import { IAppConfig } from '../../config/app'
24+
import { tenantToGraphQl } from './tenant'
2225

2326
export const getIncomingPayment: QueryResolvers<TenantedApolloContext>['incomingPayment'] =
2427
async (parent, args, ctx): Promise<ResolversTypes['IncomingPayment']> => {
@@ -266,6 +269,30 @@ export const cancelIncomingPayment: MutationResolvers<TenantedApolloContext>['ca
266269
}
267270
}
268271

272+
export const getIncomingPaymentTenant: IncomingPaymentResolvers<TenantedApolloContext>['tenant'] =
273+
async (parent, args, ctx): Promise<ResolversTypes['Tenant'] | null> => {
274+
if (!parent.id)
275+
throw new GraphQLError('"id" required in request to resolve "tenant".')
276+
const incomingPaymentService = await ctx.container.use(
277+
'incomingPaymentService'
278+
)
279+
const incomingPayment = await incomingPaymentService.get({ id: parent.id })
280+
if (!incomingPayment)
281+
throw new GraphQLError(
282+
errorToMessage[IncomingPaymentError.UnknownPayment],
283+
{
284+
extensions: {
285+
code: errorToCode[IncomingPaymentError.UnknownPayment]
286+
}
287+
}
288+
)
289+
290+
const tenantService = await ctx.container.use('tenantService')
291+
const tenant = await tenantService.get(incomingPayment.tenantId)
292+
if (!tenant) return null
293+
return tenantToGraphQl(tenant)
294+
}
295+
269296
export function paymentToGraphql(
270297
payment: IncomingPayment,
271298
config: IAppConfig

packages/backend/src/graphql/resolvers/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import {
2727
updateIncomingPayment,
2828
approveIncomingPayment,
2929
cancelIncomingPayment,
30-
getIncomingPayments
30+
getIncomingPayments,
31+
getIncomingPaymentTenant
3132
} from './incoming_payment'
3233
import { getQuote, createQuote, getWalletAddressQuotes } from './quote'
3334
import {
@@ -36,7 +37,8 @@ import {
3637
createOutgoingPayment,
3738
getWalletAddressOutgoingPayments,
3839
createOutgoingPaymentFromIncomingPayment,
39-
cancelOutgoingPayment
40+
cancelOutgoingPayment,
41+
getOutgoingPaymentTenant
4042
} from './outgoing_payment'
4143
import {
4244
getPeer,
@@ -142,10 +144,12 @@ export const resolvers: Resolvers = {
142144
settings: getTenantSettings
143145
},
144146
IncomingPayment: {
145-
liquidity: getIncomingPaymentLiquidity
147+
liquidity: getIncomingPaymentLiquidity,
148+
tenant: getIncomingPaymentTenant
146149
},
147150
OutgoingPayment: {
148-
liquidity: getOutgoingPaymentLiquidity
151+
liquidity: getOutgoingPaymentLiquidity,
152+
tenant: getOutgoingPaymentTenant
149153
},
150154
Payment: {
151155
liquidity: getPaymentLiquidity,

packages/backend/src/graphql/resolvers/outgoing_payment.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,35 @@ describe('OutgoingPayment Resolvers', (): void => {
717717
__typename: 'OutgoingPayment'
718718
})
719719
})
720+
721+
test('with tenant', async (): Promise<void> => {
722+
const query = await appContainer.apolloClient
723+
.query({
724+
query: gql`
725+
query OutgoingPayment($paymentId: String!) {
726+
outgoingPayment(id: $paymentId) {
727+
id
728+
tenant {
729+
id
730+
}
731+
}
732+
}
733+
`,
734+
variables: {
735+
paymentId: payment.id
736+
}
737+
})
738+
.then((query): OutgoingPayment => query.data?.outgoingPayment)
739+
740+
expect(query).toEqual({
741+
id: payment.id,
742+
tenant: {
743+
__typename: 'Tenant',
744+
id: payment.tenantId
745+
},
746+
__typename: 'OutgoingPayment'
747+
})
748+
})
720749
})
721750

722751
test('not found', async (): Promise<void> => {

packages/backend/src/graphql/resolvers/outgoing_payment.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import {
44
OutgoingPayment as SchemaOutgoingPayment,
55
WalletAddressResolvers,
66
QueryResolvers,
7-
ResolversTypes
7+
ResolversTypes,
8+
OutgoingPaymentResolvers
89
} from '../generated/graphql'
910
import {
11+
OutgoingPaymentError,
1012
isOutgoingPaymentError,
1113
errorToMessage,
1214
errorToCode
@@ -17,6 +19,7 @@ import { getPageInfo } from '../../shared/pagination'
1719
import { Pagination, SortOrder } from '../../shared/baseModel'
1820
import { GraphQLError } from 'graphql'
1921
import { GraphQLErrorCode } from '../errors'
22+
import { tenantToGraphQl } from './tenant'
2023

2124
export const getOutgoingPayment: QueryResolvers<TenantedApolloContext>['outgoingPayment'] =
2225
async (parent, args, ctx): Promise<ResolversTypes['OutgoingPayment']> => {
@@ -230,6 +233,31 @@ export const getWalletAddressOutgoingPayments: WalletAddressResolvers<TenantedAp
230233
}
231234
}
232235

236+
export const getOutgoingPaymentTenant: OutgoingPaymentResolvers<TenantedApolloContext>['tenant'] =
237+
async (parent, args, ctx): Promise<ResolversTypes['Tenant'] | null> => {
238+
if (!parent.id)
239+
throw new GraphQLError('"id" required in request to resolve "tenant".')
240+
const outgoingPaymentService = await ctx.container.use(
241+
'outgoingPaymentService'
242+
)
243+
const outgoingPayment = await outgoingPaymentService.get({ id: parent.id })
244+
if (!outgoingPayment)
245+
throw new GraphQLError(
246+
errorToMessage[OutgoingPaymentError.UnknownPayment],
247+
{
248+
extensions: {
249+
code: errorToCode[OutgoingPaymentError.UnknownPayment]
250+
}
251+
}
252+
)
253+
254+
const tenantService = await ctx.container.use('tenantService')
255+
const tenant = await tenantService.get(outgoingPayment.tenantId)
256+
if (!tenant) return null
257+
258+
return tenantToGraphQl(tenant)
259+
}
260+
233261
export function paymentToGraphql(
234262
payment: OutgoingPayment
235263
): SchemaOutgoingPayment {

packages/backend/src/graphql/resolvers/peer.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ describe('Peer Resolvers', (): void => {
280280
liquidity
281281
name
282282
liquidityThreshold
283+
tenant {
284+
id
285+
}
283286
}
284287
}
285288
`,
@@ -303,6 +306,10 @@ describe('Peer Resolvers', (): void => {
303306
code: peer.asset.code,
304307
scale: peer.asset.scale
305308
},
309+
tenant: {
310+
__typename: 'Tenant',
311+
id: peer.tenantId
312+
},
306313
http: {
307314
__typename: 'Http',
308315
outgoing: {
@@ -331,6 +338,10 @@ describe('Peer Resolvers', (): void => {
331338
code: peer.asset.code,
332339
scale: peer.asset.scale
333340
},
341+
tenant: {
342+
__typename: 'Tenant',
343+
id: peer.tenantId
344+
},
334345
http: {
335346
__typename: 'Http',
336347
outgoing: {

packages/backend/src/graphql/resolvers/wallet_address.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,9 @@ describe('Wallet Address Resolvers', (): void => {
914914
value
915915
visibleInOpenPayments
916916
}
917+
tenant {
918+
id
919+
}
917920
}
918921
}
919922
`,
@@ -938,6 +941,10 @@ describe('Wallet Address Resolvers', (): void => {
938941
code: walletAddress.asset.code,
939942
scale: walletAddress.asset.scale
940943
},
944+
tenant: {
945+
__typename: 'Tenant',
946+
id: walletAddress.tenantId
947+
},
941948
address: walletAddress.address,
942949
publicName: publicName ?? null,
943950
additionalProperties: [

packages/backend/src/graphql/resolvers/webhooks.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ describe('Webhook Events Query', (): void => {
6868
id
6969
type
7070
data
71+
tenant {
72+
id
73+
}
7174
}
7275
cursor
7376
}
@@ -92,7 +95,11 @@ describe('Webhook Events Query', (): void => {
9295
__typename: 'WebhookEvent',
9396
id: webhookEvent.id,
9497
type: webhookEvent.type,
95-
data: webhookEvent.data
98+
data: webhookEvent.data,
99+
tenant: {
100+
__typename: 'Tenant',
101+
id: webhookEvent.tenantId
102+
}
96103
})
97104
})
98105
})

0 commit comments

Comments
 (0)