Generate resolver name from walletField

This commit is contained in:
ekzyis 2024-07-16 04:08:13 +02:00
parent 03ca84629b
commit f01ce79afa
3 changed files with 10 additions and 10 deletions

View File

@ -20,15 +20,21 @@ import { fetchLnAddrInvoice } from '@/lib/wallet'
export const SERVER_WALLET_DEFS = [lnd, lnAddr, cln]
export function generateResolverName (walletField) {
const capitalized = walletField[0].toUpperCase() + walletField.slice(1)
return `upsertWallet${capitalized}`
}
function injectResolvers (resolvers) {
console.group('injected GraphQL resolvers:')
for (
const w of SERVER_WALLET_DEFS) {
const {
schema,
server: { walletType, walletField, resolverName, testConnect }
server: { walletType, walletField, testConnect }
// app and worker import file differently
} = w.default || w
const resolverName = generateResolverName(walletField)
console.log(resolverName)
resolvers.Mutation[resolverName] = async (parent, { settings, ...data }, { me, models }) => {
return await upsertWallet({

View File

@ -1,5 +1,5 @@
import { gql } from 'graphql-tag'
import { SERVER_WALLET_DEFS } from '@/api/resolvers/wallet'
import { SERVER_WALLET_DEFS, generateResolverName } from '@/api/resolvers/wallet'
function injectTypeDefs (typeDefs) {
console.group('injected GraphQL type defs:')
@ -14,7 +14,8 @@ function injectTypeDefs (typeDefs) {
return arg
}).join(', ')
args += ', settings: AutowithdrawSettings!'
const typeDef = `${w.server.resolverName}(${args}): Boolean`
const resolverName = generateResolverName(w.server.walletField)
const typeDef = `${resolverName}(${args}): Boolean`
console.log(typeDef)
return typeDef
})

View File

@ -95,13 +95,6 @@ export const server = {
// [required]
walletField: 'walletLNbits',
// This can be any name but it makes sense to use something appropriate here like 'upsertWallet<WalletName>'.
// This is used to generate the mutation during save (see `generateMutation` in components/wallets/index.js)
// and inject the corresponding resolver into the GraphQL schema
// (see `injectResolvers` in pages/api/resolvers/wallet.js.).
// [required]
resolverName: 'upsertWalletLNbits',
// Similar to validate above, this function should throw an error if the connection test fails.
// It is called on save on the server before writing the configuration to the database.
// As the name suggests, a good idea is to try to connect to the wallet and create an invoice in this function.