Update resolver to match one Donations node

- there should only ever be one Donations node to start off with, if
that changes in the future for some reason, then we'd need to look into
changing the match to something that makes more sense.
This commit is contained in:
mattwr18 2019-11-11 19:14:06 +01:00
parent 835a098731
commit afb443ac0d
3 changed files with 12 additions and 6 deletions

View File

@ -1,13 +1,18 @@
import uuid from 'uuid/v4'
export default {
Mutation: {
UpdateDonations: async (_parent, params, context, _resolveInfo) => {
const { driver } = context
const session = driver.session()
let donations
params.id = params.id || uuid()
const writeTxResultPromise = session.writeTransaction(async txc => {
const updateDonationsTransactionResponse = await txc.run(
`
MATCH (donations:Donations {id: $params.id})
MATCH (donations:Donations)
WITH donations LIMIT 1
SET donations += $params
SET donations.updatedAt = toString(datetime())
RETURN donations

View File

@ -10,8 +10,8 @@ const instance = getNeode()
const driver = getDriver()
const updateDonationsMutation = gql`
mutation($id: ID!, $goal: Int, $progress: Int) {
UpdateDonations(id: $id, goal: $goal, progress: $progress) {
mutation($goal: Int, $progress: Int) {
UpdateDonations(goal: $goal, progress: $progress) {
goal
progress
createdAt
@ -48,7 +48,7 @@ describe('donations', () => {
beforeEach(async () => {
variables = {}
newlyCreatedDonations = await factory.create('Donations', { id: 'total-donations' })
newlyCreatedDonations = await factory.create('Donations')
})
afterEach(async () => {
@ -84,7 +84,7 @@ describe('donations', () => {
describe('update donations', () => {
beforeEach(() => {
variables = { id: 'total-donations', goal: 20000, progress: 3000 }
variables = { goal: 20000, progress: 3000 }
})
describe('unauthenticated', () => {

View File

@ -1,4 +1,5 @@
type Donations {
id: ID!
goal: Int!
progress: Int!
createdAt: String
@ -10,5 +11,5 @@ type Query {
}
type Mutation {
UpdateDonations(id: ID!, goal: Int, progress: Int): Donations
UpdateDonations(goal: Int, progress: Int): Donations
}