-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathinternalPlugin.ts
More file actions
40 lines (35 loc) · 1.49 KB
/
internalPlugin.ts
File metadata and controls
40 lines (35 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import type { BaseContext, ApolloServerPlugin } from './externalTypes/index.js';
// This file's exports should not be exported from the overall
// @apollo/server module.
// The internal plugins implement this interface which
// ApolloServer.ensurePluginInstantiation uses to figure out if the plugins have
// already been installed (or explicitly disabled via the matching Disable
// plugins).
export interface InternalApolloServerPlugin<TContext extends BaseContext>
extends ApolloServerPlugin<TContext> {
// Used to identify a few specific plugins that are instantiated
// by default if not explicitly used or disabled.
__internal_plugin_id__(): InternalPluginId;
}
// Helper function for writing internal plugins which lets you write an object
// that is type-checked as InternalApolloServerPlugin but is still only of type
// ApolloServerPlugin (as appropriate for externally-exported plugin-returning
// functions).
export function internalPlugin<TContext extends BaseContext>(
p: InternalApolloServerPlugin<TContext>,
): ApolloServerPlugin<TContext> {
return p;
}
export type InternalPluginId =
| 'CacheControl'
| 'LandingPageDisabled'
| 'SchemaReporting'
| 'InlineTrace'
| 'UsageReporting';
export function pluginIsInternal<TContext extends BaseContext>(
plugin: ApolloServerPlugin<TContext>,
): plugin is InternalApolloServerPlugin<TContext> {
// We could call the function and compare it to the list above, but this seems
// good enough.
return '__internal_plugin_id__' in plugin;
}