Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/app/src/cli/api/graphql/admin/generated/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ export type Scalars = {
JSON: {input: JsonMapType | string; output: JsonMapType}
/** A monetary value string without a currency symbol or code. Example value: `"100.57"`. */
Money: {input: any; output: any}
/** A scalar value. */
Scalar: {input: any; output: any}
/**
* Represents a unique identifier in the Storefront API. A `StorefrontID` value can
* be used wherever an ID is expected in the Storefront API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ export type Scalars = {
JSON: {input: JsonMapType | string; output: JsonMapType}
/** A monetary value string without a currency symbol or code. Example value: `"100.57"`. */
Money: {input: any; output: any}
/** A scalar value. */
Scalar: {input: any; output: any}
/**
* Represents a unique identifier in the Storefront API. A `StorefrontID` value can
* be used wherever an ID is expected in the Storefront API.
Expand Down
30 changes: 30 additions & 0 deletions packages/app/src/cli/utilities/execute-command-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ describe('prepareExecuteContext', () => {
await expect(prepareExecuteContext(flagsWithoutQuery)).rejects.toThrow('exactlyOne constraint')
})

test('throws AbortError when query flag is empty string', async () => {
const flagsWithEmptyQuery = {...mockFlags, query: ''}

await expect(prepareExecuteContext(flagsWithEmptyQuery)).rejects.toThrow('--query flag value is empty')
})

test('throws AbortError when query flag contains only whitespace', async () => {
const flagsWithWhitespaceQuery = {...mockFlags, query: ' \n\t '}

await expect(prepareExecuteContext(flagsWithWhitespaceQuery)).rejects.toThrow('--query flag value is empty')
})

test('returns query, app context, and store', async () => {
const result = await prepareExecuteContext(mockFlags)

Expand Down Expand Up @@ -169,6 +181,24 @@ describe('prepareExecuteContext', () => {
expect(readFile).not.toHaveBeenCalled()
})

test('throws AbortError when query file is empty', async () => {
vi.mocked(fileExists).mockResolvedValue(true)
vi.mocked(readFile).mockResolvedValue('' as any)

const flagsWithQueryFile = {...mockFlags, query: undefined, 'query-file': '/path/to/empty.graphql'}

await expect(prepareExecuteContext(flagsWithQueryFile)).rejects.toThrow('is empty')
})

test('throws AbortError when query file contains only whitespace', async () => {
vi.mocked(fileExists).mockResolvedValue(true)
vi.mocked(readFile).mockResolvedValue(' \n\t ' as any)

const flagsWithQueryFile = {...mockFlags, query: undefined, 'query-file': '/path/to/whitespace.graphql'}

await expect(prepareExecuteContext(flagsWithQueryFile)).rejects.toThrow('is empty')
})

test('validates GraphQL query using validateSingleOperation', async () => {
await prepareExecuteContext(mockFlags)

Expand Down
12 changes: 11 additions & 1 deletion packages/app/src/cli/utilities/execute-command-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ export async function prepareAppStoreContext(flags: AppStoreContextFlags): Promi
export async function prepareExecuteContext(flags: ExecuteCommandFlags): Promise<ExecuteContext> {
let query: string | undefined

if (flags.query) {
if (flags.query !== undefined) {
if (!flags.query.trim()) {
throw new AbortError('The --query flag value is empty. Please provide a valid GraphQL query or mutation.')
}
query = flags.query
} else if (flags['query-file']) {
const queryFile = flags['query-file']
Expand All @@ -73,6 +76,13 @@ export async function prepareExecuteContext(flags: ExecuteCommandFlags): Promise
)
}
query = await readFile(queryFile, {encoding: 'utf8'})
if (!query.trim()) {
throw new AbortError(
outputContent`Query file at ${outputToken.path(
queryFile,
)} is empty. Please provide a valid GraphQL query or mutation.`,
)
}
}

if (!query) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ export type Scalars = {
JSON: {input: JsonMapType | string; output: JsonMapType}
/** A monetary value string without a currency symbol or code. Example value: `"100.57"`. */
Money: {input: any; output: any}
/** A scalar value. */
Scalar: {input: any; output: any}
/**
* Represents a unique identifier in the Storefront API. A `StorefrontID` value can
* be used wherever an ID is expected in the Storefront API.
Expand Down
Loading