-
Notifications
You must be signed in to change notification settings - Fork 2
feat: manage the tsconfig file #215
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
Conversation
Reviewer's Guide by SourceryThis pull request implements changes to manage the tsconfig file and update the gqltada code generation process. It introduces a new configuration for GraphQL schemas, updates the tsconfig.json file dynamically, and modifies the output file names and locations for generated schemas and caches. Class diagram for tsconfig management and gqltada code generationclassDiagram
class TadaConfig {
+String name
+Schema[] schemas
}
class Schema {
+String name
+String schema
+String tadaOutputLocation
+String tadaTurboLocation
}
class Tsconfig {
+CompilerOptions compilerOptions
}
class CompilerOptions {
+Plugin[] plugins
}
class Plugin {
+String name
+Schema[] schemas
}
TadaConfig --> Schema
Tsconfig --> CompilerOptions
CompilerOptions --> Plugin
Plugin --> Schema
class GqltadaCodegen {
+String type
+DotEnv env
+String gqlEndpoint
+String output
+String turboOutput
+String adminSecret
}
GqltadaCodegen --> DotEnv
class DotEnv {
+String SETTLEMINT_ACCESS_TOKEN
+String SETTLEMINT_HASURA_ENDPOINT
+String SETTLEMINT_HASURA_ADMIN_SECRET
+String SETTLEMINT_PORTAL_GRAPHQL_ENDPOINT
+String SETTLEMINT_THEGRAPH_SUBGRAPH_ENDPOINT
+String SETTLEMINT_THEGRAPH_SUBGRAPH_ENDPOINT_FALLBACK
}
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 and they look great!
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟡 Review instructions: 1 issue found
- 🟢 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.
| const tadaConfig = { | ||
| name: "@0no-co/graphqlsp", | ||
| schemas: [ | ||
| { | ||
| name: "hasura", | ||
| schema: "hasura-schema.graphql", | ||
| tadaOutputLocation: "hasura-env.d.ts", | ||
| tadaTurboLocation: "hasura-cache.d.ts", | ||
| }, | ||
| { | ||
| name: "thegraph", | ||
| schema: "thegraph-schema.graphql", | ||
| tadaOutputLocation: "thegraph-env.d.ts", | ||
| tadaTurboLocation: "thegraph-cache.d.ts", | ||
| }, | ||
| { | ||
| name: "thegraph-fallback", | ||
| schema: "thegraph-fallback-schema.graphql", | ||
| tadaOutputLocation: "thegraph-fallback-env.d.ts", | ||
| tadaTurboLocation: "thegraph-fallback-cache.d.ts", | ||
| }, | ||
| { | ||
| name: "portal", | ||
| schema: "portal-schema.graphql", | ||
| tadaOutputLocation: "portal-env.d.ts", | ||
| tadaTurboLocation: "portal-cache.d.ts", | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const projectDir = await projectRoot(); | ||
| const tsconfigFile = join(projectDir, "tsconfig.json"); | ||
| const tsconfigContent = readFileSync(tsconfigFile, "utf8"); | ||
| const tsconfig: { | ||
| compilerOptions: { | ||
| plugins?: { | ||
| name: string; | ||
| schemas: { | ||
| name: string; | ||
| schema: string; | ||
| tadaOutputLocation: string; | ||
| tadaTurboLocation: string; | ||
| }[]; | ||
| }[]; | ||
| }; | ||
| } = JSON.parse(tsconfigContent); | ||
| // Find the existing @0no-co/graphqlsp plugin or create a new one | ||
| if (!tsconfig.compilerOptions.plugins) { | ||
| tsconfig.compilerOptions.plugins = []; | ||
| } | ||
| let graphqlspPlugin = (tsconfig.compilerOptions.plugins ?? []).find((plugin) => plugin.name === "@0no-co/graphqlsp"); | ||
|
|
||
| if (!graphqlspPlugin) { | ||
| // If the plugin doesn't exist, create it and add it to the plugins array | ||
| graphqlspPlugin = { name: "@0no-co/graphqlsp", schemas: [] }; | ||
| tsconfig.compilerOptions.plugins.push(graphqlspPlugin); | ||
| } | ||
|
|
||
| // Update or add the schemas defined in tadaConfig | ||
| for (const schema of tadaConfig.schemas) { | ||
| const existingSchemaIndex = graphqlspPlugin.schemas.findIndex((s) => s.name === schema.name); | ||
| if (existingSchemaIndex !== -1) { | ||
| // Update existing schema | ||
| graphqlspPlugin.schemas[existingSchemaIndex] = schema; | ||
| } else { | ||
| // Add new schema | ||
| graphqlspPlugin.schemas.push(schema); | ||
| } | ||
| } | ||
|
|
||
| // Write the updated tsconfig back to the file | ||
| writeFileSync(tsconfigFile, JSON.stringify(tsconfig, null, 2), "utf8"); |
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 (review_instructions): Consider extracting the tsconfig update logic into a separate function for better readability.
This would improve code organization and make the main function easier to understand at a glance.
function updateTsConfig(tadaConfig: any, projectDir: string) {
const tsconfigFile = join(projectDir, "tsconfig.json");
const tsconfig = JSON.parse(readFileSync(tsconfigFile, "utf8"));
tsconfig.compilerOptions.plugins = tsconfig.compilerOptions.plugins || [];
let graphqlspPlugin = tsconfig.compilerOptions.plugins.find(p => p.name === "@0no-co/graphqlsp") || { name: "@0no-co/graphqlsp", schemas: [] };
tadaConfig.schemas.forEach(schema => {
const existingIndex = graphqlspPlugin.schemas.findIndex(s => s.name === schema.name);
existingIndex !== -1 ? graphqlspPlugin.schemas[existingIndex] = schema : graphqlspPlugin.schemas.push(schema);
});
writeFileSync(tsconfigFile, JSON.stringify(tsconfig, null, 2), "utf8");
}
Review instructions:
Path patterns: **/*.ts
Instructions:
- You always use the latest version of NodeJS, Bun, React, NestJS and NextJS, and you are familiar with the latest features and best practices.
- Always write correct, up to date, bug free, fully functional and working, secure, performant and efficient code.
- Focus on readability over being performant, but performance is important.
Summary by Sourcery
Manage the tsconfig.json file by adding or updating the @0no-co/graphqlsp plugin with specified schemas, and enhance the gqltadaCodegen function to support turbo output generation for various schema types.
New Features:
Enhancements: