-
Notifications
You must be signed in to change notification settings - Fork 222
Add --query-file flag to app execute and app bulk execute for loading GraphQL queries from files
#6733
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
Merged
Merged
Add --query-file flag to app execute and app bulk execute for loading GraphQL queries from files
#6733
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| import {linkedAppContext, LoadedAppContextOutput} from '../services/app-context.js' | ||
| import {storeContext} from '../services/store-context.js' | ||
| import {validateSingleOperation} from '../services/graphql/common.js' | ||
| import {OrganizationStore} from '../models/organization.js' | ||
| import {readStdinString} from '@shopify/cli-kit/node/system' | ||
| import {AbortError} from '@shopify/cli-kit/node/error' | ||
| import {readFile, fileExists} from '@shopify/cli-kit/node/fs' | ||
| import {outputContent, outputToken} from '@shopify/cli-kit/node/output' | ||
|
|
||
| interface AppStoreContextFlags { | ||
| path: string | ||
|
|
@@ -19,6 +22,7 @@ interface AppStoreContext { | |
|
|
||
| interface ExecuteCommandFlags extends AppStoreContextFlags { | ||
| query?: string | ||
| 'query-file'?: string | ||
| } | ||
|
|
||
| interface ExecuteContext extends AppStoreContext { | ||
|
|
@@ -51,7 +55,7 @@ export async function prepareAppStoreContext(flags: AppStoreContextFlags): Promi | |
|
|
||
| /** | ||
| * Prepares the execution context for GraphQL operations. | ||
| * Handles query input from flag or stdin, and sets up app and store contexts. | ||
| * Handles query input from flag, file, or stdin, validates GraphQL syntax, and sets up app and store contexts. | ||
| * | ||
| * @param flags - Command flags containing configuration options. | ||
| * @param commandName - Name of the command for error messages (e.g., 'execute', 'bulk execute'). | ||
|
|
@@ -61,14 +65,32 @@ export async function prepareExecuteContext( | |
| flags: ExecuteCommandFlags, | ||
| commandName = 'execute', | ||
| ): Promise<ExecuteContext> { | ||
| const query = flags.query ?? (await readStdinString()) | ||
| let query: string | undefined | ||
|
|
||
| if (flags.query) { | ||
| query = flags.query | ||
| } else if (flags['query-file']) { | ||
|
Comment on lines
+70
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if a user submits both?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OCLIF should prevent that based on the flag config |
||
| const queryFile = flags['query-file'] | ||
| if (!(await fileExists(queryFile))) { | ||
| throw new AbortError( | ||
| outputContent`Query file not found at ${outputToken.path(queryFile)}. Please check the path and try again.`, | ||
| ) | ||
| } | ||
| query = await readFile(queryFile, {encoding: 'utf8'}) | ||
| } else { | ||
| query = await readStdinString() | ||
| } | ||
|
|
||
| if (!query) { | ||
nickwesselman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| throw new AbortError( | ||
| 'No query provided. Use the --query flag or pipe input via stdin.', | ||
| `Example: echo "query { ... }" | shopify app ${commandName}`, | ||
| 'No query provided. Use the --query flag, --query-file flag, or pipe input via stdin.', | ||
| `Example: shopify app ${commandName} --query-file query.graphql`, | ||
| ) | ||
| } | ||
|
|
||
| // Validate GraphQL syntax and ensure single operation | ||
| validateSingleOperation(query) | ||
|
|
||
| const {appContextResult, store} = await prepareAppStoreContext(flags) | ||
|
|
||
| return {query, appContextResult, store} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm assuming this means that normal (non-bulk) GraphQL queries can have variables?
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.
Correct, this is only invoked for bulk operations