-
-
Notifications
You must be signed in to change notification settings - Fork 517
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
Update utils.ts #435
base: main
Are you sure you want to change the base?
Update utils.ts #435
Conversation
WalkthroughThe changes primarily focus on enhancing the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- src/introspection/utils.ts (1 hunks)
🔇 Additional comments (7)
src/introspection/utils.ts (7)
12-17
: Introduction of generic typesMapper
andPayload
enhances modularityThe addition of
Mapper
andPayload
types standardizes mapping functions and encapsulates mapping parameters, improving code clarity and reusability.
21-22
: Addition ofjoinParts
function centralizes ID constructionThe
joinParts
function consolidates ID string construction, promoting consistency and reducing duplication in ID generation.
26-27
: RefactoredtypeNameToId
to utilizejoinParts
Updating
typeNameToId
to usejoinParts
enhances consistency in ID generation across the codebase.
45-58
: Introduction ofmapItems
function reduces code duplicationThe new
mapItems
helper function centralizes the mapping logic, improving maintainability and reducing redundancy in the mapping functions.
62-72
: RefactoredmapFields
to leveragemapItems
andMapper
The
mapFields
function now utilizesmapItems
and theMapper
type, simplifying the logic and enhancing code consistency.
77-85
: RefactoredmapPossibleTypes
to utilizemapItems
andMapper
By using
mapItems
and theMapper
type,mapPossibleTypes
becomes more streamlined and maintainable.
104-114
: RefactoredmapInterfaces
to usemapItems
andMapper
Updating
mapInterfaces
to leveragemapItems
and theMapper
type enhances consistency and reduces code duplication.
mapper: Mapper<GraphQLObjectType | GraphQLInterfaceType, R> | ||
) { | ||
if (!isInterfaceType(type)) return []; | ||
|
||
return mapItems({ | ||
items: getDerivedTypes(schema, type), | ||
mapper, | ||
idParts: ["DERIVED_TYPE", type.name], | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Suggestion: Adjust type
parameter to GraphQLInterfaceType
in mapDerivedTypes
Since mapDerivedTypes
is applicable only to interface types, narrowing the type
parameter enhances type safety and eliminates unnecessary type checks.
Apply this diff to refine the parameter type and remove redundant checks:
-export function mapDerivedTypes<R>(
- schema: GraphQLSchema,
- type: GraphQLNamedType,
- mapper: Mapper<GraphQLObjectType | GraphQLInterfaceType, R>
-) {
- if (!isInterfaceType(type)) return [];
+export function mapDerivedTypes<R>(
+ schema: GraphQLSchema,
+ type: GraphQLInterfaceType,
+ mapper: Mapper<GraphQLObjectType | GraphQLInterfaceType, R>
+) {
return mapItems({
items: getDerivedTypes(schema, type),
mapper,
idParts: ["DERIVED_TYPE", type.name],
});
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
mapper: Mapper<GraphQLObjectType | GraphQLInterfaceType, R> | |
) { | |
if (!isInterfaceType(type)) return []; | |
return mapItems({ | |
items: getDerivedTypes(schema, type), | |
mapper, | |
idParts: ["DERIVED_TYPE", type.name], | |
}); | |
mapper: Mapper<GraphQLObjectType | GraphQLInterfaceType, R> | |
) { | |
return mapItems({ | |
items: getDerivedTypes(schema, type), | |
mapper, | |
idParts: ["DERIVED_TYPE", type.name], | |
}); |
Summary by CodeRabbit
New Features
joinParts
function for constructing ID strings more efficiently.getDerivedTypes
function for better retrieval of derived types from schemas.Refactor