Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Experimental mutation API: Fixes for data input objects #536

Merged
merged 9 commits into from
Nov 9, 2020
Prev Previous commit
Next Next commit
Update translate.js
michaeldgraham committed Nov 9, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit b5072b66bd55995ee63b26ec3d1e03c8a968f685
74 changes: 36 additions & 38 deletions src/translate.js
Original file line number Diff line number Diff line change
@@ -1745,24 +1745,23 @@ const nodeMergeOrUpdate = ({
// config.experimental
// no need to use .params key in this argument design
params = params.params;
const [
createProperties,
updateProperties,
generatePrimaryKey
] = translateNodeInputArgument({
dataArgument,
params,
primaryKey,
typeMap,
fieldMap,
resolveInfo,
context
});
const [propertyStatements, generatePrimaryKey] = translateNodeInputArgument(
{
selectionArgument,
dataArgument,
params,
primaryKey,
typeMap,
fieldMap,
resolveInfo,
context
}
);
let onMatchStatements = ``;
if (updateProperties.length > 0) {
if (propertyStatements.length > 0) {
onMatchStatements = `SET ${safeVar(
variableName
)} += {${updateProperties.join(',')}} `;
)} += {${propertyStatements.join(',')}} `;
}
if (isMergeMutation(resolveInfo)) {
const unwrappedType = unwrapNamedType({ type: selectionArgument.type });
@@ -1777,7 +1776,8 @@ const nodeMergeOrUpdate = ({
resolveInfo,
cypherParams: getCypherParams(context)
});
const onCreateProps = [...createProperties, ...generatePrimaryKey];
// generatePrimaryKey is either empty or contains a call to apoc.create.uuid for @id key
const onCreateProps = [...propertyStatements, ...generatePrimaryKey];
let onCreateStatements = ``;
if (onCreateProps.length > 0) {
onCreateStatements = `SET ${safeVar(
@@ -1885,11 +1885,11 @@ RETURN ${safeVariableName}`;
};

const translateNodeInputArgument = ({
selectionArgument = {},
dataArgument = {},
params,
primaryKey,
typeMap,
fieldMap,
resolveInfo,
context
}) => {
@@ -1898,39 +1898,37 @@ const translateNodeInputArgument = ({
const inputType = typeMap[name];
const inputValues = inputType.getFields();
const updateArgs = Object.values(inputValues).map(arg => arg.astNode);
let paramUpdateStatements = buildCypherParameters({
let propertyStatements = buildCypherParameters({
args: updateArgs,
params,
paramKey: 'data',
resolveInfo,
cypherParams: getCypherParams(context)
});
const propertyArgs = updateArgs.filter(arg => {
const name = arg.name.value;
const field = fieldMap[name];
const directives = field.astNode.directives;
return (
!isPrimaryKeyField({ directives }) &&
!isUniqueField({ directives }) &&
!isIndexedField({ directives })
);
});
const createProperties = buildCypherParameters({
args: propertyArgs,
params,
paramKey: 'data',
resolveInfo,
cypherParams: getCypherParams(context)
});
let primaryKeyStatement = [];
if (isMergeMutation(resolveInfo)) {
primaryKeyStatement = setPrimaryKeyValue({
args: updateArgs,
const unwrappedType = unwrapNamedType({ type: selectionArgument.type });
const name = unwrappedType.name;
const inputType = typeMap[name];
const inputValues = inputType.getFields();
const selectionArgs = Object.values(inputValues).map(arg => arg.astNode);
// check key selection values for @id key argument
const primaryKeySelectionValue = setPrimaryKeyValue({
args: selectionArgs,
params: params['where'],
primaryKey
});
const primaryKeyValue = setPrimaryKeyValue({
args: updateArgs,
params: params['data'],
primaryKey
});
if (primaryKeySelectionValue.length && primaryKeyValue.length) {
// apoc.create.uuid() statement returned for both, so a value exists in neither
primaryKeyStatement = primaryKeySelectionValue;
}
}
return [createProperties, paramUpdateStatements, primaryKeyStatement];
return [propertyStatements, primaryKeyStatement];
};

const translateNodeSelectionArgument = ({