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

Cypher filtering 1 to 1 relationships #5723

Merged
merged 20 commits into from
Nov 1, 2024

Conversation

mjfwebb
Copy link
Contributor

@mjfwebb mjfwebb commented Oct 29, 2024

Description

This PR adds the ability to filter on 1 to 1 relationship cypher fields. A contrived example:

Type definitions:

type Movie
    @node
    @authorization(validate: [{ where: { node: { directed_by: { name: "$jwt.custom_value" } } } }]) {
    title: String
    released: Int
    directed_by: Person!
        @cypher(
            statement: """
            MATCH (this)<-[:DIRECTED]-(director:Person)
            RETURN director
            """
            columnName: "director"
        )
}

type Person @node {
    name: String
    directed: Movie!
        @cypher(
            statement: """
            MATCH (this)-[:DIRECTED]->(movie:Movie)
            RETURN movie
            """
            columnName: "movie"
        )
}

You can now query with a filter based on the directed field:

query {
    people(where: { directed: { title: "The Matrix" } }) {
        directed {
            title
            directed_by {
                name
            }
        }
    }
}

Complexity

Medium

Issue

Relates to #554, but not fully closing as this does not n to n relationship fields.

Checklist

The following requirements should have been met (depending on the changes in the branch):

  • Documentation has been updated
  • TCK tests have been updated
  • Integration tests have been updated
  • Example applications have been updated
  • New files have copyright header
  • CLA (https://neo4j.com/developer/cla/) has been signed

Copy link

changeset-bot bot commented Oct 29, 2024

🦋 Changeset detected

Latest commit: 51d9a45

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@neo4j/graphql Minor
@neo4j/graphql-ogm Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@neo4j-team-graphql
Copy link
Collaborator

neo4j-team-graphql commented Oct 29, 2024

Performance Report

No Performance Changes

Show Full Table
name dbHits old dbHits time (ms) old time (ms) maxRows
aggregations.TopLevelAggregate 3404 3404 35 54 1134
aggregations.TopLevelAggregateWithMultipleFields 6802 6802 42 67 1134
aggregations.NestedAggregation 15407 15407 53 73 2174
aggregations.AggregationWithWhere 10833 10833 40 64 2174
aggregations.AggregationWhereWithinNestedRelationships 20097917 20097917 2051 2053 2008534
aggregations.AggregationWhereWithinNestedConnections 20097917 20097917 1989 2028 2008534
aggregations.NestedCountFromMovieToActors 8603 8603 38 38 2174
aggregations.NestedCountFromActorsToMovie 8791 8791 33 38 2174
aggregations.DeeplyNestedCount 10052335 10052335 2741 2816 2008534
aggregations.InterfacesAggregations 6242 6242 42 52 2080
aggregations.InterfacesAggregationsWithTwoFields 11444 11444 72 82 2080
batch-create.BatchCreate 4200 4200 120 164 600
batch-create.BatchCreateSmall 77 77 50 56 11
connect.createAndConnect 6433 6433 156 156 3003
connections.Connection 12951 12951 59 61 2174
connections.NestedConnection 37705 37705 137 147 4516
create.SimpleMutation 7 7 62 62 1
cypher-directive.TopLevelMutationDirective 1135 1135 29 32 1134
delete.SimpleDelete 19401 19401 683 762 1040
delete.NestedDeleteInUpdate 16844 16844 130 147 1183
2871.NestedRelationshipFilter 19632 19632 53 69 4395
2925.SingleRelationshipFilter 5245 5245 38 50 1040
2925.NestedSingleRelationshipFilter 17641 17641 71 98 2174
2925.SingleRelationshipRequiredFilter 5201 5201 40 46 1040
2925.NestedSingleRelationshipRequiredFilter 9361 9361 56 61 1040
query.SimpleQuery 3121 3121 26 29 1040
query.SimpleQueryWithRelationship 15031 15031 41 41 2174
query.QueryWhere 8564 8564 33 42 2154
query.SimpleQueryWithNestedWhere 8713 8713 46 54 2154
query.Nested 10084891 10084891 6796 6965 2008534
query.NestedWithFilter 10064992 10064992 6479 6489 2004000
query.OrFilterOnRelationships 36676 36497 147 234 1937
query.OrFilterOnRelationshipsAndNested 26749 26928 183 208 1937
query.QueryWithNestedIn 14132 14165 102 60 1844
query.NestedConnectionWhere 8703 8703 48 60 2174
query.DeeplyNestedConnectionWhere 8702 8702 73 90 2174
query.DeeplyNestedWithRelationshipFilters 17357 17357 116 151 1552
query.NestedWithRelationshipSingleFilters 3808 3808 151 172 1134
query.Fulltext 64 64 29 37 16
query.FulltextWithNestedQuery 516 516 41 44 84
sorting-and-cypher.TopLevelSortWithCypher 12961 12961 38 47 2174
sorting-and-cypher.TopLevelConnectionSortWithCypher 12961 12961 57 86 2174
sorting-and-cypher.TopLevelSortWithCypherWithNested 13096 13096 55 67 2174
sorting-and-cypher.TopLevelConnectionSortWithCypherWithNested 13096 13096 87 100 2174
sorting-and-cypher.TopLevelSortWithExpensiveCypher 13725 13735 98 134 2174
sorting-and-cypher.TopLevelConnectionSortWithExpensiveCypher 13266 13266 97 151 2174
sorting.SortMultipleTypes 3436 3436 81 95 1040
sorting.SortMultipleTypesWithCypherWithCypher 13321 13321 98 129 2174
sorting.SortOnNestedFields 12951 12951 49 59 2174
sorting.SortDeeplyNestedFields 39785 39785 80 107 4516
sorting.ConnectionWithSort 3271 3271 70 88 1040
unions.SimpleUnionQuery 321 321 64 82 35
unions.SimpleUnionQueryWithMissingFields 293 293 52 76 35
unions.NestedUnion 309975 309975 286 281 33033
unions.NestedUnionWithMissingFields 283949 283949 271 266 33033
update.NestedUpdate 14137 14137 103 111 2002

Old Schema Generation: 29.453s
Schema Generation: 28.149s
Old Subgraph Schema Generation: 31.038s
Subgraph Schema Generation: 30.835s

@mjfwebb mjfwebb marked this pull request as ready for review October 30, 2024 10:38
@mjfwebb mjfwebb changed the title Draft: Cypher filtering 1 to 1 relationships Cypher filtering 1 to 1 relationships Oct 30, 2024
@angrykoala
Copy link
Member

Maybe worth double check by @MacondoExpress as I've contributed to this PR

Copy link
Contributor

@MacondoExpress MacondoExpress left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I left some comments!

Copy link
Contributor

@MacondoExpress MacondoExpress left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mjfwebb mjfwebb merged commit d40590e into neo4j:lts Nov 1, 2024
67 checks passed
mjfwebb added a commit to mjfwebb/graphql that referenced this pull request Nov 1, 2024
…lationships

Cypher filtering 1 to 1 relationships

(cherry picked from commit d40590e)
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

Successfully merging this pull request may close these issues.

4 participants