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

nodes field incompatible with custom edge #434

Closed
imkh opened this issue Apr 12, 2022 · 1 comment · Fixed by #435
Closed

nodes field incompatible with custom edge #434

imkh opened this issue Apr 12, 2022 · 1 comment · Fixed by #435

Comments

@imkh
Copy link

imkh commented Apr 12, 2022

The addition of the nodes field in #432 is a super useful change when working on the frontend side, but unfortunately it doesn't work great when using custom edges.

With custom edges, the nodes field contains an array of the records instead of an array of the node specified in recordToEdge:

  {
    recordToEdge: (record) => ({
      node: record.foo,
      extraEdgeField: 'Bar',
    }),
  }

The typing of nodes is correct, but not the actual value inside.

This use case is bit more complex so I wasn't able to find the change necessary to make things work 😕

In the meantime, I use this workaround:

const result = await findManyCursorConnection...

result.nodes = result.edges.map((edge) => edge.node);

return result;

Also, I notice that the hasRequestedField when requesting all records wasn't updated to check for nodes. Right now, it only checks for edges and totalCount.

} else {
// Execute the underlying query operations
records = hasRequestedField('edges') ? await findMany({}) : []
totalCount = hasRequestedField('totalCount') ? await aggregate() : -1
// Since we are getting all records, there are no pages
hasNextPage = false
hasPreviousPage = false
}

@queicherius
Copy link
Member

Thank you! Fixed via https://github.com/devoxa/prisma-relay-cursor-connection/releases/tag/v2.2.1

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 a pull request may close this issue.

2 participants