-
Notifications
You must be signed in to change notification settings - Fork 224
Add GraphQL Operation Validation for Bulk Operations CLI #6632
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
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
We detected some changes at Caution DO NOT create changesets for features which you do not wish to be included in the public changelog of the next CLI release. |
Coverage report
Show new covered files 🐣
Show files with reduced coverage 🔻
Test suite run success3371 tests passing in 1380 suites. Report generated by 🧪jest coverage report action from c316242 |
bce09b0 to
ff34685
Compare
742d51c to
1e7de33
Compare
ff34685 to
71ee5db
Compare
1e7de33 to
5b0a797
Compare
71ee5db to
0404698
Compare
5b0a797 to
fc9f640
Compare
0404698 to
85156dc
Compare
fc9f640 to
af1941b
Compare
290c967 to
ac1fd53
Compare
af1941b to
8582fa3
Compare
ac1fd53 to
5c20695
Compare
8582fa3 to
e9edae7
Compare
5c20695 to
3f00902
Compare
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/cli-kit/dist/public/node/ui.d.ts@@ -1,5 +1,4 @@
import { FatalError as Fatal } from './error.js';
-import { TokenizedString } from './output.js';
import { ConcurrentOutputProps } from '../../private/node/ui/components/ConcurrentOutput.js';
import { handleCtrlC, render } from '../../private/node/ui.js';
import { AlertOptions } from '../../private/node/ui/alert.js';
@@ -332,23 +331,21 @@ interface RenderTasksOptions {
* Installing dependencies ...
*/
export declare function renderTasks<TContext>(tasks: Task<TContext>[], { renderOptions, noProgressBar }?: RenderTasksOptions): Promise<TContext>;
-export interface RenderSingleTaskOptions<T> {
- title: TokenizedString;
- task: (updateStatus: (status: TokenizedString) => void) => Promise<T>;
- renderOptions?: RenderOptions;
-}
/**
- * Awaits a single task and displays a loading bar while it's in progress. The task's result is returned.
+ * Awaits a single promise and displays a loading bar while it's in progress. The promise's result is returned.
* @param options - Configuration object
- * @param options.title - The initial title to display with the loading bar
- * @param options.task - The async task to execute. Receives an updateStatus callback to change the displayed title.
- * @param options.renderOptions - Optional render configuration
- * @returns The result of the task
+ * @param options.title - The title to display with the loading bar
+ * @param options.taskPromise - The promise to track
+ * @param renderOptions - Optional render configuration
+ * @returns The result of the promise
* @example
* ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
* Loading app ...
*/
-export declare function renderSingleTask<T>({ title, task, renderOptions }: RenderSingleTaskOptions<T>): Promise<T>;
+export declare function renderSingleTask<T>({ title, taskPromise }: {
+ title: string;
+ taskPromise: Promise<T> | (() => Promise<T>);
+}, { renderOptions }?: RenderTasksOptions): Promise<T>;
export interface RenderTextPromptOptions extends Omit<TextPromptProps, 'onSubmit'> {
renderOptions?: RenderOptions;
}
packages/cli-kit/dist/private/node/ui/components/SingleTask.d.ts@@ -1,9 +1,8 @@
-import { TokenizedString } from '../../../../public/node/output.js';
-interface SingleTaskProps<T> {
- title: TokenizedString;
- task: (updateStatus: (status: TokenizedString) => void) => Promise<T>;
- onComplete?: (result: T) => void;
+import React from 'react';
+interface SingleTaskProps {
+ title: string;
+ taskPromise: Promise<unknown>;
noColor?: boolean;
}
-declare const SingleTask: <T>({ task, title, onComplete, noColor }: SingleTaskProps<T>) => JSX.Element | null;
+declare const SingleTask: ({ taskPromise, title, noColor }: React.PropsWithChildren<SingleTaskProps>) => JSX.Element | null;
export { SingleTask };
\ No newline at end of file
|
| } | ||
|
|
||
| function isMutation(graphqlOperation: string): boolean { | ||
| function validateGraphQLDocument(graphqlOperation: string, variables?: string[]): boolean { |
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.
I find it weird that validateGraphQLDocument returns a boolean that doesn't represent if the graphql is valid or not, but if its a mutation. Someone reading just the signature of this function wouldn't understand that.
I see two options here:
- Split in two:
validateGraphQLDocumentthat returns nothing, just throws if invalid, andisMutationreturns a boolean. Is ok to parse the document twice, is not a heavy operation afaik. - Type the return of
validateGraphQLDocumentto be something like:
type ValidationResult =
| {
result: 'ok'
type: 'mutation' | 'query'
}
| {
result: 'error'
message: TokenItem | OutputMessage
}
I'm ok with both, I think the first option would be cleaner.
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.
Good point. Refactored to the first option!
e9edae7 to
f788315
Compare
3f00902 to
24f0ce6
Compare
24f0ce6 to
c6e18b0
Compare
c6e18b0 to
c316242
Compare

Resolves: https://github.com/orgs/shop/projects/208/views/34?pane=issue&itemId=139461468&issue=shop%7Cissues-api-foundations%7C1114 and https://github.com/orgs/shop/projects/208/views/34?pane=issue&itemId=139446074&issue=shop%7Cissues-api-foundations%7C1112
Why are these changes introduced?
Improves the validation and error handling for GraphQL operations in the bulk operations service.
Implementation Details
validateGraphQLDocument()function that consolidates all GraphQL validation in one place:isMutation()function.Testing
Unit tests in
execute-bulk-operation.test.ts