@@ -177,8 +177,9 @@ const relationTypeMutationPayloadField = ({
177
177
tailParams,
178
178
rootVariableNames
179
179
} ) => {
180
+ const safeVariableName = safeVar ( variableName ) ;
180
181
return {
181
- initial : `${ initial } ${ fieldName } : ${ variableName } {${
182
+ initial : `${ initial } ${ fieldName } : ${ safeVariableName } {${
182
183
subSelection [ 0 ]
183
184
} }${ skipLimit } ${ commaIfTail } `,
184
185
...tailParams ,
@@ -802,7 +803,10 @@ const relationshipCreate = ({
802
803
let query = `
803
804
MATCH (${ fromVariable } :${ fromLabel } ${
804
805
fromTemporalClauses && fromTemporalClauses . length > 0
806
+ // uses either a WHERE clause for managed type primary keys (temporal, etc.)
805
807
? `) WHERE ${ fromTemporalClauses . join ( ' AND ' ) } `
808
+ // or a an internal matching clause for normal, scalar property primary keys
809
+ // NOTE this will need to change if we at some point allow for multi field node selection
806
810
: `{${ fromParam } : $from.${ fromParam } })`
807
811
}
808
812
MATCH (${ toVariable } :${ toLabel } ${
@@ -838,15 +842,14 @@ const relationshipDelete = ({
838
842
'Missing required MutationMeta directive on add relationship directive'
839
843
) ;
840
844
}
845
+
841
846
try {
842
847
relationshipNameArg = mutationMeta . arguments . find ( x => {
843
848
return x . name . value === 'relationship' ;
844
849
} ) ;
845
-
846
850
fromTypeArg = mutationMeta . arguments . find ( x => {
847
851
return x . name . value === 'from' ;
848
852
} ) ;
849
-
850
853
toTypeArg = mutationMeta . arguments . find ( x => {
851
854
return x . name . value === 'to' ;
852
855
} ) ;
@@ -855,29 +858,51 @@ const relationshipDelete = ({
855
858
'Missing required argument in MutationMeta directive (relationship, from, or to)'
856
859
) ;
857
860
}
858
- //TODO: need to handle one-to-one and one-to-many
859
- const args = resolveInfo . schema . getMutationType ( ) . getFields ( ) [
860
- resolveInfo . fieldName
861
- ] . astNode . arguments ;
862
861
862
+ //TODO: need to handle one-to-one and one-to-many
863
+ const args = getMutationArguments ( resolveInfo ) ;
863
864
const typeMap = resolveInfo . schema . getTypeMap ( ) ;
864
865
865
866
const fromType = fromTypeArg . value . value ;
866
867
const fromVar = `${ lowFirstLetter ( fromType ) } _from` ;
867
868
const fromInputArg = args . find ( e => e . name . value === 'from' ) . type ;
868
- const fromInputAst =
869
- typeMap [ getNamedType ( fromInputArg ) . type . name . value ] . astNode ;
870
- const fromParam = fromInputAst . fields [ 0 ] . name . value ;
869
+ const fromInputAst = typeMap [ getNamedType ( fromInputArg ) . type . name . value ] . astNode ;
870
+ const fromFields = fromInputAst . fields ;
871
+ const fromParam = fromFields [ 0 ] . name . value ;
872
+ const fromTemporalArgs = getTemporalArguments ( fromFields ) ;
871
873
872
874
const toType = toTypeArg . value . value ;
873
875
const toVar = `${ lowFirstLetter ( toType ) } _to` ;
874
876
const toInputArg = args . find ( e => e . name . value === 'to' ) . type ;
875
- const toInputAst =
876
- typeMap [ getNamedType ( toInputArg ) . type . name . value ] . astNode ;
877
- const toParam = toInputAst . fields [ 0 ] . name . value ;
877
+ const toInputAst = typeMap [ getNamedType ( toInputArg ) . type . name . value ] . astNode ;
878
+ const toFields = toInputAst . fields ;
879
+ const toParam = toFields [ 0 ] . name . value ;
880
+ const toTemporalArgs = getTemporalArguments ( toFields ) ;
878
881
879
882
const relationshipName = relationshipNameArg . value . value ;
880
883
884
+ const schemaTypeName = safeVar ( schemaType ) ;
885
+ const fromVariable = safeVar ( fromVar ) ;
886
+ const fromLabel = safeLabel ( fromType ) ;
887
+ const toVariable = safeVar ( toVar ) ;
888
+ const toLabel = safeLabel ( toType ) ;
889
+ const relationshipVariable = safeVar ( fromVar + toVar ) ;
890
+ const relationshipLabel = safeLabel ( relationshipName ) ;
891
+ const fromRootVariable = safeVar ( '_' + fromVar ) ;
892
+ const toRootVariable = safeVar ( '_' + toVar ) ;
893
+ const fromTemporalClauses = temporalPredicateClauses (
894
+ params . from ,
895
+ fromVariable ,
896
+ fromTemporalArgs ,
897
+ "from"
898
+ ) ;
899
+ const toTemporalClauses = temporalPredicateClauses (
900
+ params . to ,
901
+ toVariable ,
902
+ toTemporalArgs ,
903
+ "to"
904
+ ) ;
905
+ // TODO remove use of _ prefixes in root variableNames and variableName
881
906
const [ subQuery , subParams ] = buildCypherSelection ( {
882
907
initial : '' ,
883
908
selections,
@@ -892,19 +917,20 @@ const relationshipDelete = ({
892
917
variableName : schemaType . name === fromType ? `_${ toVar } ` : `_${ fromVar } `
893
918
} ) ;
894
919
params = { ...params , ...subParams } ;
895
-
896
- const schemaTypeName = safeVar ( schemaType ) ;
897
- const fromVariable = safeVar ( fromVar ) ;
898
- const fromLabel = safeLabel ( fromType ) ;
899
- const toVariable = safeVar ( toVar ) ;
900
- const toLabel = safeLabel ( toType ) ;
901
- const relationshipVariable = safeVar ( fromVar + toVar ) ;
902
- const relationshipLabel = safeLabel ( relationshipName ) ;
903
- const fromRootVariable = safeVar ( '_' + fromVar ) ;
904
- const toRootVariable = safeVar ( '_' + toVar ) ;
905
- const query = `
906
- MATCH (${ fromVariable } :${ fromLabel } {${ fromParam } : $from.${ fromParam } })
907
- MATCH (${ toVariable } :${ toLabel } {${ toParam } : $to.${ toParam } })
920
+ // TODO create builder functions for selection clauses below for both relation mutations
921
+ let query = `
922
+ MATCH (${ fromVariable } :${ fromLabel } ${
923
+ fromTemporalClauses && fromTemporalClauses . length > 0
924
+ // uses either a WHERE clause for managed type primary keys (temporal, etc.)
925
+ ? `) WHERE ${ fromTemporalClauses . join ( ' AND ' ) } `
926
+ // or a an internal matching clause for normal, scalar property primary keys
927
+ : `{${ fromParam } : $from.${ fromParam } })`
928
+ }
929
+ MATCH (${ toVariable } :${ toLabel } ${
930
+ toTemporalClauses && toTemporalClauses . length > 0
931
+ ? `) WHERE ${ toTemporalClauses . join ( ' AND ' ) } `
932
+ : `{${ toParam } : $to.${ toParam } })`
933
+ }
908
934
OPTIONAL MATCH (${ fromVariable } )-[${ relationshipVariable } :${ relationshipLabel } ]->(${ toVariable } )
909
935
DELETE ${ relationshipVariable }
910
936
WITH COUNT(*) AS scope, ${ fromVariable } AS ${ fromRootVariable } , ${ toVariable } AS ${ toRootVariable }
0 commit comments