graphql-hive / graphql-hive/envelop

[core] Add an option for disallowing `useOnResolve` usage

Open
#2,225 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
No language data
Stars
827
Forks
132
PR merge metrics
No merged PRs in 30d

Description

## Context

In the past, Envelop allowed to hook into the execution at resolver level, meaning plugin was able to replace or wrap any resolver.
This was causing performance issues, since wrapping every resolver added a significant overhead.

To circumvent this issue, we removed this `onResolve` hook and replaced it by a plugin `useOnResolve`, which wraps each resolvers only when used, meaning other users doesn't have perf issues for this feature.

But it turns out we think this should not be part of Envelop at all. Envelop is meant as a runtime plugin system. This means that schema modifications should happen at schema build time, and wrapping resolvers is a schema modification.

Since this change is a breaking change and will need the refactoring of multiple plugins, it will takes time. Meanwhile, we should allow users or library maintainers using Envelop to enforce the fact the schema is not mutated during Envelop execution.

## Solution

Add an option to Envelop to globally disallow the usage of `useOnResolve`. If this option is enabled, `useOnResolve` should throw a comprehensive error. It could also be a good thing to make this error message configurable, so that library maintainers can explain why this plugin is disallowed.

## Alternatives

An alternative could be to freeze the schema object. But this has a cost, and the error will not be clear from a user perspective.

## Additional context

This is not a perfect solution, but it's mean to gracefully guide users and library maintainers towards the removal of `useOnResolve`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.