I am trying to pass an array to form multiple relationships from a node I am creating to multiple other nodes. So far, I am only using the default resolvers created by the neo4j graphql library.
More specifically, I am trying to pass an array "broaderConceptsV" which is an array of objects in the form [{uid1: ___ , name1: ___ }, {uid2: ___ , name2: ___ }, ... ] while creating a new concept node to create multiple IS_NARROWER relationships to other existing concept nodes.
The set-up below works if there is only one object in the broaderConceptsV array, but if the broaderConceptsV array is empty it creates an IS_NARROWER relationship to every existing node, and if the broaderConceptsV array has multiple objects, no relationships are created but the new concept node is still created.
Any help is appreciated! I think the issue lies in how the AND: variable in the ConceptWhere input, but I do not understand how I would loop through the array if I input it differently.
Edit: Changing out "AND:" for "OR:" fixed the multiple object case, but passing an empty array still forms a connection with every existing node
This is my schema:
const typeDefs = gql`
type Concept {
uid: ID!
name: String!
block: String!
addedBy: String!
methodVideos: [Video!]! @relationship(type: "IS_METHOD", direction: IN, properties: "IsMethod")
interestVideos: [Video!]! @relationship(type: "IS_INTEREST", direction: IN)
narrowerConcepts: [Concept!]! @relationship(type: "IS_NARROWER", direction: OUT)
broaderConcepts: [Concept!]! @relationship(type: "IS_NARROWER", direction: IN)
}
This is the mutation I was trying to get working:
const ADD_CONCEPT = gql`
mutation AddConcept(
$uid: ID!
$name: String!
$block: String!
$addedBy: String!
$broaderConcepts: [ConceptWhere!]
) {
createConcepts(
input: [
{
uid: $uid
name: $name
block: $block
addedBy: $addedBy
broaderConcepts: { connect: { where: { node: { AND: $broaderConcepts } } } }
}
]
) {
concepts {
uid
name
block
addedBy
}
}
}
`;
This is the how I set up createConcepts:
createConcepts({
variables: {
uid: uuidv4(),
name: nameRef.current.value,
block: blockV,
addedBy: user.uid,
broaderConcepts: broaderConceptsV,
},
Some relevant pieces from the augmented schema as seen in the Apollo client:
type Mutation {
createConcepts(input: [ConceptCreateInput!]!): CreateConceptsMutationResponse!
}
input ConceptCreateInput {
uid: ID!
name: String!
block: String!
addedBy: String!
methodVideos: ConceptMethodVideosFieldInput
interestVideos: ConceptInterestVideosFieldInput
narrowerConcepts: ConceptNarrowerConceptsFieldInput
broaderConcepts: ConceptBroaderConceptsFieldInput
}
input ConceptBroaderConceptsFieldInput {
create: [ConceptBroaderConceptsCreateFieldInput!]
connect: [ConceptBroaderConceptsConnectFieldInput!]
}
input ConceptBroaderConceptsConnectFieldInput {
where: ConceptConnectWhere
connect: [ConceptConnectInput!]
}
input ConceptConnectWhere {
node: ConceptWhere!
}
input ConceptConnectInput {
methodVideos: [ConceptMethodVideosConnectFieldInput!]
interestVideos: [ConceptInterestVideosConnectFieldInput!]
narrowerConcepts: [ConceptNarrowerConceptsConnectFieldInput!]
broaderConcepts: [ConceptBroaderConceptsConnectFieldInput!]
}
input ConceptWhere {
OR: [ConceptWhere!]
AND: [ConceptWhere!]
uid: ID
uid_NOT: ID
uid_IN: [ID!]
uid_NOT_IN: [ID!]
uid_CONTAINS: ID
uid_NOT_CONTAINS: ID
uid_STARTS_WITH: ID
uid_NOT_STARTS_WITH: ID
uid_ENDS_WITH: ID
uid_NOT_ENDS_WITH: ID
name: String
name_NOT: String
name_IN: [String!]
name_NOT_IN: [String!]
name_CONTAINS: String
name_NOT_CONTAINS: String
name_STARTS_WITH: String
name_NOT_STARTS_WITH: String
name_ENDS_WITH: String
name_NOT_ENDS_WITH: String
block: String
block_NOT: String
block_IN: [String!]
block_NOT_IN: [String!]
block_CONTAINS: String
block_NOT_CONTAINS: String
block_STARTS_WITH: String
block_NOT_STARTS_WITH: String
block_ENDS_WITH: String
block_NOT_ENDS_WITH: String
addedBy: String
addedBy_NOT: String
addedBy_IN: [String!]
addedBy_NOT_IN: [String!]
addedBy_CONTAINS: String
addedBy_NOT_CONTAINS: String
addedBy_STARTS_WITH: String
addedBy_NOT_STARTS_WITH: String
addedBy_ENDS_WITH: String
addedBy_NOT_ENDS_WITH: String
methodVideos: VideoWhere @deprecated(reason: "Use `methodVideos_SOME` instead.")
methodVideos_NOT: VideoWhere @deprecated(reason: "Use `methodVideos_NONE` instead.")
methodVideosAggregate: ConceptMethodVideosAggregateInput