Skip to content

Support for non node types on cypher directives #6199

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

angrykoala
Copy link
Member

Description

Add support for @cypher directive of fields targeting types that do not use the @node directive. For example:

type Movie @node {
    title: String
    id: String!
    link: Link!
        @cypher(
            statement: """
            MATCH(l:${Link})
            WHERE l.movieId=this.id
            RETURN l {.name, .url} as link
            """
            columnName: "link"
        )
}

type Link {
    movieId: String!
    url: String!
    name: String!
}

This approach has some limitations, particularly with non-node interfaces and unions

Copy link

changeset-bot bot commented Apr 10, 2025

🦋 Changeset detected

Latest commit: 944c8f6

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

This PR includes changesets to release 1 package
Name Type
@neo4j/graphql 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

@angrykoala angrykoala force-pushed the support-custom-cypher-types branch from 944c8f6 to 739025c Compare April 10, 2025 12:09
Copy link
Contributor

@darrellwarde darrellwarde left a comment

Choose a reason for hiding this comment

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

Some comments to think about?

Comment on lines +209 to +211
/**
* Interfaces without `@node` are not supported yet because there is no way to access "__resolveTree", as the information of the concrete type returned by the cypher field is not available
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

What will happen in this case? Will we throw a validation error? Or just some weird indecipherable error?

const Movie = testHelper.createUniqueType("Movie");

const typeDefs = /* GraphQL */ `
type Movie @node {
Copy link
Contributor

Choose a reason for hiding this comment

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

@node shouldn't he here right?

Suggested change
type Movie @node {
type Movie {

Comment on lines +44 to +48
type ${Link} {
movieId: String!
url: String!
name: String!
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How about this kind of case where the Cypher might return a more complex object?

Suggested change
type ${Link} {
movieId: String!
url: String!
name: String!
}
type ${Link} {
movieId: String!
url: String!
name: String!
somethingElse: SomethingElse!
}
type ${SomethingElse} {
something: String!
}

Comment on lines -144 to -146
if (attributeType instanceof InterfaceEntity || attributeType instanceof UnionEntity) {
throw new Error("@cypher field target cannot be an interface or an union");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should be keeping this given the skipped test?

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

Successfully merging this pull request may close these issues.

3 participants