@envelop/on-resolve 4.0.0 → 4.1.0-alpha-20231017135127-dcc5719a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/index.js CHANGED
@@ -7,7 +7,7 @@ const graphql_1 = require("graphql");
7
7
  *
8
8
  * Use the `onResolve` argument to manipulate the resolver and its results/errors.
9
9
  */
10
- function useOnResolve(onResolve) {
10
+ function useOnResolve(onResolve, opts = { skipIntrospection: true }) {
11
11
  const hasWrappedResolveSymbol = Symbol('hasWrappedResolve');
12
12
  return {
13
13
  onSchemaChange({ schema: _schema }) {
@@ -15,7 +15,7 @@ function useOnResolve(onResolve) {
15
15
  if (!schema)
16
16
  return; // nothing to do if schema is missing
17
17
  for (const type of Object.values(schema.getTypeMap())) {
18
- if (!(0, graphql_1.isIntrospectionType)(type) && (0, graphql_1.isObjectType)(type)) {
18
+ if ((!opts.skipIntrospection || !(0, graphql_1.isIntrospectionType)(type)) && (0, graphql_1.isObjectType)(type)) {
19
19
  for (const field of Object.values(type.getFields())) {
20
20
  if (field[hasWrappedResolveSymbol])
21
21
  continue;
package/esm/index.js CHANGED
@@ -4,7 +4,7 @@ import { defaultFieldResolver, isIntrospectionType, isObjectType, } from 'graphq
4
4
  *
5
5
  * Use the `onResolve` argument to manipulate the resolver and its results/errors.
6
6
  */
7
- export function useOnResolve(onResolve) {
7
+ export function useOnResolve(onResolve, opts = { skipIntrospection: true }) {
8
8
  const hasWrappedResolveSymbol = Symbol('hasWrappedResolve');
9
9
  return {
10
10
  onSchemaChange({ schema: _schema }) {
@@ -12,7 +12,7 @@ export function useOnResolve(onResolve) {
12
12
  if (!schema)
13
13
  return; // nothing to do if schema is missing
14
14
  for (const type of Object.values(schema.getTypeMap())) {
15
- if (!isIntrospectionType(type) && isObjectType(type)) {
15
+ if ((!opts.skipIntrospection || !isIntrospectionType(type)) && isObjectType(type)) {
16
16
  for (const field of Object.values(type.getFields())) {
17
17
  if (field[hasWrappedResolveSymbol])
18
18
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envelop/on-resolve",
3
- "version": "4.0.0",
3
+ "version": "4.1.0-alpha-20231017135127-dcc5719a",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "@envelop/core": "^5.0.0",
@@ -14,9 +14,17 @@ export interface OnResolveOptions<PluginContext extends Record<string, any> = {}
14
14
  replaceResolver: (newResolver: Resolver<PluginContext>) => void;
15
15
  }
16
16
  export type OnResolve<PluginContext extends Record<string, any> = {}> = (options: OnResolveOptions<PluginContext>) => PromiseOrValue<AfterResolver | void>;
17
+ export type UseOnResolveOptions = {
18
+ /**
19
+ * Skip executing the `onResolve` hook on introspection queries.
20
+ *
21
+ * @default true
22
+ */
23
+ skipIntrospection?: boolean;
24
+ };
17
25
  /**
18
26
  * Wraps the provided schema by hooking into the resolvers of every field.
19
27
  *
20
28
  * Use the `onResolve` argument to manipulate the resolver and its results/errors.
21
29
  */
22
- export declare function useOnResolve<PluginContext extends Record<string, any> = {}>(onResolve: OnResolve<PluginContext>): Plugin<PluginContext>;
30
+ export declare function useOnResolve<PluginContext extends Record<string, any> = {}>(onResolve: OnResolve<PluginContext>, opts?: UseOnResolveOptions): Plugin<PluginContext>;
@@ -14,9 +14,17 @@ export interface OnResolveOptions<PluginContext extends Record<string, any> = {}
14
14
  replaceResolver: (newResolver: Resolver<PluginContext>) => void;
15
15
  }
16
16
  export type OnResolve<PluginContext extends Record<string, any> = {}> = (options: OnResolveOptions<PluginContext>) => PromiseOrValue<AfterResolver | void>;
17
+ export type UseOnResolveOptions = {
18
+ /**
19
+ * Skip executing the `onResolve` hook on introspection queries.
20
+ *
21
+ * @default true
22
+ */
23
+ skipIntrospection?: boolean;
24
+ };
17
25
  /**
18
26
  * Wraps the provided schema by hooking into the resolvers of every field.
19
27
  *
20
28
  * Use the `onResolve` argument to manipulate the resolver and its results/errors.
21
29
  */
22
- export declare function useOnResolve<PluginContext extends Record<string, any> = {}>(onResolve: OnResolve<PluginContext>): Plugin<PluginContext>;
30
+ export declare function useOnResolve<PluginContext extends Record<string, any> = {}>(onResolve: OnResolve<PluginContext>, opts?: UseOnResolveOptions): Plugin<PluginContext>;