diff --git a/core/api/dev/apollo-federation/supergraph.graphql b/core/api/dev/apollo-federation/supergraph.graphql index 0120d4f607c..eb736dc1fba 100644 --- a/core/api/dev/apollo-federation/supergraph.graphql +++ b/core/api/dev/apollo-federation/supergraph.graphql @@ -184,7 +184,7 @@ type BTCWallet implements Wallet """An unconfirmed incoming onchain balance.""" pendingIncomingBalance: SignedAmount! transactionById(transactionId: ID!): Transaction! - transactionByPaymentHash(paymentHash: PaymentHash!): Transaction! + transactionByPaymentHash(paymentHash: PaymentHash!): Transaction """A list of BTC transactions associated with this wallet.""" transactions( @@ -550,11 +550,19 @@ input IntraLedgerUsdPaymentSendInput walletId: WalletId! } -union Invoice +"""A lightning invoice.""" +interface Invoice @join__type(graph: PUBLIC) - @join__unionMember(graph: PUBLIC, member: "LnInvoice") - @join__unionMember(graph: PUBLIC, member: "LnNoAmountInvoice") - = LnInvoice | LnNoAmountInvoice +{ + """The payment hash of the lightning invoice.""" + paymentHash: PaymentHash! + + """The bolt11 invoice to be paid.""" + paymentRequest: LnPaymentRequest! + + """The payment secret of the lightning invoice.""" + paymentSecret: LnPaymentSecret! +} enum InvoicePaymentStatus @join__type(graph: PUBLIC) @@ -587,7 +595,8 @@ enum link__Purpose { EXECUTION } -type LnInvoice +type LnInvoice implements Invoice + @join__implements(graph: PUBLIC, interface: "Invoice") @join__type(graph: PUBLIC) { paymentHash: PaymentHash! @@ -671,7 +680,8 @@ type LnInvoicePaymentStatusPayload status: InvoicePaymentStatus } -type LnNoAmountInvoice +type LnNoAmountInvoice implements Invoice + @join__implements(graph: PUBLIC, interface: "Invoice") @join__type(graph: PUBLIC) { paymentHash: PaymentHash! @@ -1598,7 +1608,7 @@ type UsdWallet implements Wallet """An unconfirmed incoming onchain balance.""" pendingIncomingBalance: SignedAmount! transactionById(transactionId: ID!): Transaction! - transactionByPaymentHash(paymentHash: PaymentHash!): Transaction! + transactionByPaymentHash(paymentHash: PaymentHash!): Transaction transactions( """Returns the items in the list that come after the specified cursor.""" after: String @@ -1919,7 +1929,7 @@ interface Wallet transactionByPaymentHash( """The payment hash of the lightning invoice paid in this transaction.""" paymentHash: PaymentHash! - ): Transaction! + ): Transaction """ Transactions are ordered anti-chronologically, diff --git a/core/api/src/graphql/admin/schema.graphql b/core/api/src/graphql/admin/schema.graphql index 6d4504a45dd..ee004274a5e 100644 --- a/core/api/src/graphql/admin/schema.graphql +++ b/core/api/src/graphql/admin/schema.graphql @@ -86,7 +86,7 @@ type BTCWallet implements Wallet { """An unconfirmed incoming onchain balance.""" pendingIncomingBalance: SignedAmount! transactionById(transactionId: ID!): Transaction! - transactionByPaymentHash(paymentHash: PaymentHash!): Transaction! + transactionByPaymentHash(paymentHash: PaymentHash!): Transaction """A list of BTC transactions associated with this wallet.""" transactions( @@ -175,7 +175,17 @@ type InitiationViaOnChain { address: OnChainAddress! } -union Invoice = LnInvoice | LnNoAmountInvoice +"""A lightning invoice.""" +interface Invoice { + """The payment hash of the lightning invoice.""" + paymentHash: PaymentHash! + + """The bolt11 invoice to be paid.""" + paymentRequest: LnPaymentRequest! + + """The payment secret of the lightning invoice.""" + paymentSecret: LnPaymentSecret! +} scalar Language @@ -201,19 +211,6 @@ type LightningPayment { status: LnPaymentStatus } -type LnInvoice { - paymentHash: PaymentHash! - paymentRequest: LnPaymentRequest! - paymentSecret: LnPaymentSecret! - satoshis: SatAmount -} - -type LnNoAmountInvoice { - paymentHash: PaymentHash! - paymentRequest: LnPaymentRequest! - paymentSecret: LnPaymentSecret! -} - scalar LnPaymentPreImage """BOLT11 lightning invoice payment request with the amount included""" @@ -416,7 +413,7 @@ type UsdWallet implements Wallet { """An unconfirmed incoming onchain balance.""" pendingIncomingBalance: SignedAmount! transactionById(transactionId: ID!): Transaction! - transactionByPaymentHash(paymentHash: PaymentHash!): Transaction! + transactionByPaymentHash(paymentHash: PaymentHash!): Transaction transactions( """Returns the items in the list that come after the specified cursor.""" after: String @@ -475,7 +472,7 @@ interface Wallet { transactionByPaymentHash( """The payment hash of the lightning invoice paid in this transaction.""" paymentHash: PaymentHash! - ): Transaction! + ): Transaction """ Transactions are ordered anti-chronologically, diff --git a/core/api/src/graphql/public/schema.graphql b/core/api/src/graphql/public/schema.graphql index 7c0ad668bc6..fe64bc01873 100644 --- a/core/api/src/graphql/public/schema.graphql +++ b/core/api/src/graphql/public/schema.graphql @@ -127,7 +127,7 @@ type BTCWallet implements Wallet { """An unconfirmed incoming onchain balance.""" pendingIncomingBalance: SignedAmount! transactionById(transactionId: ID!): Transaction! - transactionByPaymentHash(paymentHash: PaymentHash!): Transaction! + transactionByPaymentHash(paymentHash: PaymentHash!): Transaction """A list of BTC transactions associated with this wallet.""" transactions( @@ -420,7 +420,17 @@ input IntraLedgerUsdPaymentSendInput { walletId: WalletId! } -union Invoice = LnInvoice | LnNoAmountInvoice +"""A lightning invoice.""" +interface Invoice { + """The payment hash of the lightning invoice.""" + paymentHash: PaymentHash! + + """The bolt11 invoice to be paid.""" + paymentRequest: LnPaymentRequest! + + """The payment secret of the lightning invoice.""" + paymentSecret: LnPaymentSecret! +} enum InvoicePaymentStatus { EXPIRED @@ -430,7 +440,7 @@ enum InvoicePaymentStatus { scalar Language -type LnInvoice { +type LnInvoice implements Invoice { paymentHash: PaymentHash! paymentRequest: LnPaymentRequest! paymentSecret: LnPaymentSecret! @@ -498,7 +508,7 @@ type LnInvoicePaymentStatusPayload { status: InvoicePaymentStatus } -type LnNoAmountInvoice { +type LnNoAmountInvoice implements Invoice { paymentHash: PaymentHash! paymentRequest: LnPaymentRequest! paymentSecret: LnPaymentSecret! @@ -1255,7 +1265,7 @@ type UsdWallet implements Wallet { """An unconfirmed incoming onchain balance.""" pendingIncomingBalance: SignedAmount! transactionById(transactionId: ID!): Transaction! - transactionByPaymentHash(paymentHash: PaymentHash!): Transaction! + transactionByPaymentHash(paymentHash: PaymentHash!): Transaction transactions( """Returns the items in the list that come after the specified cursor.""" after: String @@ -1508,7 +1518,7 @@ interface Wallet { transactionByPaymentHash( """The payment hash of the lightning invoice paid in this transaction.""" paymentHash: PaymentHash! - ): Transaction! + ): Transaction """ Transactions are ordered anti-chronologically, diff --git a/core/api/src/graphql/shared/types/abstract/invoice.ts b/core/api/src/graphql/shared/types/abstract/invoice.ts index 96081531f4c..b6c16c823f8 100644 --- a/core/api/src/graphql/shared/types/abstract/invoice.ts +++ b/core/api/src/graphql/shared/types/abstract/invoice.ts @@ -1,12 +1,27 @@ -import LnInvoice from "../object/ln-invoice" +import PaymentHash from "../scalar/payment-hash" +import LnPaymentRequest from "../scalar/ln-payment-request" -import { GT } from "@/graphql/index" +import LnPaymentSecret from "../scalar/ln-payment-secret" -import LnNoAmountInvoice from "@/graphql/shared/types/object/ln-noamount-invoice" +import { GT } from "@/graphql/index" -const Invoice = GT.Union({ +const IInvoice = GT.Interface({ name: "Invoice", - types: () => [LnInvoice, LnNoAmountInvoice], + description: "A lightning invoice.", + fields: () => ({ + paymentRequest: { + type: GT.NonNull(LnPaymentRequest), + description: "The bolt11 invoice to be paid.", + }, + paymentHash: { + type: GT.NonNull(PaymentHash), + description: "The payment hash of the lightning invoice.", + }, + paymentSecret: { + type: GT.NonNull(LnPaymentSecret), + description: "The payment secret of the lightning invoice.", + }, + }), }) -export default Invoice +export default IInvoice diff --git a/core/api/src/graphql/shared/types/abstract/wallet.ts b/core/api/src/graphql/shared/types/abstract/wallet.ts index ebf56cd5758..6690c69912d 100644 --- a/core/api/src/graphql/shared/types/abstract/wallet.ts +++ b/core/api/src/graphql/shared/types/abstract/wallet.ts @@ -6,7 +6,7 @@ import SignedAmount from "../scalar/signed-amount" import OnChainAddress from "../scalar/on-chain-address" import PaymentHash from "../scalar/payment-hash" -import Invoice from "./invoice" +import IInvoice from "./invoice" import { connectionArgs } from "@/graphql/connections" import { GT } from "@/graphql/index" @@ -49,7 +49,7 @@ const IWallet = GT.Interface({ }, }, invoiceByPaymentHash: { - type: GT.NonNull(Invoice), + type: GT.NonNull(IInvoice), args: { paymentHash: { type: GT.NonNull(PaymentHash), @@ -59,7 +59,7 @@ const IWallet = GT.Interface({ }, }, transactionByPaymentHash: { - type: GT.NonNull(Transaction), + type: Transaction, args: { paymentHash: { type: GT.NonNull(PaymentHash), diff --git a/core/api/src/graphql/shared/types/object/btc-wallet.ts b/core/api/src/graphql/shared/types/object/btc-wallet.ts index c50d66d9344..377fb137aff 100644 --- a/core/api/src/graphql/shared/types/object/btc-wallet.ts +++ b/core/api/src/graphql/shared/types/object/btc-wallet.ts @@ -8,7 +8,7 @@ import OnChainAddress from "../scalar/on-chain-address" import PaymentHash from "../scalar/payment-hash" -import Invoice from "../abstract/invoice" +import IInvoice from "../abstract/invoice" import Transaction, { TransactionConnection } from "./transaction" @@ -130,7 +130,7 @@ const BtcWallet = GT.Object({ }, }, invoiceByPaymentHash: { - type: GT.NonNull(Invoice), + type: GT.NonNull(IInvoice), args: { paymentHash: { type: GT.NonNull(PaymentHash), @@ -153,7 +153,7 @@ const BtcWallet = GT.Object({ }, }, transactionByPaymentHash: { - type: GT.NonNull(Transaction), + type: Transaction, args: { paymentHash: { type: GT.NonNull(PaymentHash), diff --git a/core/api/src/graphql/shared/types/object/ln-invoice.ts b/core/api/src/graphql/shared/types/object/ln-invoice.ts index df1dfb172da..7d914f86cd6 100644 --- a/core/api/src/graphql/shared/types/object/ln-invoice.ts +++ b/core/api/src/graphql/shared/types/object/ln-invoice.ts @@ -3,10 +3,13 @@ import PaymentHash from "../scalar/payment-hash" import LnPaymentSecret from "../scalar/ln-payment-secret" import SatAmount from "../scalar/sat-amount" +import IInvoice from "../abstract/invoice" + import { GT } from "@/graphql/index" const LnInvoice = GT.Object({ name: "LnInvoice", + interfaces: () => [IInvoice], isTypeOf: (source) => !!source.lnInvoice.amount, fields: () => ({ paymentRequest: { diff --git a/core/api/src/graphql/shared/types/object/ln-noamount-invoice.ts b/core/api/src/graphql/shared/types/object/ln-noamount-invoice.ts index ddbd7f04c07..49ebed19b53 100644 --- a/core/api/src/graphql/shared/types/object/ln-noamount-invoice.ts +++ b/core/api/src/graphql/shared/types/object/ln-noamount-invoice.ts @@ -2,11 +2,14 @@ import LnPaymentRequest from "../scalar/ln-payment-request" import PaymentHash from "../scalar/payment-hash" import LnPaymentSecret from "../scalar/ln-payment-secret" +import IInvoice from "../abstract/invoice" + import { GT } from "@/graphql/index" // import InvoicePaymentStatus from "../scalar/invoice-payment-status" const LnNoAmountInvoice = GT.Object({ name: "LnNoAmountInvoice", + interfaces: () => [IInvoice], isTypeOf: (source) => !source.lnInvoice.amount, fields: () => ({ paymentRequest: { diff --git a/core/api/src/graphql/shared/types/object/usd-wallet.ts b/core/api/src/graphql/shared/types/object/usd-wallet.ts index cfb6e27f830..d63415658ff 100644 --- a/core/api/src/graphql/shared/types/object/usd-wallet.ts +++ b/core/api/src/graphql/shared/types/object/usd-wallet.ts @@ -8,7 +8,7 @@ import OnChainAddress from "../scalar/on-chain-address" import PaymentHash from "../scalar/payment-hash" -import Invoice from "../abstract/invoice" +import IInvoice from "../abstract/invoice" import Transaction, { TransactionConnection } from "./transaction" @@ -128,7 +128,7 @@ const UsdWallet = GT.Object({ }, }, invoiceByPaymentHash: { - type: GT.NonNull(Invoice), + type: GT.NonNull(IInvoice), args: { paymentHash: { type: GT.NonNull(PaymentHash), @@ -151,7 +151,7 @@ const UsdWallet = GT.Object({ }, }, transactionByPaymentHash: { - type: GT.NonNull(Transaction), + type: Transaction, args: { paymentHash: { type: GT.NonNull(PaymentHash), diff --git a/core/api/test/bats/gql/invoice-for-wallet-by-payment-hash.gql b/core/api/test/bats/gql/invoice-for-wallet-by-payment-hash.gql index aa90e4344b6..795a3fcc6ba 100644 --- a/core/api/test/bats/gql/invoice-for-wallet-by-payment-hash.gql +++ b/core/api/test/bats/gql/invoice-for-wallet-by-payment-hash.gql @@ -5,11 +5,9 @@ query me($walletId: WalletId!, $paymentHash: PaymentHash!) { walletById(walletId: $walletId) { id invoiceByPaymentHash(paymentHash: $paymentHash) { + paymentHash ... on LnInvoice { - paymentHash - } - ... on LnNoAmountInvoice { - paymentHash + satoshis } } }