feat(graphql): Add registerIn option for module-scoped type filtering#3811
Open
joe-re wants to merge 1 commit intonestjs:masterfrom
Open
feat(graphql): Add registerIn option for module-scoped type filtering#3811joe-re wants to merge 1 commit intonestjs:masterfrom
joe-re wants to merge 1 commit intonestjs:masterfrom
Conversation
Add the ability to associate GraphQL types with specific NestJS modules using the new `registerIn` option. This enables type filtering when generating schemas for specific modules via the `include` option. ## Motivation When building multiple GraphQL endpoints with different schemas, developers need a way to control which types appear in each schema. Previously, only resolvers could be filtered by module - types were always included globally. ## Changes - Add `registerIn` option to decorators: - @ObjectType, @inputType, @InterfaceType, @ArgsType - registerEnumType(), createUnionType() - Add `RegisterInOption` type (Function | (() => Function)) - Add module filtering logic in TypeMetadataStorage - Add TypeDefinitionsStorage.clear() for multi-schema generation - Connect GqlModuleOptions.include to type filtering ## Behavior - Types without `registerIn`: Included in all schemas - Types with `registerIn`: Included only when module is in `include` list ## Example ```typescript @ObjectType({ registerIn: () => UsersModule }) class User { ... } ``` ## Notes I followed @kamilmysliwiec's suggestion from nestjs#1432 (comment) and took over nestjs#1999 since it seems no progress recently. If you suggest any other solutions please let me know. ## Fixes nestjs#1999, #14759
46b5ef3 to
0eed8e8
Compare
Author
|
@kamilmysliwiec I'd appreciate your review and feedback on this PR when you get a chance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add the ability to associate GraphQL types with specific NestJS modules using the new
registerInoption. This enables type filtering when generating schemas for specific modules via theincludeoption.Motivation
When building multiple GraphQL endpoints with different schemas, developers need a way to control which types appear in each schema. Previously, only resolvers could be filtered by module - types were always included globally.
Changes
registerInoption to decorators:RegisterInOptiontype (Function | (() => Function))Behavior
registerIn: Included in all schemasregisterIn: Included only when module is inincludelistExample
Notes
I followed @kamilmysliwiec's suggestion from #1432 (comment) and took over #1999 since it seems no progress recently. If you suggest any other solutions please let me know.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #1999
When using the
includeoption inGqlModuleOptions, only resolvers are filtered by module. All GraphQL types (ObjectType, InputType, InterfaceType, etc.) are always included in every schema regardless of module configuration.What is the new behavior?
Types with
registerInoption are only included in schemas where the specified module is listed ininclude. Types withoutregisterInremain globally available.Does this PR introduce a breaking change?
Other information
You can check how it work on the below repo.
https://github.com/joe-re/nestjs-graphql-register-in-sample
refs
#721 #1432