diff --git a/api/resolvers/wallet.js b/api/resolvers/wallet.js index 97bb433c..cbba0eb8 100644 --- a/api/resolvers/wallet.js +++ b/api/resolvers/wallet.js @@ -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({ diff --git a/api/typeDefs/wallet.js b/api/typeDefs/wallet.js index 0fb9063b..78f104c0 100644 --- a/api/typeDefs/wallet.js +++ b/api/typeDefs/wallet.js @@ -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 }) diff --git a/components/wallet/_example.js b/components/wallet/_example.js index 70d37049..c4a2369d 100644 --- a/components/wallet/_example.js +++ b/components/wallet/_example.js @@ -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'. - // 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.