From adc680ecdda45c11343bfe6367bbf64a00ee474d Mon Sep 17 00:00:00 2001 From: golobitch Date: Mon, 5 Aug 2024 22:57:42 +0200 Subject: [PATCH 1/3] feat(backend): support for returning grantId when querying outgoing payment When querying outgoing payment, either single one, or list of them via pagination, etc., it will be possible to also get a grantId under which the outgoing --- .../generated/graphql.ts | 3 +++ .../src/graphql/generated/graphql.schema.json | 12 ++++++++++++ packages/backend/src/graphql/generated/graphql.ts | 3 +++ .../src/graphql/resolvers/outgoing_payment.ts | 3 ++- packages/backend/src/graphql/schema.graphql | 2 ++ packages/frontend/app/generated/graphql.ts | 3 +++ .../src/generated/graphql.ts | 3 +++ test/integration/lib/generated/graphql.ts | 3 +++ 8 files changed, 31 insertions(+), 1 deletion(-) diff --git a/localenv/mock-account-servicing-entity/generated/graphql.ts b/localenv/mock-account-servicing-entity/generated/graphql.ts index 44c15b81de..e482374c2f 100644 --- a/localenv/mock-account-servicing-entity/generated/graphql.ts +++ b/localenv/mock-account-servicing-entity/generated/graphql.ts @@ -841,6 +841,8 @@ export type OutgoingPayment = BasePayment & Model & { /** Amount to send (fixed send) */ debitAmount: Amount; error?: Maybe; + /** Id of the Grant under which this outgoing payment was created */ + grantId?: Maybe; /** Outgoing payment id */ id: Scalars['ID']['output']; /** Available liquidity */ @@ -1992,6 +1994,7 @@ export type OutgoingPaymentResolvers; debitAmount?: Resolver; error?: Resolver, ParentType, ContextType>; + grantId?: Resolver, ParentType, ContextType>; id?: Resolver; liquidity?: Resolver, ParentType, ContextType>; metadata?: Resolver, ParentType, ContextType>; diff --git a/packages/backend/src/graphql/generated/graphql.schema.json b/packages/backend/src/graphql/generated/graphql.schema.json index 6cc8288adf..f0b8b64033 100644 --- a/packages/backend/src/graphql/generated/graphql.schema.json +++ b/packages/backend/src/graphql/generated/graphql.schema.json @@ -4916,6 +4916,18 @@ "isDeprecated": false, "deprecationReason": null }, + { + "name": "grantId", + "description": "Id of the Grant under which this outgoing payment was created", + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, { "name": "id", "description": "Outgoing payment id", diff --git a/packages/backend/src/graphql/generated/graphql.ts b/packages/backend/src/graphql/generated/graphql.ts index 44c15b81de..e482374c2f 100644 --- a/packages/backend/src/graphql/generated/graphql.ts +++ b/packages/backend/src/graphql/generated/graphql.ts @@ -841,6 +841,8 @@ export type OutgoingPayment = BasePayment & Model & { /** Amount to send (fixed send) */ debitAmount: Amount; error?: Maybe; + /** Id of the Grant under which this outgoing payment was created */ + grantId?: Maybe; /** Outgoing payment id */ id: Scalars['ID']['output']; /** Available liquidity */ @@ -1992,6 +1994,7 @@ export type OutgoingPaymentResolvers; debitAmount?: Resolver; error?: Resolver, ParentType, ContextType>; + grantId?: Resolver, ParentType, ContextType>; id?: Resolver; liquidity?: Resolver, ParentType, ContextType>; metadata?: Resolver, ParentType, ContextType>; diff --git a/packages/backend/src/graphql/resolvers/outgoing_payment.ts b/packages/backend/src/graphql/resolvers/outgoing_payment.ts index c4907b6e58..699357de60 100644 --- a/packages/backend/src/graphql/resolvers/outgoing_payment.ts +++ b/packages/backend/src/graphql/resolvers/outgoing_payment.ts @@ -172,6 +172,7 @@ export function paymentToGraphql( receiveAmount: payment.receiveAmount, metadata: payment.metadata, createdAt: new Date(+payment.createdAt).toISOString(), - quote: quoteToGraphql(payment.quote) + quote: quoteToGraphql(payment.quote), + grantId: payment.grantId } } diff --git a/packages/backend/src/graphql/schema.graphql b/packages/backend/src/graphql/schema.graphql index 1e1d0e4489..dcf104c049 100644 --- a/packages/backend/src/graphql/schema.graphql +++ b/packages/backend/src/graphql/schema.graphql @@ -849,6 +849,8 @@ type OutgoingPayment implements BasePayment & Model { sentAmount: Amount! "Date-time of creation" createdAt: String! + "Id of the Grant under which this outgoing payment was created" + grantId: String } enum OutgoingPaymentState { diff --git a/packages/frontend/app/generated/graphql.ts b/packages/frontend/app/generated/graphql.ts index 4e89d4245c..10e878774f 100644 --- a/packages/frontend/app/generated/graphql.ts +++ b/packages/frontend/app/generated/graphql.ts @@ -841,6 +841,8 @@ export type OutgoingPayment = BasePayment & Model & { /** Amount to send (fixed send) */ debitAmount: Amount; error?: Maybe; + /** Id of the Grant under which this outgoing payment was created */ + grantId?: Maybe; /** Outgoing payment id */ id: Scalars['ID']['output']; /** Available liquidity */ @@ -1992,6 +1994,7 @@ export type OutgoingPaymentResolvers; debitAmount?: Resolver; error?: Resolver, ParentType, ContextType>; + grantId?: Resolver, ParentType, ContextType>; id?: Resolver; liquidity?: Resolver, ParentType, ContextType>; metadata?: Resolver, ParentType, ContextType>; diff --git a/packages/mock-account-service-lib/src/generated/graphql.ts b/packages/mock-account-service-lib/src/generated/graphql.ts index 44c15b81de..e482374c2f 100644 --- a/packages/mock-account-service-lib/src/generated/graphql.ts +++ b/packages/mock-account-service-lib/src/generated/graphql.ts @@ -841,6 +841,8 @@ export type OutgoingPayment = BasePayment & Model & { /** Amount to send (fixed send) */ debitAmount: Amount; error?: Maybe; + /** Id of the Grant under which this outgoing payment was created */ + grantId?: Maybe; /** Outgoing payment id */ id: Scalars['ID']['output']; /** Available liquidity */ @@ -1992,6 +1994,7 @@ export type OutgoingPaymentResolvers; debitAmount?: Resolver; error?: Resolver, ParentType, ContextType>; + grantId?: Resolver, ParentType, ContextType>; id?: Resolver; liquidity?: Resolver, ParentType, ContextType>; metadata?: Resolver, ParentType, ContextType>; diff --git a/test/integration/lib/generated/graphql.ts b/test/integration/lib/generated/graphql.ts index 44c15b81de..e482374c2f 100644 --- a/test/integration/lib/generated/graphql.ts +++ b/test/integration/lib/generated/graphql.ts @@ -841,6 +841,8 @@ export type OutgoingPayment = BasePayment & Model & { /** Amount to send (fixed send) */ debitAmount: Amount; error?: Maybe; + /** Id of the Grant under which this outgoing payment was created */ + grantId?: Maybe; /** Outgoing payment id */ id: Scalars['ID']['output']; /** Available liquidity */ @@ -1992,6 +1994,7 @@ export type OutgoingPaymentResolvers; debitAmount?: Resolver; error?: Resolver, ParentType, ContextType>; + grantId?: Resolver, ParentType, ContextType>; id?: Resolver; liquidity?: Resolver, ParentType, ContextType>; metadata?: Resolver, ParentType, ContextType>; From 90c1ca5cc00d519689315fdc725c34e36662b5b7 Mon Sep 17 00:00:00 2001 From: golobitch Date: Mon, 5 Aug 2024 22:58:44 +0200 Subject: [PATCH 2/3] test(outgoing-payment): check if grantId is returned --- .../resolvers/outgoing_payment.test.ts | 62 ++++++++++++++++--- packages/backend/src/tests/outgoingPayment.ts | 2 +- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/graphql/resolvers/outgoing_payment.test.ts b/packages/backend/src/graphql/resolvers/outgoing_payment.test.ts index 53d7d9bb48..71c51affcc 100644 --- a/packages/backend/src/graphql/resolvers/outgoing_payment.test.ts +++ b/packages/backend/src/graphql/resolvers/outgoing_payment.test.ts @@ -10,7 +10,10 @@ import { AppServices } from '../../app' import { initIocContainer } from '../..' import { Config } from '../../config/app' import { createAsset } from '../../tests/asset' -import { createOutgoingPayment } from '../../tests/outgoingPayment' +import { + createOutgoingPayment, + CreateTestQuoteAndOutgoingPaymentOptions +} from '../../tests/outgoingPayment' import { createWalletAddress } from '../../tests/walletAddress' import { truncateTables } from '../../tests/tableManager' import { @@ -61,11 +64,14 @@ describe('OutgoingPayment Resolvers', (): void => { await appContainer.shutdown() }) - const createPayment = async (options: { - walletAddressId: string - metadata?: Record - }): Promise => { - return await createOutgoingPayment(deps, { + const createPayment = async ( + options: { + walletAddressId: string + metadata?: Record + }, + grantId?: string + ): Promise => { + const obj: CreateTestQuoteAndOutgoingPaymentOptions = { ...options, method: 'ilp', receiver: `${Config.openPaymentsUrl}/${uuid()}`, @@ -75,12 +81,54 @@ describe('OutgoingPayment Resolvers', (): void => { assetScale: asset.scale }, validDestination: false - }) + } + + if (grantId) { + obj.grant = { id: grantId } + } + + return await createOutgoingPayment(deps, obj) } describe('Query.outgoingPayment', (): void => { let payment: OutgoingPaymentModel + describe('grantId', (): void => { + it('should return grantId', async (): Promise => { + const grantId = uuid() + + const { id: walletAddressId } = await createWalletAddress(deps, { + assetId: asset.id + }) + + const payment = await createPayment({ walletAddressId }, grantId) + + const query = await appContainer.apolloClient + .query({ + query: gql` + query OutgoingPayment($paymentId: String!) { + outgoingPayment(id: $paymentId) { + id + grantId + walletAddressId + } + } + `, + variables: { + paymentId: payment.id + } + }) + .then((query): OutgoingPayment => query.data?.outgoingPayment) + + expect(query).toEqual({ + id: payment.id, + grantId: payment.grantId, + walletAddressId: payment.walletAddressId, + __typename: 'OutgoingPayment' + }) + }) + }) + describe('metadata', (): void => { const metadata = { description: 'rent', diff --git a/packages/backend/src/tests/outgoingPayment.ts b/packages/backend/src/tests/outgoingPayment.ts index 13d756653d..f28b38e694 100644 --- a/packages/backend/src/tests/outgoingPayment.ts +++ b/packages/backend/src/tests/outgoingPayment.ts @@ -14,7 +14,7 @@ import { IncomingPayment } from '../open_payments/payment/incoming/model' import { createIncomingPayment } from './incomingPayment' import assert from 'assert' -type CreateTestQuoteAndOutgoingPaymentOptions = Omit< +export type CreateTestQuoteAndOutgoingPaymentOptions = Omit< CreateOutgoingPaymentOptions & CreateTestQuoteOptions, 'quoteId' > From 44041aec9c618ab45bd9ec7022786d59cf1a3e10 Mon Sep 17 00:00:00 2001 From: golobitch Date: Mon, 5 Aug 2024 23:02:54 +0200 Subject: [PATCH 3/3] docs(bruno): include grantId when fetching outgoing payment --- .../Peer-to-Peer Payment/Get Outgoing Payment.bru | 1 + .../Rafiki/Rafiki Admin APIs/Get Outgoing Payment.bru | 1 + 2 files changed, 2 insertions(+) diff --git a/bruno/collections/Rafiki/Examples/Admin API - only locally/Peer-to-Peer Payment/Get Outgoing Payment.bru b/bruno/collections/Rafiki/Examples/Admin API - only locally/Peer-to-Peer Payment/Get Outgoing Payment.bru index 3216293fbd..cfca035df3 100644 --- a/bruno/collections/Rafiki/Examples/Admin API - only locally/Peer-to-Peer Payment/Get Outgoing Payment.bru +++ b/bruno/collections/Rafiki/Examples/Admin API - only locally/Peer-to-Peer Payment/Get Outgoing Payment.bru @@ -17,6 +17,7 @@ body:graphql { error metadata id + grantId walletAddressId quote { id diff --git a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Outgoing Payment.bru b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Outgoing Payment.bru index dd91eec3c1..ae9cd5ff47 100644 --- a/bruno/collections/Rafiki/Rafiki Admin APIs/Get Outgoing Payment.bru +++ b/bruno/collections/Rafiki/Rafiki Admin APIs/Get Outgoing Payment.bru @@ -17,6 +17,7 @@ body:graphql { error metadata id + grantId walletAddressId client quote {