Skip to content

Commit 0f5afcf

Browse files
read operation type using graphql npm package
1 parent ac31502 commit 0f5afcf

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

packages/store/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
},
2222
"dependencies": {
2323
"@oclif/core": "4.5.3",
24-
"@shopify/cli-kit": "3.86.0"
24+
"@shopify/cli-kit": "3.86.0",
25+
"graphql": "^16.10.0"
2526
},
2627
"devDependencies": {
2728
"@vitest/coverage-istanbul": "^3.1.4"

packages/store/src/cli/commands/store/execute.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {globalFlags} from '@shopify/cli-kit/node/cli'
33
import {readFile} from '@shopify/cli-kit/node/fs'
44
import {ensureAuthenticatedAdmin} from '@shopify/cli-kit/node/session'
55
import {adminRequest} from '@shopify/cli-kit/node/api/admin'
6+
import {parseGraphQLOperation} from '../../services/graphql-parser.js'
67

78
export default class Execute extends Command {
89
static summary = 'execute a graphql query or mutation on a store'
@@ -86,6 +87,12 @@ export default class Execute extends Command {
8687

8788
const adminSession = await ensureAuthenticatedAdmin(store)
8889

90+
if (flags['bulk-operation']) {
91+
const operationType = parseGraphQLOperation(query)
92+
this.log(`executing bulk ${operationType}...`)
93+
this.error('bulk operations not yet implemented')
94+
}
95+
8996
const result = await adminRequest(query, adminSession, variables)
9097

9198
this.log(JSON.stringify(result, null, 2))
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {parse, OperationDefinitionNode, OperationTypeNode} from 'graphql'
2+
3+
export function parseGraphQLOperation(document: string): OperationTypeNode {
4+
const ast = parse(document)
5+
const operation = ast.definitions.find(
6+
(def) => def.kind === 'OperationDefinition',
7+
) as OperationDefinitionNode | undefined
8+
9+
if (!operation) {
10+
throw new Error('no operation found in graphql document')
11+
}
12+
13+
return operation.operation
14+
}

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)