Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

Fixes #295: Querying interface @relation fields with non-unique relationship names #366

Merged
merged 2 commits into from
Dec 31, 2019

Conversation

michaeldgraham
Copy link
Collaborator

@michaeldgraham michaeldgraham commented Dec 31, 2019

Issue #295 resulted from no label being added to the Cypher path pattern for related nodes being matched when querying an interface type @relation field. To make the path pattern more specific and prevent matching inappropriate nodes, the interface type name is now added as a label.

For example, given the following schema:

interface Tools {
  id: ID
}
type Screwdriver implements Tools {
  id: ID
  size: Int!
}
type Material {
  id: ID!
}
type Product {
  materials: [Material!]! @relation(name: "USES", direction: OUT)
  tools: [Tools!]! @relation(name: "USES", direction: OUT)
}

And this query over the tools interface type @relation field:

query {
  Product {
    tools {
      id
    }
  }
}

Current translation:

MATCH (`product`:`Product`) RETURN `product` {tools: [(`product`)-[:`USES`]->(`product_tools`) | product_tools {FRAGMENT_TYPE: head( [ label IN labels(product_tools) WHERE label IN $Tools_derivedTypes ] ),  .id }] } AS `product`

Translation with the fix:

MATCH (`product`:`Product`) RETURN `product` {tools: [(`product`)-[:`USES`]->(`product_tools`:`Tools`) | product_tools {FRAGMENT_TYPE: head( [ label IN labels(product_tools) WHERE label IN $Tools_derivedTypes ] ),  .id }] } AS `product`

In this translation, tools: [(`product`)-[:`USES`]->(`product_tools`) becomes tools: [(`product`)-[:`USES`]->(`product_tools`:`Tools`).

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Upstream merge
removed a branch that prevented normal labeling behavior from being applied when matching related interface type nodes
@codecov-io
Copy link

codecov-io commented Dec 31, 2019

Codecov Report

Merging #366 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master    #366   +/-   ##
======================================
  Coverage    96.3%   96.3%           
======================================
  Files          24      24           
  Lines        2844    2844           
======================================
  Hits         2739    2739           
  Misses        105     105
Impacted Files Coverage Δ
src/translate.js 98.31% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5a2e52e...0c09873. Read the comment docs.

@johnymontana johnymontana merged commit 588b6e3 into neo4j-graphql:master Dec 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants