2024-10-23 00:53:56 +00:00
|
|
|
import gql from 'graphql-tag'
|
2024-10-23 17:42:34 +00:00
|
|
|
import { isServerField } from './common'
|
2024-10-24 01:12:43 +00:00
|
|
|
import { WALLET_FIELDS } from '@/fragments/wallet'
|
2024-10-23 00:53:56 +00:00
|
|
|
|
|
|
|
export function fieldToGqlArg (field) {
|
|
|
|
let arg = `${field.name}: String`
|
|
|
|
if (!field.optional) {
|
|
|
|
arg += '!'
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
|
|
|
|
|
|
|
// same as fieldToGqlArg, but makes the field always optional
|
|
|
|
export function fieldToGqlArgOptional (field) {
|
|
|
|
return `${field.name}: String`
|
|
|
|
}
|
|
|
|
|
|
|
|
export function generateResolverName (walletField) {
|
|
|
|
const capitalized = walletField[0].toUpperCase() + walletField.slice(1)
|
|
|
|
return `upsert${capitalized}`
|
|
|
|
}
|
|
|
|
|
|
|
|
export function generateTypeDefName (walletType) {
|
|
|
|
const PascalCase = walletType.split('_').map(s => s[0].toUpperCase() + s.slice(1).toLowerCase()).join('')
|
|
|
|
return `Wallet${PascalCase}`
|
|
|
|
}
|
|
|
|
|
|
|
|
export function generateMutation (wallet) {
|
|
|
|
const resolverName = generateResolverName(wallet.walletField)
|
|
|
|
|
|
|
|
let headerArgs = '$id: ID, '
|
|
|
|
headerArgs += wallet.fields
|
|
|
|
.filter(isServerField)
|
2024-10-24 01:12:43 +00:00
|
|
|
.map(f => `$${f.name}: String`)
|
|
|
|
.join(', ')
|
|
|
|
headerArgs += ', $settings: AutowithdrawSettings!, $validateLightning: Boolean'
|
2024-10-23 00:53:56 +00:00
|
|
|
|
|
|
|
let inputArgs = 'id: $id, '
|
|
|
|
inputArgs += wallet.fields
|
|
|
|
.filter(isServerField)
|
|
|
|
.map(f => `${f.name}: $${f.name}`).join(', ')
|
2024-10-24 01:12:43 +00:00
|
|
|
inputArgs += ', settings: $settings, validateLightning: $validateLightning,'
|
2024-10-23 00:53:56 +00:00
|
|
|
|
|
|
|
return gql`mutation ${resolverName}(${headerArgs}) {
|
2024-10-24 01:12:43 +00:00
|
|
|
${WALLET_FIELDS}
|
2024-10-23 00:53:56 +00:00
|
|
|
${resolverName}(${inputArgs}) {
|
2024-10-24 01:12:43 +00:00
|
|
|
...WalletFields
|
2024-10-23 00:53:56 +00:00
|
|
|
}
|
|
|
|
}`
|
|
|
|
}
|