Skip to content

Conversation

@roderik
Copy link
Member

@roderik roderik commented Oct 6, 2024

Summary by Sourcery

Add a new SDK Portal package with client creation functions and update the CI workflow to publish this package. Simplify the GraphQL client instantiation in existing packages by aligning the instance URI format. Include detailed documentation for the new Portal package.

New Features:

  • Introduce a new SDK Portal package to the project, including its publication in the CI workflow.
  • Add a new createHasuraClient function for client-side and server-side use in the Portal package.

Enhancements:

  • Simplify the GraphQL client instantiation by removing the subgraph path from the instance URI in The Graph and Hasura packages.

CI:

  • Update the CI workflow to include publishing the new SDK Portal package to npm.

Documentation:

  • Add comprehensive documentation for the new Portal package, including installation, usage, API reference, examples, and contribution guidelines.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 6, 2024

Reviewer's Guide by Sourcery

This pull request adds a new SDK Portal package, aligns instance URIs across different clients, and updates the build workflow to publish the new package. The changes include modifications to existing client implementations, the addition of new files for the Portal package, and updates to the build configuration.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Add new SDK Portal package
  • Create new Portal package with README, source files, and configuration
  • Implement createHasuraClient and createServerHasuraClient functions
  • Add client options schema for Portal package
packages/portal/README.md
packages/portal/src/portal.ts
packages/portal/src/helpers/client-options.schema.ts
packages/portal/tsconfig.json
packages/portal/tsup.config.ts
packages/portal/knip.json
Align instance URIs across client implementations
  • Remove subgraph parameter from TheGraph client options
  • Update GraphQLClient initialization to use instance directly without appending subgraph path
  • Modify Hasura client to use instance directly without appending '/v1/graphql'
packages/thegraph/src/thegraph.ts
packages/thegraph/src/helpers/client-options.schema.ts
packages/hasura/src/hasura.ts
Update build workflow to publish SDK Portal package
  • Add new step to publish SDK Portal package
  • Include SDK Portal in the release notes
.github/workflows/build.yml

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 6, 2024
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 adding comments or updating documentation to explain the changes in GraphQL client URLs for thegraph and hasura packages, as this might affect existing implementations.
  • The new portal package shares a lot of code with the hasura package. Consider refactoring to create common utilities or a base package to reduce code duplication.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Review instructions: 2 issues found
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 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.

`${validatedOptions.instance}/subgraphs/name/${validatedOptions.subgraph}`,
requestConfig,
),
client: new GraphQLClient(validatedOptions.instance, requestConfig),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (review_instructions): Consider adding a comment explaining the change in URL construction.

The removal of '/subgraphs/name/${validatedOptions.subgraph}' from the URL might affect functionality. Please ensure this change is intentional and doesn't break existing queries.

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.

*/
export const ClientOptionsSchema = z.object({
instance: UrlSchema,
subgraph: z.string(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (review_instructions): Removal of 'subgraph' field from ClientOptionsSchema may affect existing code.

Please ensure that all places using this schema are updated accordingly, and that this removal doesn't break any existing functionality.

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.

* instance: 'https://your-hasura-instance.com',
* });
*/
export function createHasuraClient<const Setup extends AbstractSetupSchema>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider refactoring the client creation functions to reduce code duplication and improve API simplicity.

While the intent to provide type-safe and validated client creation is good, the current implementation can be simplified without losing functionality or type safety. Consider the following improvements:

  1. Create a base function for common client creation logic:
function createBaseHasuraClient<const Setup extends AbstractSetupSchema>(
  options: ClientOptions,
  requestConfig?: RequestConfig
) {
  const validatedOptions = validate(ClientOptionsSchema, options);
  const graphql = initGraphQLTada<Setup>();
  return { validatedOptions, graphql };
}
  1. Simplify client and server functions using the base function:
export function createHasuraClient<const Setup extends AbstractSetupSchema>(
  options: ClientOptions,
  requestConfig?: RequestConfig
) {
  const { validatedOptions, graphql } = createBaseHasuraClient<Setup>(options, requestConfig);
  return {
    client: new GraphQLClient(validatedOptions.instance, requestConfig),
    graphql,
  };
}

export function createServerHasuraClient<const Setup extends AbstractSetupSchema>(
  options: ClientOptions & { accessToken: string },
  requestConfig?: RequestConfig
) {
  ensureServer();
  const { validatedOptions, graphql } = createBaseHasuraClient<Setup>(options, requestConfig);
  return {
    client: new GraphQLClient(validatedOptions.instance, {
      ...requestConfig,
      headers: {
        ...requestConfig?.headers,
        "x-auth-token": validatedOptions.accessToken,
      },
    }),
    graphql,
  };
}
  1. Consider providing a default Setup type to simplify usage for basic cases:
type DefaultSetup = {
  introspection: unknown;
  disableMasking: boolean;
  scalars: {
    DateTime: Date;
    JSON: Record<string, unknown>;
  };
};

export function createHasuraClient(
  options: ClientOptions,
  requestConfig?: RequestConfig
) {
  return createHasuraClient<DefaultSetup>(options, requestConfig);
}

export function createServerHasuraClient(
  options: ClientOptions & { accessToken: string },
  requestConfig?: RequestConfig
) {
  return createServerHasuraClient<DefaultSetup>(options, requestConfig);
}

These changes reduce code duplication, maintain type safety and security separation, and provide a simpler API for basic use cases while still allowing for advanced configuration when needed.

@github-actions
Copy link

github-actions bot commented Oct 6, 2024

📦 Packages

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

@roderik roderik merged commit 138f0fe into main Oct 6, 2024
@roderik roderik deleted the feat/portal-client branch October 6, 2024 17:25
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