Skip to content

Conversation

@roderik
Copy link
Member

@roderik roderik commented Oct 7, 2024

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:

  • Introduce management of the tsconfig.json file by adding or updating the @0no-co/graphqlsp plugin with specified schemas.

Enhancements:

  • Enhance the gqltadaCodegen function to include turbo output generation for different schema types.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 7, 2024

Reviewer's Guide by Sourcery

This 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 generation

classDiagram
    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
    }
Loading

File-Level Changes

Change Details Files
Introduce new tadaConfig object and update tsconfig.json
  • Create a tadaConfig object with GraphQL schema configurations
  • Read and parse the existing tsconfig.json file
  • Update or add the @0no-co/graphqlsp plugin in tsconfig.json
  • Dynamically update the schemas in the plugin configuration
  • Write the updated tsconfig back to the file
packages/cli/src/commands/codegen/gqltada.spinner.ts
Modify gqltadaCodegen function to support new schema and cache output
  • Update output file names for different GraphQL types (Hasura, Portal, TheGraph, TheGraph Fallback)
  • Add turboOutput variable for cache file names
  • Implement generateTurbo function call to generate cache files
packages/cli/src/commands/codegen/gqltada.spinner.ts
Improve error handling in the codegen command
  • Wrap gqltadaSpinner call in a try-catch block
  • Cancel the process with an error message if an exception occurs
packages/cli/src/commands/codegen.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions bot added the feat New feature label Oct 7, 2024
@github-actions
Copy link

github-actions bot commented Oct 7, 2024

📦 Packages

Package Version
SDK Cli @settlemint/sdk-cli@0.5.2-pr2d2a0bc
SDK The Graph @settlemint/sdk-thegraph@0.5.2-pr2d2a0bc
SDK Portal @settlemint/sdk-portal@0.5.2-pr2d2a0bc
SDK Hasura @settlemint/sdk-hasura@0.5.2-pr2d2a0bc
SDK JS @settlemint/sdk-js@0.5.2-pr2d2a0bc
SDK Utils @settlemint/sdk-utils@0.5.2-pr2d2a0bc

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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.

Comment on lines +22 to +93
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");
Copy link
Contributor

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.

@roderik roderik merged commit 4610be7 into main Oct 7, 2024
@roderik roderik deleted the feat/manage-tsconfig branch October 7, 2024 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants