-
Notifications
You must be signed in to change notification settings - Fork 65
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
Allow Query and Mutation type generation to be skipped #198
Conversation
WalkthroughThe recent modifications across several files introduce conditional logic to both the generation and operation of queries and mutations. This includes checks before proceeding with logic in source files, conditional type declaration generation based on queries, streamlined method logic in client code, and configurable code generation options in configuration files. These changes enable more flexible and efficient code generation tailored to the presence of queries and mutations. Changes
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 as PR comments)
Additionally, you can add CodeRabbit Configration 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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files ignored due to path filters (2)
example/github/gen/client.go
is excluded by:!**/gen/**
example/github/gen/models_gen.go
is excluded by:!**/gen/**
Files selected for processing (7)
- clientgen/source.go (2 hunks)
- clientgen/template.gotpl (1 hunks)
- clientgenv2/client.go (1 hunks)
- clientgenv2/source.go (2 hunks)
- clientgenv2/template.gotpl (1 hunks)
- config/config.go (1 hunks)
- example/github/.gqlgenc.yml (1 hunks)
Files skipped from review due to trivial changes (1)
- clientgenv2/template.gotpl
Additional comments: 9
example/github/.gqlgenc.yml (1)
- 17-18: The addition of
query: false
andmutation: false
under thegenerate
section effectively demonstrates how to disable the generation of query and mutation types. This is a straightforward and clear way to configure the tool for specific needs.clientgen/template.gotpl (1)
- 39-41: The conditional logic for generating type declarations based on the presence of a query is a good practice. It ensures that unnecessary types are not declared, keeping the generated code clean and relevant to the actual GraphQL schema being used.
clientgen/source.go (2)
- 171-173: The conditional check in the
Query
method to determine if query generation should proceed is correctly implemented. Returningnil, nil
when the condition is not met is a clear way to skip the generation process.- 197-199: Similarly, the conditional check in the
Mutation
method is correctly implemented. This consistency in handling both query and mutation generation based on configuration is commendable.clientgenv2/source.go (2)
- 192-197: The addition of a check for
s.schema.Query == nil
before proceeding with query generation in theQuery
method is a good defensive programming practice. It ensures that the method behaves correctly even if the schema does not define any queries.- 221-226: The check for
s.schema.Mutation == nil
in theMutation
method follows the same good practice as theQuery
method, ensuring that the method behaves correctly even if the schema does not define any mutations.config/config.go (3)
- 286-287: The addition of
Query
andMutation
fields in theGenerateConfig
struct, along with their correspondingShouldGenerateQuery
andShouldGenerateMutation
methods, introduces a flexible way to control the generation of query and mutation types. This is a significant improvement for users who need to customize their generated code.- 295-305: The implementation of
ShouldGenerateQuery
method is straightforward and correctly handles the case where theQuery
field might not be set. Returningtrue
by default maintains backward compatibility and ensures that query generation is enabled unless explicitly disabled.- 307-317: The
ShouldGenerateMutation
method mirrors the logic ofShouldGenerateQuery
, providing a consistent approach to controlling the generation of mutation types. This consistency in handling both queries and mutations is good for maintainability.
query, err := source.Query() | ||
if err != nil { | ||
return fmt.Errorf("generating query object: %w", err) | ||
} | ||
|
||
var mutation *Mutation | ||
if source.schema.Mutation != nil { | ||
mutation, err = source.Mutation() | ||
if err != nil { | ||
return fmt.Errorf("generating mutation object: %w", err) | ||
} | ||
mutation, err := source.Mutation() | ||
if err != nil { | ||
return fmt.Errorf("generating mutation object: %w", err) |
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.
The refactoring of the MutateConfig
method to directly call source.Query()
and source.Mutation()
simplifies the control flow. However, ensure that error handling is consistent and that any potential nil
values returned from these methods are handled appropriately to avoid runtime errors.
if query != nil {
// Handle query
}
if mutation != nil {
// Handle mutation
}
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.
query, err := source.Query() | |
if err != nil { | |
return fmt.Errorf("generating query object: %w", err) | |
} | |
var mutation *Mutation | |
if source.schema.Mutation != nil { | |
mutation, err = source.Mutation() | |
if err != nil { | |
return fmt.Errorf("generating mutation object: %w", err) | |
} | |
mutation, err := source.Mutation() | |
if err != nil { | |
return fmt.Errorf("generating mutation object: %w", err) | |
query, err := source.Query() | |
if err != nil { | |
return fmt.Errorf("generating query object: %w", err) | |
} | |
if query != nil { | |
// Handle query | |
} | |
mutation, err := source.Mutation() | |
if err != nil { | |
return fmt.Errorf("generating mutation object: %w", err) | |
if mutation != nil { | |
// Handle mutation | |
} |
Summary by CodeRabbit
New Features
Refactor
MutateConfig
method for improved readability and efficiency.Chores