Skip to content

Enables support for resolver extensions for compatibility with grafast, complexity, etc. #2618

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

vlad-x
Copy link

@vlad-x vlad-x commented Jul 10, 2025

Description

This change makes it possible to use graphql-modules with resolver extensions such as grafast, graphql-query-complexity and others.

Fixes #2615

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Added a test in packages/graphql-modules/tests/bootstrap.spec.ts

Test Environment:

  • OS: masOS 15.5
  • @graphql-modules/...: 3.0.0
  • NodeJS: v24.3.0

Checklist:

  • I have followed the CONTRIBUTING doc and the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests and linter rules pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Further comments

This is a pretty trivial change, but will significantly improve compatibility of graphql-modules with the rest of graphql ecosystem.

@vlad-x vlad-x force-pushed the feature/resolver-extensions branch from d9f7fd2 to aa5b092 Compare July 10, 2025 07:37
Copy link

@benjie benjie left a comment

Choose a reason for hiding this comment

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

I'd be really happy to see extensions support in graphql-modules!

Comment on lines +95 to +106
if (isDefined((obj[fieldName] as any).extensions)) {
// some extensions allow to omit the resolve function, e.g. grafast
const defaultResolver = (val: any) => val;
const resolver = wrapResolver({
config,
resolver: (obj[fieldName] as any).resolve || defaultResolver,
middlewareMap,
path,
});
resolvers[typeName][fieldName].resolve = resolver;
}

Copy link

Choose a reason for hiding this comment

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

Is this needed? It doesn't seem to do anything with the extensions, and adding a resolver where one isn't needed unnecessarily increases memory usage of the schema (and will also break Grafast plans).

Suggested change
if (isDefined((obj[fieldName] as any).extensions)) {
// some extensions allow to omit the resolve function, e.g. grafast
const defaultResolver = (val: any) => val;
const resolver = wrapResolver({
config,
resolver: (obj[fieldName] as any).resolve || defaultResolver,
middlewareMap,
path,
});
resolvers[typeName][fieldName].resolve = resolver;
}

Copy link
Author

Choose a reason for hiding this comment

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

@benjie thanks for the review! 🙌
Yes, this is needed due to how graphql-modules works internally - it needs to have some sort of resolver to keep track of this part of schema.
An implementation without a resolver would require a much bigger refactoring of graphql-modules, my goal here was to make it work with minimal changes.

@@ -2,6 +2,7 @@ import 'reflect-metadata';
import { makeExecutableSchema } from '@graphql-tools/schema';
import { createApplication, createModule, testkit, gql } from '../src';
import { NonDocumentNodeError } from '../src/shared/errors';
import { resolve } from 'path';
Copy link

Choose a reason for hiding this comment

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

Suggested change
import { resolve } from 'path';

Did you import this by accident?

Comment on lines 63 to 64
import MyQueryType from './query.type.graphql'
import { createModule } from 'graphql-modules'
import { loadFilesSync } from '@graphql-tools/load-files'
import { join } from 'path'
import { constant } from "grafast";
Copy link

Choose a reason for hiding this comment

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

I don't think you meant to make these changes?

@vlad-x vlad-x marked this pull request as ready for review August 5, 2025 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for Grafast plan resolvers
2 participants