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

Alias is not working on "wrapper" fields #5584

Open
Andy2003 opened this issue Sep 20, 2024 · 6 comments
Open

Alias is not working on "wrapper" fields #5584

Andy2003 opened this issue Sep 20, 2024 · 6 comments
Labels
bug Something isn't working confirmed Confirmed bug

Comments

@Andy2003
Copy link
Contributor

Its not possible to add an alias to each level of the projection.

Type definitions

type Movie {
  title: String!
  actors: [Actor!]! @relationship(type: "ACTED_IN", properties: "ActedIn", direction: IN)
}

type Actor {
  name: String!
  movies: [Movie!]! @relationship(type: "ACTED_IN", properties: "ActedIn", direction: OUT)
}

type ActedIn @relationshipProperties {
  screenTime: Int!
}

To Reproduce

Run the query

{
                movies(where: { title: "The Matrix" }) {
                    title1: title
                    actorsConnection1: actorsConnection(where: { node: { name: "Keanu Reeves" } }) {
                        edges1: edges {
                            properties1: properties {
                                screenTime1: screenTime
                            }
                            node1: node {
                                name1: name
                                b: moviesConnection(where: { node: { title: "The Matrix"}}) {
                                    edges2: edges {
                                        node2: node {
                                            title2: title
                                            a: actors {
                                                name2: name
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

Error: Cannot read properties of undefined (reading 'edges')

Additional context

Aliases are currently not supported at "wrapper" fields. I think this is a low priority bug, but since the grapqhl spec allows aliases on each field, we should support these cases as well.

@Andy2003 Andy2003 added the bug Something isn't working label Sep 20, 2024
@angrykoala
Copy link
Member

Hi @Andy2003
Thanks for your report, I went ahead and wrote a test to validate and it seems to be working as expected. Which version of neo4j/graphql are you using?

You can check the test here to make sure I didn't misinterpreted your reproduction steps

@angrykoala angrykoala added the unreproducible Based on the information given, unable to reproduce at this time label Sep 23, 2024
@Andy2003
Copy link
Contributor Author

It seems to be a typing issue on my side, your test is valid and it is working as expected!

@angrykoala angrykoala linked a pull request Sep 23, 2024 that will close this issue
@Andy2003
Copy link
Contributor Author

But if you adjust the query to be even more fancy: you will get an error:

            query {
                ${Movie.plural}(where: { title: "The Matrix" }) {
                    title1: title
                    actorsConnection1: actorsConnection(where: { node: { name: "Keanu Reeves" } }) {
                        edges1: edges {
                            node1: node {
                                nameA1: name
                                A1: moviesConnection(where: { node: { title: "Foo" } }) {
                                    edges2: edges {
                                        node2: node {
                                            title2: title
                                            a: actors {
                                                name2: name
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        edges2: edges {
                            node1: node {
                                nameA2: name
                                A2: moviesConnection(where: { node: { title: "The Matrix" } }) {
                                    edges2: edges {
                                        node2: node {
                                            title2: title
                                            a: actors {
                                                name2: name
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

Received: [[GraphQLError: Cannot return null for non-nullable field RqZuCzQTMovieActorsConnection.edges.]]

at Object.<anonymous> (/neo4j-graphql-2/packages/graphql/tests/integration/issues/5584.int.test.ts:104:33)
at processTicksAndRejections (node:internal/process/task_queues:95:5)

@Andy2003
Copy link
Contributor Author

Andy2003 commented Sep 23, 2024

I was miss-leaded by the generated cypher. There is this fallback

export function defaultFieldResolver(source, args, context: Neo4jGraphQLContext, info: GraphQLResolveInfo) {
which maps fields to its alias.

But this does not work in the code I provided in the previous comment

@Andy2003 Andy2003 reopened this Sep 23, 2024
@angrykoala angrykoala added confirmed Confirmed bug and removed unreproducible Based on the information given, unable to reproduce at this time labels Sep 23, 2024
@neo4j-team-graphql
Copy link
Collaborator

We've been able to confirm this bug using the steps to reproduce that you provided - many thanks @Andy2003! 🙏 We will now prioritise the bug and address it appropriately.

@angrykoala
Copy link
Member

After tinkering a bit with this. The problem is caused by the translation not applying the edge alias, meaning that it only generates 1 set of edges instead of 2. This can be replicated with a simpler query:

query {
    movies(where: { title: "The Matrix" }) {
        title1: title
        actorsConnection1: actorsConnection(where: { node: { name: "Keanu Reeves" } }) {
            edges1: edges {
                node1: node {
                    nameA1: name
                }
            }
            edges2: edges {
                node1: node {
                    nameA2: name
                }
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working confirmed Confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants