-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add the portal client and aling instance URI #208
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 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
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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 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), |
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.
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(), |
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.
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.
packages/portal/src/portal.ts
Outdated
| * instance: 'https://your-hasura-instance.com', | ||
| * }); | ||
| */ | ||
| export function createHasuraClient<const Setup extends AbstractSetupSchema>( |
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.
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:
- 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 };
}- 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,
};
}- Consider providing a default
Setuptype 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.
📦 Packages
|
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:
createHasuraClientfunction for client-side and server-side use in the Portal package.Enhancements:
CI:
Documentation: