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

Commit

Permalink
chore(project): fix eslint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristiaanScheermeijer committed Mar 19, 2021
1 parent dbef14b commit c95fc49
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 79 deletions.
8 changes: 5 additions & 3 deletions src/auth/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { AuthorizationError } from 'graphql-auth-directives'
describe('verifyRequest', function () {
const makeContext = (jwt) => ({
req: {
headers: jwt ? ({
Authorization: `Bearer ${jwt}`
}) : {}
headers: jwt
? ({
Authorization: `Bearer ${jwt}`
})
: {}
}
})

Expand Down
52 changes: 26 additions & 26 deletions src/commands/RequestControlActionCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ class RequestControlActionCommand {
return [
`MATCH (sa:SoftwareApplication)<-[:ACTION_APPLICATION]-(ep:EntryPoint {identifier:"${requestInput.entryPointIdentifier}"})-[:POTENTIAL_ACTION]->(ca:ControlAction {identifier:"${requestInput.potentialActionIdentifier}"})`,
`RETURN ep {${QueryHelper.schemaTypeClause('ep')}, identifier:ep.identifier, name:ep.name, contributor:ep.contributor, title:ep.title, creator:ep.creator, source:ep.source, subject:ep.subject, format:ep.format, language:ep.language,`,
`actionApplication:sa,`,
'actionApplication:sa,',
`potentialAction:{${QueryHelper.schemaTypeClause('ca')}, identifier:ca.identifier, name:ca.name, contributor:ca.contributor, title:ca.title, description:ca.description, creator:ca.creator, source:ca.source, subject:ca.subject, format:ca.format, language:ca.language, actionStatus:ca.actionStatus, url:ca.url,`,
`object:[(ca)-[:\`OBJECT\`]->(\`controlActionTemplate_property\`:\`Property\`) | { ${QueryHelper.schemaTypeClause('controlActionTemplate_property', ['Property'])}, \`identifier\`:\`controlActionTemplate_property\`.\`identifier\`, \`title\`:\`controlActionTemplate_property\`.\`title\`, \`name\`:\`controlActionTemplate_property\`.\`name\`, \`description\`:\`controlActionTemplate_property\`.\`description\`, \`rangeIncludes\`:\`controlActionTemplate_property\`.\`rangeIncludes\`, \`valueRequired\`:\`controlActionTemplate_property\`.\`valueRequired\` }]`,
`+ [(ca)-[:\`OBJECT\`]->(\`controlActionTemplate_propertyValueSpecification\`:\`PropertyValueSpecification\`) | { ${QueryHelper.schemaTypeClause('controlActionTemplate_propertyValueSpecification', ['PropertyValueSpecification'])}, \`identifier\`:\`controlActionTemplate_propertyValueSpecification\`.\`identifier\`, \`title\`:\`controlActionTemplate_propertyValueSpecification\`.\`title\`, \`name\`:\`controlActionTemplate_propertyValueSpecification\`.\`name\`,\`valueName\`:\`controlActionTemplate_propertyValueSpecification\`.\`valueName\`, \`valueRequired\`:\`controlActionTemplate_propertyValueSpecification\`.\`valueRequired\`, \`defaultValue\`:\`controlActionTemplate_propertyValueSpecification\`.\`defaultValue\`, \`stepValue\`:\`controlActionTemplate_propertyValueSpecification\`.\`stepValue\`, \`disambiguatingDescription\`:\`controlActionTemplate_propertyValueSpecification\`.\`disambiguatingDescription\`, \`minValue\`:\`controlActionTemplate_propertyValueSpecification\`.\`maxValue\`, \`multipleValue\`:\`controlActionTemplate_propertyValueSpecification\`.\`multipleValue\`, \`readonlyValue\`:\`controlActionTemplate_propertyValueSpecification\`.\`readonlyValue\`, \`valueMaxLength\`:\`controlActionTemplate_propertyValueSpecification\`.\`valueMaxLength\`, \`valueMinLength\`:\`controlActionTemplate_propertyValueSpecification\`.\`valueMinLength\`, \`valuePattern\`:\`controlActionTemplate_propertyValueSpecification\`.\`valuePattern\`, \`valueRequired\`:\`controlActionTemplate_propertyValueSpecification\`.\`valueRequired\` }]`,
`}} AS _payload`
'}} AS _payload'
].join(' ')
}

Expand All @@ -103,16 +103,18 @@ class RequestControlActionCommand {
* @private
*/
_generateCreateQuery (template, requestInput) {
const nodeAliasesClause = (Array.isArray(requestInput.propertyObject) && requestInput.propertyObject.length > 0) ? `, ${requestInput.propertyObject.map(object => {
const nodeAliasesClause = (Array.isArray(requestInput.propertyObject) && requestInput.propertyObject.length > 0)
? `, ${requestInput.propertyObject.map(object => {
return `\`${object.alias}\``
}).join(', ')}` : ``
}).join(', ')}`
: ''
const propertySelections = this._generateMatchPropertyNodes(requestInput)

return [
`MATCH (\`entryPoint\`:\`EntryPoint\` {\`identifier\`:"${requestInput.entryPointIdentifier}"})${this.queryHelper.generateRelationClause('EntryPoint', 'potentialAction')}(\`potentialControlAction\`:\`ControlAction\` {\`identifier\`:"${requestInput.potentialActionIdentifier}"})`,
propertySelections ? `, ${propertySelections}` : '',
`WITH \`entryPoint\`, \`potentialControlAction\`${nodeAliasesClause}`,
`LIMIT 1`,
'LIMIT 1',
`CREATE (\`entryPoint\`)${this.queryHelper.generateRelationClause('ControlAction', 'target', null, true)}(\`controlAction\`:\`ControlAction\`:\`ActionInterface\`:\`ProvenanceActivityInterface\`:\`ProvenanceEntityInterface\`:\`ThingInterface\` {${this._generateControlActionPropertyClause(template.potentialAction)}})${this.queryHelper.generateRelationClause('ControlAction', 'wasDerivedFrom')}(\`potentialControlAction\`)`,
`WITH \`entryPoint\`, \`potentialControlAction\`, \`controlAction\`${nodeAliasesClause}`,
this._generateCreatePropertyValuesClause(template, requestInput),
Expand All @@ -129,13 +131,9 @@ class RequestControlActionCommand {
*/
_validateRequestInput (template, requestInput) {
// check request propertyObjects against template properties
let requestPropertyValidity = (requestInput.propertyObject || []).map(requestProperty => {
const requestPropertyValidity = (requestInput.propertyObject || []).map(requestProperty => {
return template.potentialAction.object.some(templateProperty => {
if (
templateProperty._schemaType === 'Property' && requestProperty.potentialActionPropertyIdentifier === templateProperty.identifier
) {
return true
}
return templateProperty._schemaType === 'Property' && requestProperty.potentialActionPropertyIdentifier === templateProperty.identifier
})
})

Expand All @@ -144,11 +142,9 @@ class RequestControlActionCommand {
}

// check request propertyObjects against template properties
let requestPropertyValueValidity = (requestInput.propertyValueObject || []).map(requestProperty => {
const requestPropertyValueValidity = (requestInput.propertyValueObject || []).map(requestProperty => {
return template.potentialAction.object.some(templateProperty => {
if (templateProperty._schemaType === 'PropertyValueSpecification' && requestProperty.potentialActionPropertyValueSpecificationIdentifier === templateProperty.identifier) {
return true
}
return templateProperty._schemaType === 'PropertyValueSpecification' && requestProperty.potentialActionPropertyValueSpecificationIdentifier === templateProperty.identifier
})
})

Expand Down Expand Up @@ -225,8 +221,8 @@ class RequestControlActionCommand {
* @private
*/
_composeControlActionPropertyClause (templateProperty, requestProperty) {
let segments = [
`\`identifier\`: apoc.create.uuid()`,
const segments = [
'`identifier`: apoc.create.uuid()',
`\`propertyID\`:"${templateProperty.identifier}"`,
`\`description\`:"${templateProperty.description}"`,
`\`title\`:"${templateProperty.title}"`,
Expand All @@ -245,8 +241,8 @@ class RequestControlActionCommand {
* @private
*/
_composeControlActionPropertyValueClause (templateProperty, requestPropertyValue) {
let segments = [
`\`identifier\`: apoc.create.uuid()`,
const segments = [
'`identifier`: apoc.create.uuid()',
`\`propertyID\`:"${templateProperty.identifier}"`,
`\`description\`:"${templateProperty.description}"`,
`\`title\`:"${templateProperty.title}"`,
Expand Down Expand Up @@ -289,7 +285,7 @@ class RequestControlActionCommand {
const segments = template.potentialAction.object.map(templateProperty => {
// find matching property in requestInput
switch (templateProperty._schemaType) {
case 'Property':
case 'Property': {
// find matching property in requestInput
const matchingRequestProperty = requestInput.propertyObject.find(requestProperty => {
return requestProperty.potentialActionPropertyIdentifier === templateProperty.identifier
Expand All @@ -300,7 +296,8 @@ class RequestControlActionCommand {
}
// compose PropertyValue clause
return `(\`controlAction\`)${objectRelationClause}(\`${matchingRequestProperty.propertyValueAlias}\`:\`PropertyValue\`:\`ThingInterface\` {${this._composeControlActionPropertyClause(templateProperty, matchingRequestProperty)}})`
case 'PropertyValueSpecification':
}
case 'PropertyValueSpecification': {
const matchingRequestPropertyValue = requestInput.propertyValueObject.find(requestPropertyValue => {
return requestPropertyValue.potentialActionPropertyValueSpecificationIdentifier === templateProperty.identifier
})
Expand Down Expand Up @@ -328,10 +325,13 @@ class RequestControlActionCommand {
if (templateProperty.valueRequired === true) {
throw new UserInputError('Required value property is missing from input: ' + templateProperty.identifier + ' ' + templateProperty.title)
}
return
return undefined
}
default:
warning('Unknown potentialAction template object encountered')
}

return undefined
})
if (segments.length <= 0) {
return ''
Expand All @@ -350,7 +350,7 @@ class RequestControlActionCommand {
return ''
}

let segments = requestProperties.map(requestProperty => {
const segments = requestProperties.map(requestProperty => {
return `(\`${requestProperty.propertyValueAlias}\`)${this.queryHelper.generateRelationClause('PropertyValue', 'nodeValue')}(\`${requestProperty.alias}\`)`
})

Expand All @@ -364,10 +364,10 @@ class RequestControlActionCommand {
* @private
*/
_generateReturnClause (template, requestInput) {
let segments = [
`RETURN \`controlAction\` {`,
const segments = [
'RETURN `controlAction` {',
this.queryHelper.selectedPropertiesClause('ControlAction', 'controlAction', this.resolveInfo.fieldNodes[0].selectionSet),
`} AS _payload`
'} AS _payload'
]

return segments.join(' ')
Expand Down
54 changes: 29 additions & 25 deletions src/helpers/QueryHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SchemaHelper from './SchemaHelper'
import StringHelper from './StringHelper'

const bracketRegExString = '^\\[.*?\\]$'
const paginationParameters = { 'offset': 'SKIP', 'first': 'LIMIT' }
const paginationParameters = { offset: 'SKIP', first: 'LIMIT' }

class QueryHelper {
/**
Expand All @@ -25,7 +25,7 @@ class QueryHelper {
typeFieldsClause (typeName, alias, host, depth = 2) {
if (depth <= 0) {
info('typeFieldsClause depth reached')
return `DEPTH REACHED`
return 'DEPTH REACHED'
}

const typeFields = this.schemaHelper.getTypeFields(typeName)
Expand Down Expand Up @@ -64,10 +64,10 @@ class QueryHelper {
const type = this.schemaHelper.getSchemaType(fieldTypeName)
if (typeof type === 'undefined') {
warning(`unknown type encountered: ${fieldTypeName}`)
return `UNKNOWN TYPE`
return 'UNKNOWN TYPE'
}

let segments = []
const segments = []
const className = type.constructor.name
switch (className) {
case 'GraphQLScalarType':
Expand All @@ -83,41 +83,44 @@ class QueryHelper {
case 'GraphQLObjectType':
// return _Neo4j classes (datetime etc) as Scalars not Objects
if (fieldTypeName.startsWith('_Neo4j')) {
info(`_Neo4j class detected`)
info('_Neo4j class detected')
segments.push(QueryHelper.scalarPropertyClause(fieldName, alias))
} else if (depth <= 1) {
segments.push(`\`${fieldName}\`:${isListType ? `` : `HEAD(`}`)
segments.push(`\`${fieldName}\`:${isListType ? '' : 'HEAD('}`)
segments.push(this._nodePropertyURIClause(typeName, alias, fieldName, fieldTypeName, host))
segments.push(`${isListType ? `` : `)`}`)
segments.push(`${isListType ? '' : ')'}`)
} else {
info(`Object fieldType ${fieldTypeName} fields`)
}
break
case 'GraphQLInterfaceType':
case 'GraphQLInterfaceType': {
const interfaceTypeNames = this.schemaHelper.findInterfaceImplementingTypes(fieldTypeName)
if (!interfaceTypeNames || interfaceTypeNames.length <= 0) {
break
}
segments.push(`\`${fieldName}\`:${isListType ? `` : `HEAD(`}`)
segments.push(`\`${fieldName}\`:${isListType ? '' : 'HEAD('}`)
segments.push(this._nodePropertyURIClause(typeName, alias, fieldName, fieldTypeName, host))
segments.push(`${isListType ? `` : `)`}`)
segments.push(`${isListType ? '' : ')'}`)
break
case 'GraphQLUnionType':
}
case 'GraphQLUnionType': {
const unionType = this.schemaHelper.findUnionType(fieldTypeName)
if (!unionType || unionType._types.length <= 0) {
break
}
segments.push(`\`${fieldName}\`:${isListType ? `` : `HEAD(`}`)
segments.push(`\`${fieldName}\`:${isListType ? '' : 'HEAD('}`)
segments.push(
unionType._types.map(unionType => {
if (depth <= 1) {
return this._nodePropertyURIClause(typeName, alias, fieldName, unionType.name, host)
} else {
info(`Union fieldType ${unionType.name} fields`)
}
return undefined
}).filter(Boolean).join(' + '))
segments.push(`${isListType ? `` : `)`}`)
segments.push(`${isListType ? '' : ')'}`)
break
}
default:
warning(`unknown type class encountered: ${fieldTypeName}`)
break
Expand All @@ -133,23 +136,24 @@ class QueryHelper {
* @returns {string}
*/
selectedPropertiesClause (parentType, parentAlias, selectionSet) {
let scalarPropertyClauses = [`\`_schemaType\`:HEAD(labels(\`${parentAlias}\`))`]
const scalarPropertyClauses = [`\`_schemaType\`:HEAD(labels(\`${parentAlias}\`))`]

if (selectionSet.kind !== 'SelectionSet') {
throw Error('Property clause generation needs a selectionSet')
}

selectionSet.selections.map(selection => {
selectionSet.selections.forEach(selection => {
switch (selection.kind) {
case 'Field':
case 'Field': {
const nodeClause = this.selectedPropertyClause(parentType, parentAlias, selection)
if (typeof nodeClause === 'string') {
scalarPropertyClauses.push(nodeClause)
}
break
}
case 'InlineFragment':
if (selection.typeCondition.kind === 'NamedType' && selection.typeCondition.name.value === parentType) {
selection.selectionSet.selections.map(namedTypeSelection => {
selection.selectionSet.selections.forEach(namedTypeSelection => {
const nodeClause = this.selectedPropertyClause(parentType, parentAlias, namedTypeSelection)
if (typeof nodeClause === 'string') {
scalarPropertyClauses.push(nodeClause)
Expand All @@ -162,7 +166,7 @@ class QueryHelper {
}
})

return scalarPropertyClauses.filter(Boolean).join(`, `)
return scalarPropertyClauses.filter(Boolean).join(', ')
}

/**
Expand Down Expand Up @@ -237,7 +241,7 @@ class QueryHelper {
QueryHelper.relationClause(relationDetails),
`(\`${alias}\`:\`${propertyTypeName}\`) | {`,
this.selectedPropertiesClause(propertyTypeName, alias, selection.selectionSet),
`}]`
'}]'
].join(' ')
}).join(' + ')
} else {
Expand All @@ -247,7 +251,7 @@ class QueryHelper {
QueryHelper.relationClause(relationDetails),
`(\`${alias}\`:\`${propertyTypeName}\`) | {`,
this.selectedPropertiesClause(propertyTypeName, alias, selection.selectionSet),
`}]`
'}]'
].join(' ')
}

Expand Down Expand Up @@ -281,7 +285,7 @@ class QueryHelper {
generatePaginationClause (params) {
let paginationClause = ''

for (let paginationParam in paginationParameters) {
for (const paginationParam in paginationParameters) {
if (paginationParam in params) {
paginationClause += ` ${paginationParameters[paginationParam]} ${params[paginationParam]}`
}
Expand All @@ -298,7 +302,7 @@ class QueryHelper {
let conditionalClause = ''

// process all parameters, except pagination parameters
for (let param in params) {
for (const param in params) {
// ignore pagination parameters
if (param in paginationParameters) {
continue
Expand All @@ -316,9 +320,9 @@ class QueryHelper {
* @returns {string}
*/
static relationClause (relationDetails, alias, invert) {
let clause = `-[${(typeof alias === 'string') ? `\`${alias}\`` : ``}:\`${relationDetails['name']}\`]-`
let clause = `-[${(typeof alias === 'string') ? `\`${alias}\`` : ''}:\`${relationDetails.name}\`]-`

switch (relationDetails['direction'].toString().toUpperCase()) {
switch (relationDetails.direction.toString().toUpperCase()) {
case 'OUT':
clause = `${(invert) ? '<' : ''}${clause}${(invert) ? '' : '>'}`
break
Expand Down Expand Up @@ -370,7 +374,7 @@ class QueryHelper {
const relatedNodeAlias = `${parentAlias}_${propertyTypeAlias}`
return [
`[(\`${parentAlias}\`)${this.generateRelationClause(parentTypeName, propertyName)}(\`${relatedNodeAlias}\`:\`${propertyTypeName}\`)`,
`|`,
'|',
`"${host.replace(/\/$|$/, '/')}"+\`${relatedNodeAlias}\`.\`identifier\` ]`
].join(' ')
}
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/SchemaHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class SchemaHelper {
* @param propertyType
*/
static retrievePropertyTypeRelationDetails (propertyType) {
let relationDetails = {}
const relationDetails = {}

const directives = propertyType.astNode.directives
if (directives instanceof Array === false) {
Expand All @@ -153,7 +153,7 @@ class SchemaHelper {
const directive = directives[di]
if (directive.name.value === 'relation') {
const directiveArguments = directive.arguments
directiveArguments.map(directiveArgument => {
directiveArguments.forEach(directiveArgument => {
if (directiveArgument.kind === 'Argument') {
switch (directiveArgument.name.value.toString()) {
case 'name':
Expand Down
3 changes: 2 additions & 1 deletion src/migrations.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { join } from 'path'
import walkSync from 'walk-sync'
import { driver } from './driver'
import retryPromise from './utils/retryPromise'
Expand All @@ -8,7 +9,7 @@ import chalk from 'chalk'
* @returns {Promise<void>}
*/
export const runMigrations = async () => {
const migrationFiles = walkSync(`${__dirname}/migrations`, {
const migrationFiles = walkSync(join(__dirname, '/migrations'), {
directories: false,
includeBasePath: true,
globs: ['*.js']
Expand Down
2 changes: 1 addition & 1 deletion src/queries/GetFullNodeQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class GetFullNodeQuery {
* @private
*/
_generateQuery () {
const alias = `node`
const alias = 'node'
return [
`MATCH (\`${alias}\`:\`${this.type}\`)`,
`WHERE \`${alias}\`.\`identifier\` = "${this.identifier}"`,
Expand Down
2 changes: 1 addition & 1 deletion src/queries/GetTypeQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GetTypeQuery {
*/
_generateQuery () {
return [
`MATCH (\`n\`)`,
'MATCH (`n`)',
`WHERE \`n\`.\`identifier\` = "${this.identifier}"`,
`RETURN \`n\` { ${QueryHelper.schemaTypeClause('n', this.typeNames)} } AS \`_payload\``
].join(' ')
Expand Down
Loading

0 comments on commit c95fc49

Please sign in to comment.