Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Commit

Permalink
fix(mutation): remove custom UpdateControlAction mutation
Browse files Browse the repository at this point in the history
This caused response validation errors since these were not handled in the custom mutation query.
  • Loading branch information
ChristiaanScheermeijer committed Mar 23, 2020
1 parent 8220fc8 commit c872bfd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 54 deletions.
61 changes: 8 additions & 53 deletions src/resolvers/mutation.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { info, warning } from '../utils/logger'
import { driver } from '../driver'
import { retrieveNodeData, pubsub } from '../resolvers'
import { neo4jgraphql } from 'neo4j-graphql-js'
import { pubsub } from '../resolvers'
import RequestControlActionCommand from '../commands/RequestControlActionCommand'
import UpdateControlActionQuery from '../queries/UpdateControlActionQuery'

export const mutationResolvers = {
Mutation: {
Expand All @@ -11,56 +9,13 @@ export const mutationResolvers = {
return command.create
},
UpdateControlAction (object, params, ctx, resolveInfo) {
const queryGenerator = new UpdateControlActionQuery(params, resolveInfo)
return runQuery(queryGenerator.query, 'UpdateControlAction', 'ControlActionMutation')
}
}
}

/**
* @param query
* @param queryType
* @param publishChannel
* @returns {Promise<{from, to} | never>}
*/
const runQuery = function (query, queryType, publishChannel) {
info(`query: ${query}`)
let session = driver.session()
return neo4jgraphql(object, params, ctx, resolveInfo).then(response => {
if (typeof response.identifier === 'string') {
pubsub.publish('ControlActionMutation', { ControlActionMutation: response, identifier: response.identifier })
}

return session.run(query)
.then(result => {
let rt = result.records.map(record => {
return retrievePayload(record.get('_payload'), queryType)
return response
})
const returnValue = rt[0]
if (typeof publishChannel === 'string' && typeof returnValue.identifier === 'string') {
pubsub.publish(publishChannel, { ControlActionMutation: returnValue, identifier: returnValue.identifier })
}
return returnValue
})
.catch(function (error) {
throw Error(error.toString())
})
}

/**
* @param payload
* @param payloadType
* @returns {*}
*/
const retrievePayload = function (payload, payloadType) {
switch (payloadType) {
case 'add':
case 'remove':
return {
from: retrieveNodeData(payload.from),
to: retrieveNodeData(payload.to)
}
case 'RequestControlAction':
return payload.properties
case 'UpdateControlAction':
return payload
default:
warning('Unknown payloadType encountered')
}
}
}
1 change: 0 additions & 1 deletion src/schema/mutation.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
type Mutation {
RequestControlAction(identifier: ID, controlAction: RequestControlActionInput): ControlAction
UpdateControlAction(identifier: ID, actionStatus: ActionStatusType, error: String, url: String): ControlAction
}

0 comments on commit c872bfd

Please sign in to comment.