Skip to content

Conversation

@roderik
Copy link
Member

@roderik roderik commented Oct 7, 2024

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:

  • Introduce separate code generation functions for different GraphQL endpoints, including Hasura, Portal, The Graph, and The Graph Fallback.

Enhancements:

  • Refactor the code generation process to modularize and streamline the handling of TypeScript configuration and GraphQL schema generation.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 7, 2024

Reviewer's Guide by Sourcery

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

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

File-Level Changes

Change Details Files
Refactored the gqltadaSpinner function to use separate functions for each codegen step
  • Created separate functions for tsconfig, Hasura, Portal, TheGraph, and TheGraphFallback codegen
  • Improved error handling and made some codegen steps optional if endpoints are not provided
  • Updated file naming conventions for generated schemas and clients
packages/cli/src/commands/codegen/gqltada.spinner.ts
Improved tsconfig handling for GraphQL plugin configuration
  • Added a new function codegenTsconfig to handle tsconfig updates
  • Simplified the process of adding or updating the @0no-co/graphqlsp plugin in tsconfig
  • Updated schema file names in the tadaConfig
packages/cli/src/commands/codegen/gqltada.spinner.ts
Streamlined schema generation and client creation for different GraphQL endpoints
  • Created separate functions for Hasura, Portal, TheGraph, and TheGraphFallback schema generation
  • Implemented more robust error checking when fetching schemas
  • Updated client templates for each GraphQL endpoint type
packages/cli/src/commands/codegen/gqltada.spinner.ts
Introduced a new utility function for writing client templates
  • Created a writeTemplate function to handle file writing operations
  • Standardized the process of creating directories and writing files across all client types
packages/cli/src/commands/codegen/gqltada.spinner.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.8-pr91d905c
SDK The Graph @settlemint/sdk-thegraph@0.5.8-pr91d905c
SDK Portal @settlemint/sdk-portal@0.5.8-pr91d905c
SDK Hasura @settlemint/sdk-hasura@0.5.8-pr91d905c
SDK JS @settlemint/sdk-js@0.5.8-pr91d905c
SDK Utils @settlemint/sdk-utils@0.5.8-pr91d905c

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 - 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();
Copy link
Contributor

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.

Suggested change
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;
Copy link
Contributor

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;
Copy link
Contributor

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;
  }

@roderik roderik merged commit 3c0bd16 into main Oct 7, 2024
@roderik roderik deleted the feat/rework-codegen branch October 7, 2024 13:23
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