Skip to content

Bug: Filtering on children through parent fields generates logically invalid cypher #65

Closed
@Moro-Code

Description

@Moro-Code

Here are two type definitions I have

type SurveyTemplate{
  uid: ID!
  surveyTemplate: String!
  versionNumber: Int
  evalese: String! 
  createdAt: DateTime
  responses: [SurveyResponse] @relation(name: "SURVEY_RESPONSE", direction: "OUT")
}

type SurveyResponse{
  uid: ID!
  rawData: String!
  processedData: String
  createdAt: DateTime
  startedOn: DateTime
  completedOn: DateTime
  surveyTemplate: SurveyTemplate @relation(name: "SURVEY_RESPONSE", direction: "IN")
}

To give a quick summary of these two type definitions. A SurveyTemplate is a node with many SurveyResponse children connected with SURVEY_RESPONSE relationship.

Now say I have a SurveyTemplate Node with two SurveyResponse children.

I want to use the following query with the SurveyResponse query type where I am using the filter to get all SurveyResponse nodes that has a SurveyTemplate with a specific UID ( see type definition )

query{
  SurveyResponse(filter: {surveyTemplate: {uid: "fc16cc48-d0cd-46e5-93f5-61ea48e1b568"}}){
    uid
  }
}

This generates the following cypher

MATCH (`surveyResponse`:`SurveyResponse`) WHERE (EXISTS((`surveyResponse`)<-[:SURVEY_RESPONSE]-(:SurveyTemplate)) AND ALL(`surveytemplate` IN [(`surveyresponse`)<-[:SURVEY_RESPONSE]-(`_surveytemplate`:SurveyTemplate) | `_surveytemplate`] WHERE (`surveytemplate`.uid = $filter.surveyTemplate.uid))) RETURN `surveyResponse` { .processedData } AS `surveyResponse`

with the following variables

{
 "offset": 0,
 "first": -1,
  "filter": {
     "surveyTemplate": {
    "uid": "fc16cc48-d0cd-46e5-93f5-61ea48e1b568"
 }
 }
 }

This cypher results in no results being returned beyond if there are two or more SurveyResponse children. I suspect it's because of the incorrect use of ALL in the WHERE statement of the query

According to the neo4j docs

all() returns true if the predicate holds for all elements in the given list. null is returned if the list is null or all of its elements are null

If there is more than one SurveyTemplate parent then the following statesmen will return null

ALL(`surveytemplate` IN [(`surveyresponse`)<-[:SURVEY_RESPONSE]-(`_surveytemplate`:SurveyTemplate) | `_surveytemplate`] WHERE (`surveytemplate`.uid = $filter.surveyTemplate.uid))

Is this the intended behavior or am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions