Skip to content

Projection of the edges field on wrapped type #75

Open
@yoadsn

Description

@yoadsn

@nodkz Funny - we talked about this already back in 2016 :)
So now that the mongoose composter flattens the projection to improve performance - it also flattens the non required fields from the connection structure.

This means that for schema Post { title } and User { posts } where posts is a connection you would get for a query:
{ user { posts { edges { node { title } } } } }

This projection on mongodb "posts" collection find:
{ 'edges.node.title': true, title: true }

Also, on the "users" collection you can expect this find projection:
{'posts.edges.nodes.title': true }

This used to be a small problem since there was no "flattening" so "edges" would be the only wrong field used. now it's much more. The more fields are used from the connected type the more duplication exists. I am not sure if mongodb has any performance implications but it might.

Since i know for sure my schema is not using "edges" and "node" fields on internal types - I wanted to remove this.
I thought of working around this in multiple ways:

  • Wrapping the resolver for the "find user" and clearing the "posts" field from the projection sent to the resolver. (of course working on a copy of RP). This works, and I can think of a way to build a generic wrapper.
  • Wrapping findMany of the connection is not possible since there is only way to provide customization opts to connection resolver factory.
  • No customization to connection resolver factory allows the ability to "let the connection" know those fields are "OK" to be removed before using them on the findMany resolver. For example I would make up a parameter like allowEdgeNodeFieldsInProjection which by default is off.

What do you think - I revisited all the code involved but could not find a very clean way to let the projection ignore those fields - it must be the responsibility of the "connection" plugin I feel.

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