Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filters on one-to-many relationship existence #177

Open
nmonterroso opened this issue May 3, 2019 · 1 comment
Open

filters on one-to-many relationship existence #177

nmonterroso opened this issue May 3, 2019 · 1 comment

Comments

@nmonterroso
Copy link

Similar to neo4j-graphql-java#27.

Is it possible to use filter that says "where an array field is non-empty"? For example this schema:

type Person {
	name: String!
	friends: [Person!]! @relation(name:"knows",direction:OUT)
	pets: [Pet!] @relation(name:"knows",direction:OUT)
}

type Pet {
	name: String!
}

on a db with:

create(n1:Person {name:"foo"}),
	(n2:Person {name:"bar"}),
	(n3:Pet {name:"baz"}),
	(n1)-[:knows]->(n2),
	(n2)-[:knows]->(n3)

I'm struggling to come up with a filter that only returns the Persons that have at least one [:knows]-(:Person) relationship. Based on the generated cypher It seems like friends_not: null is the intended way to do this:

MATCH (`person`:`Person`)
WHERE ( (`person`)-[:`knows`]->())
RETURN graphql.labels(`person`) AS `_labels`,
`person`.`name` AS `name`,
[ (`person`)-[:`knows`]->(`person_friends`:`Person`)  | `person_friends` {`_labels` : graphql.labels(`person_friends`), .`name`}] AS `friends`,
[ (`person`)-[:`knows`]->(`person_pets`:`Pet`)  | `person_pets` {`_labels` : graphql.labels(`person_pets`), .`name`}] AS `pets`

The key being WHERE ( (person)-[:knows]->()) but since the second node doesn't have a label the following query:

{
  Person (filter: { friends_not: null}) {
    name
    friends {
      name
    }
    pets {
      name
    }
  }
}

gives me:

    "Person": [
      {
        "name": "foo",
        "friends": [
          {
            "name": "bar"
          }
        ],
        "pets": []
      },
      {
        "name": "bar",
        "friends": [],
        "pets": [
          {
            "name": "baz"
          }
        ]
      }
    ]
@jexp
Copy link
Contributor

jexp commented Jun 19, 2019

Can you try to use:

friends_some : { name_not: null }

Currently there is no generic, "does exist"
But it's a good idea to add.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants