Skip to content
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

Introduce an internal plugin test harness to facilitate plugin testing. #3990

Conversation

abernix
Copy link
Member

@abernix abernix commented Apr 15, 2020

This test harness is meant to avoid the need to do the more heavy execution which the request pipeline itself does within processGraphQLRequest when we test some of our internal plugins.

I'm not prepared to make this a public-facing harness in its current state, but I have reason to believe that it could be beneficial for external plugin authors to take advantage of something like this - possibly within the context of apollo-server-plugin-base.

There's perhaps a best-of-both-worlds approach here where the request pipeline could be tested against a more precise plugin API contract, but I'm deferring until later for now. As it stands right now, this was a requisite for doing the migrations of the apollo-engine-reporting and apollo-cache-control extensions over to the new plugin API.

Actual usages of this will be seen in those upcoming PRs.

This test harness is meant to avoid the need to do the more heavy execution
which the request pipeline itself does within `processGraphQLRequest`.

I'm not prepared to make this a public-facing harness just yet, but I have
reason to believe that it could be beneficial for external plugin authors to
take advantage of something like this - possibly within the context of
`apollo-server-plugin-base`.

There's perhaps a best-of-both-worlds approach here where the request
pipeline could be tested against a more precise plugin API contract, but I'm
deferring that work for now.
@abernix abernix force-pushed the abernix/introduce-internal-plugin-testing-harness branch from 79db8d8 to ab3855d Compare April 15, 2020 18:03
@abernix abernix changed the base branch from abernix/graphql-extensions-deprecation-staging to abernix/add-willResolveField-and-didResolveField April 15, 2020 18:04
@abernix abernix self-assigned this Apr 15, 2020
@abernix abernix added this to the Release 2.13.0 milestone Apr 15, 2020
Copy link
Member

@trevor-scheer trevor-scheer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, looks like it'll be handy!

packages/apollo-server-core/src/utils/pluginTestHarness.ts Outdated Show resolved Hide resolved
@abernix abernix merged commit eec87a6 into abernix/add-willResolveField-and-didResolveField Apr 16, 2020
@abernix abernix deleted the abernix/introduce-internal-plugin-testing-harness branch April 16, 2020 09:58
abernix added a commit that referenced this pull request Apr 16, 2020
…o it.

Similar to 6009d8a, which migrated the tracing package to the plugin
API, this commit introduces a `plugin` (named) export from the
`apollo-cache-control` module.  It similarly accomplishes that by
duplicating the behavior of the `CacheControlExtension` which leveraged the
soon-to-be-deprecated `graphql-extensions`.  The functionality, again, is
intended to be identical in spirit.

Since the delta of the commits was otherwise even _more_ confusing, I've
left the `CacheControlExtension` present and exported and will remove it in a
subsequent commit.

Briefly summarizing what the necessary changes were:

1. We no longer use a class instance to house the extension, which was
   necessitated by the `graphql-extensions` API.  This means that uses of
   `this` have been replaced with function scoped variables by the same name.
2. The logic which actually does the formatting (previously handled by the
   `format` method in `graphql-extension`, now takes place within the plugin
   API's `willSendResponse` method.
3. Rather than leaning on plugin-specific behavior from within the request
   pipeline, the `apollo-cache-control` plugin now makes a number of
   assertions throughout its various life-cycle methods to ensure that the
   `overallCachePolicy` is calculated.
4. Switch tests to use the new `pluginTestHarness` method for testing
   plugins which was introduced in eec87a6 (#3990).
abernix added a commit that referenced this pull request Apr 16, 2020
…o it.

Similar to 6009d8a, which migrated the tracing package to the plugin
API, this commit introduces a `plugin` (named) export from the
`apollo-cache-control` module.  It similarly accomplishes that by
duplicating the behavior of the `CacheControlExtension` which leveraged the
soon-to-be-deprecated `graphql-extensions`.  The functionality, again, is
intended to be identical in spirit.

Since the delta of the commits was otherwise even _more_ confusing, I've
left the `CacheControlExtension` present and exported and will remove it in a
subsequent commit.

Briefly summarizing what the necessary changes were:

1. We no longer use a class instance to house the extension, which was
   necessitated by the `graphql-extensions` API.  This means that uses of
   `this` have been replaced with function scoped variables by the same name.
2. The logic which actually does the formatting (previously handled by the
   `format` method in `graphql-extension`, now takes place within the plugin
   API's `willSendResponse` method.
3. Rather than leaning on plugin-specific behavior from within the request
   pipeline, the `apollo-cache-control` plugin now makes a number of
   assertions throughout its various life-cycle methods to ensure that the
   `overallCachePolicy` is calculated.
4. Switch tests to use the new `pluginTestHarness` method for testing
   plugins which was introduced in eec87a6 (#3990).
abernix added a commit that referenced this pull request Apr 16, 2020
…o it.

Similar to 6009d8a, which migrated the tracing package to the plugin
API, this commit introduces a `plugin` (named) export from the
`apollo-cache-control` module.  It similarly accomplishes that by
duplicating the behavior of the `CacheControlExtension` which leveraged the
soon-to-be-deprecated `graphql-extensions`.  The functionality, again, is
intended to be identical in spirit.

Since the delta of the commits was otherwise even _more_ confusing, I've
left the `CacheControlExtension` present and exported and will remove it in a
subsequent commit.

Briefly summarizing what the necessary changes were:

1. We no longer use a class instance to house the extension, which was
   necessitated by the `graphql-extensions` API.  This means that uses of
   `this` have been replaced with function scoped variables by the same name.
2. The logic which actually does the formatting (previously handled by the
   `format` method in `graphql-extension`, now takes place within the plugin
   API's `willSendResponse` method.
3. Rather than leaning on plugin-specific behavior from within the request
   pipeline, the `apollo-cache-control` plugin now makes a number of
   assertions throughout its various life-cycle methods to ensure that the
   `overallCachePolicy` is calculated.
4. Switch tests to use the new `pluginTestHarness` method for testing
   plugins which was introduced in eec87a6 (#3990).
@abernix abernix added the 🔌 plugins Relates to the request pipeline plugin API label May 8, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🔌 plugins Relates to the request pipeline plugin API 🧪 testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants