Skip to content

'find' projection includes 'edges' and 'count' fields #4

Closed
@yoadsn

Description

@yoadsn

Well, best connection implementation I have seen so far! I must say I did not completely understand yet all the logic that went into this but the stable cursors are brilliant.

I have noticed that the find query of the connection resolve is projecting also the count and edges fields. (which would not make sense of course on a 'relay' type of connection where they have a different semantic meaning)
The reason for that is probably at the connectionResolver.js file here:
https://github.com/nodkz/graphql-compose-connection/blob/86ddc88dcce544e1579494072c5d7fb72ffad44a/src/connectionResolver.js#L126

Where the top level projection is combined with the node specific projection. This is to account for some middleware adding fields via the resolveParams object. (According to the comment)

I think the workaround should be to omit the specific known fields from this top level projection when combining. Maybe add after line 128:

delete findManyParams.projection.count;
delete findManyParams.projection.edges;

Although it's not "pretty" - it should do the trick.

This is also related to another behavior which is unexpected (should I open another issue?) - if only asking for the count field of the connection - a find is also issued, again with the count field projected. this is due to:

https://github.com/nodkz/graphql-compose-connection/blob/86ddc88dcce544e1579494072c5d7fb72ffad44a/src/connectionResolver.js#L130

Which again uses the top level projection and later issues a find even if only count is needed. this could be optimized by checking if the projection only contains the count and avoiding a find altogether.

Maybe I have misunderstood the purpose of this logic?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions