Skip to content

Certain transforms cannot be used with delegateToSchema because MapFields does not initialize transformers in its ctor #3562

@ntziolis

Description

@ntziolis

As of now when trying to use certain transformers as part of delegateToSchema they will fail as the underlying MapFields requires transformSchema to be called (and delegateToSchema only calls the operational parts of the transform). Namely we were trying to leverage HoistField when extending schema as part of a graphql mesh setup.

To Reproduce

  • Setup a graphql schema + resolvers
  • Use delegateToSchemain one of the resolvers
  • Use HoistField as a transform in the delegateToSchema call
  • Execution will fail as transformSchemahas not been called

Looking at the code, the only reason transformers is not initialized as part of the constructor is the need to know the name of the Subscription type:

typeName = subscriptionTypeName;

Key Question:
Is there any way the above can be avoided or structured differently so we can use transforms that rely on MapFields when using delegateToSchema?

Expected behavior

  • Transforms should initialize correctly independent from calling transformSchema
  • Since MapFields is used in many of them it would make sense to remove the dependency on transformSchema being called first.
  • This way they can be used as transforms in delegateToSchema calls

Environment:

Additional context
As of right now we are creating an instance of hoist field and call transformSchema manually before passing the instance into the delegateToSchema transforms array. It does work, but is obviously not the original intend. In addition it hurts performance as I happens each time the resolver is called.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions