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
Prisma connection resolves nodes even when querying only totalCount #989
Comments
this is a bit tricky, as there are many potential ways that optimizing this could inadvertently break things. A simple example would be adding additional fields or auth checks to the connection object. Similarly if you have a Definitely open to a PR for this. This would likely just be implemented by checking for what fields are selected using the |
thanks for fixing this! |
@hayes I just noticed that this introduced a regression for a specific use case
query AppQuery {
user {
files {
totalCount
}
...App_node
}
}
fragment App_node on Node {
... on User {
id
files {
edges {
node {
name
size
}
}
}
}
} |
this is an interesting combination of things I think. I think this was more of a case of uncovering/worsening a previous bug. I suspect that these fragments on an abstract type never worked correctly, but would work previously for 1 of 2 reasons:
either way, the query would resolve correctly (but maybe not efficiently). Now we are probably incorrectly marking the relation as loaded, causing the query to fail. Should be fixable, but will take some debugging |
@hayes shall we reopen this or create a new issue for it? |
Probably should be a new issue |
There are a few places throughout the query mapping like https://github.com/hayes/pothos/blob/main/packages/plugin-prisma/src/util/map-query.ts#L171 where we check that the fragment for the expected type. I think this breaks cases where you use a fragment for an abstract type, and then select the concrete type inside. I think the check for only total count looks at info.fieldNodes[0] and probably needs to account for all nodes instead |
The Prisma plugin enables using a prismaConnection with a
totalCount
function for loading the total count for the connection. This works great and is useful for containing all info for a relation within the same connection.However, I recently noticed that even when only querying the
totalCount
for the connection, it still executes the resolver that fetches the edges. And I was wondering if it was possible to avoid that and only execute thetotalCount
resolver.Following, there is an example based on my current code and an example query. Looking forward to get others thoughts and also open to contribute with a PR.
The text was updated successfully, but these errors were encountered: