-
Notifications
You must be signed in to change notification settings - Fork 2
feat: rework codegen #217
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
feat: rework codegen #217
Conversation
Reviewer's Guide by SourceryThis pull request reworks the codegen process for GraphQL schemas and TypeScript client generation. It modularizes the code generation process, improves error handling, and updates the file naming conventions. The changes aim to make the codebase more maintainable and robust. Class diagram for the updated codegen processclassDiagram
class gqltadaSpinner {
+gqltadaSpinner(env: DotEnv)
}
class codegenTsconfig {
+codegenTsconfig()
}
class codegenHasura {
+codegenHasura(env: DotEnv)
}
class codegenPortal {
+codegenPortal(env: DotEnv)
}
class codegenTheGraph {
+codegenTheGraph(env: DotEnv)
}
class codegenTheGraphFallback {
+codegenTheGraphFallback(env: DotEnv)
}
class writeTemplate {
+writeTemplate(template: string, directory: string, filename: string)
}
gqltadaSpinner --> codegenTsconfig
gqltadaSpinner --> codegenHasura
gqltadaSpinner --> codegenPortal
gqltadaSpinner --> codegenTheGraph
gqltadaSpinner --> codegenTheGraphFallback
codegenHasura --> writeTemplate
codegenPortal --> writeTemplate
codegenTheGraph --> writeTemplate
codegenTheGraphFallback --> writeTemplate
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
📦 Packages
|
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.
Hey @roderik - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider extracting common patterns in schema generation and client template creation into utility functions to reduce duplication.
- Review the error handling approach, especially in cases where errors are now being silently ignored. Consider adding logging or more robust error reporting.
Here's what I looked at during the review
- 🟡 General issues: 3 issues found
- 🟢 Security: all looks good
- 🟢 Review instructions: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| * ); | ||
| */ | ||
| export async function gqltadaSpinner(env: DotEnv) { | ||
| await codegenTsconfig(); |
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.
suggestion: Consider adding error handling for codegenTsconfig function
The new codegenTsconfig function doesn't have any error handling. Consider wrapping it in a try-catch block to handle potential errors when reading or writing the tsconfig file.
| await codegenTsconfig(); | |
| try { | |
| await codegenTsconfig(); | |
| } catch (error) { | |
| console.error('Error generating tsconfig:', error); | |
| throw error; | |
| } |
| } | ||
|
|
||
| async function codegenTheGraph(env: DotEnv) { | ||
| const gqlEndpoint = env.SETTLEMINT_THEGRAPH_SUBGRAPH_ENDPOINT; |
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.
suggestion (bug_risk): Review error handling in codegenTheGraph function
The new codegenTheGraph function silently returns on errors, which differs from the previous implementation. Consider if this change in error handling is intentional and appropriate for all scenarios.
async function codegenTheGraph(env: DotEnv): Promise<void> {
const gqlEndpoint = env.SETTLEMINT_THEGRAPH_SUBGRAPH_ENDPOINT;
if (!gqlEndpoint) {
throw new Error('SETTLEMINT_THEGRAPH_SUBGRAPH_ENDPOINT is not defined');
}
| graphqlspPlugin.schemas.push(schema); | ||
| } | ||
| async function codegenHasura(env: DotEnv) { | ||
| const gqlEndpoint = env.SETTLEMINT_HASURA_ENDPOINT; |
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.
suggestion: Consider abstracting common code in codegen functions
The codegenHasura, codegenPortal, codegenTheGraph, and codegenTheGraphFallback functions have similar structures. Consider abstracting common code into a shared function to reduce duplication and improve maintainability.
async function codegenSource(env: DotEnv, sourceType: 'Hasura' | 'Portal' | 'TheGraph' | 'TheGraphFallback') {
const gqlEndpoint = env[`SETTLEMINT_${sourceType.toUpperCase()}_ENDPOINT`];
if (!gqlEndpoint) {
return;
}
Summary by Sourcery
Rework the code generation process by introducing modular functions for handling different GraphQL endpoints and refactoring the TypeScript configuration management to improve maintainability and clarity.
New Features:
Enhancements: