Skip to content

Commit 677dca3

Browse files
amcaplanclaude
andcommitted
Fix GraphiQL tab order and remove DEFAULT_SHOP_QUERY duplication
Problem 1: Tab order was incorrect - WELCOME_MESSAGE now appears first (in focus) as intended - DEFAULT_SHOP_QUERY appears second - Custom queries from config appear after defaults Problem 2: Code duplication - Removed DEFAULT_SHOP_QUERY constant from server.ts (lines 19-31) - Changed server to pass query ?? undefined instead of query ?? DEFAULT_SHOP_QUERY - Frontend now handles all default tabs consistently Changes: - packages/graphiql-console/src/components/GraphiQLEditor/GraphiQLEditor.tsx - Reordered tab construction logic to place WELCOME_MESSAGE first - Simplified logic: always include DEFAULT_SHOP_QUERY (no deduplication) - packages/app/src/cli/services/dev/graphiql/server.ts - Removed duplicated DEFAULT_SHOP_QUERY constant - Server only sends custom queries when explicitly provided - packages/graphiql-console/src/components/GraphiQLEditor/GraphiQLEditor.test.tsx - Updated 6 tests to match new tab order 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent e0d7300 commit 677dca3

File tree

3 files changed

+35
-53
lines changed

3 files changed

+35
-53
lines changed

packages/app/src/cli/services/dev/graphiql/server.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,6 @@ import {createRequire} from 'module'
1616

1717
const require = createRequire(import.meta.url)
1818

19-
// Default query for GraphiQL - matches DEFAULT_SHOP_QUERY in graphiql-console package
20-
const DEFAULT_SHOP_QUERY = `query shopInfo {
21-
shop {
22-
name
23-
url
24-
myshopifyDomain
25-
plan {
26-
displayName
27-
partnerDevelopment
28-
shopifyPlus
29-
}
30-
}
31-
}`
32-
3319
class TokenRefreshError extends AbortError {
3420
constructor() {
3521
super('Failed to refresh credentials. Check that your app is installed, and try again.')
@@ -194,7 +180,7 @@ export function setupGraphiQLServer({
194180
storeFqdn,
195181
baseUrl,
196182
key: key ?? undefined,
197-
query: query ?? DEFAULT_SHOP_QUERY,
183+
query: query ?? undefined,
198184
}
199185

200186
// Inject config script before </head>

packages/graphiql-console/src/components/GraphiQLEditor/GraphiQLEditor.test.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ describe('<GraphiQLEditor />', () => {
121121
const graphiqlCall = mockGraphiQL.mock.calls[0][0]
122122
const defaultTabs = graphiqlCall.defaultTabs
123123

124-
// Should have DEFAULT_SHOP_QUERY + WELCOME_MESSAGE
124+
// Should have WELCOME_MESSAGE + DEFAULT_SHOP_QUERY
125125
expect(defaultTabs).toHaveLength(2)
126-
expect(defaultTabs[0].query).toContain('query shopInfo')
127-
expect(defaultTabs[1].query).toContain('Welcome to GraphiQL')
126+
expect(defaultTabs[0].query).toContain('Welcome to GraphiQL')
127+
expect(defaultTabs[1].query).toContain('query shopInfo')
128128
})
129129

130-
test('includes initial query from config as first tab', () => {
130+
test('includes initial query from config as third tab', () => {
131131
const configWithQuery = {
132132
...baseConfig,
133133
query: 'query test { shop { name } }',
@@ -138,12 +138,12 @@ describe('<GraphiQLEditor />', () => {
138138
const graphiqlCall = mockGraphiQL.mock.calls[0][0]
139139
const defaultTabs = graphiqlCall.defaultTabs
140140

141-
// First tab should be the config query
142-
expect(defaultTabs[0].query).toBe('query test { shop { name } }')
143-
expect(defaultTabs[0].variables).toBe('{"var": "value"}')
141+
// First tab is WELCOME_MESSAGE, second is DEFAULT_SHOP_QUERY, third is config query
142+
expect(defaultTabs[2].query).toBe('query test { shop { name } }')
143+
expect(defaultTabs[2].variables).toBe('{"var": "value"}')
144144
})
145145

146-
test('skips DEFAULT_SHOP_QUERY if already in config.query', () => {
146+
test('always includes DEFAULT_SHOP_QUERY even if config has similar query', () => {
147147
const configWithShopQuery = {
148148
...baseConfig,
149149
query: 'query shopInfo { shop { id name } }',
@@ -153,10 +153,11 @@ describe('<GraphiQLEditor />', () => {
153153
const graphiqlCall = mockGraphiQL.mock.calls[0][0]
154154
const defaultTabs = graphiqlCall.defaultTabs
155155

156-
// Should have: config query + WELCOME_MESSAGE (no duplicate shop query)
157-
expect(defaultTabs).toHaveLength(2)
158-
expect(defaultTabs[0].query).toContain('query shopInfo')
159-
expect(defaultTabs[1].query).toContain('Welcome to GraphiQL')
156+
// Should have: WELCOME_MESSAGE + DEFAULT_SHOP_QUERY + config query (no deduplication)
157+
expect(defaultTabs).toHaveLength(3)
158+
expect(defaultTabs[0].query).toContain('Welcome to GraphiQL')
159+
expect(defaultTabs[1].query).toContain('query shopInfo')
160+
expect(defaultTabs[2].query).toContain('query shopInfo')
160161
})
161162

162163
test('includes defaultQueries from config', () => {
@@ -172,11 +173,11 @@ describe('<GraphiQLEditor />', () => {
172173
const graphiqlCall = mockGraphiQL.mock.calls[0][0]
173174
const defaultTabs = graphiqlCall.defaultTabs
174175

175-
// Should have: DEFAULT_SHOP_QUERY + 2 defaultQueries + WELCOME_MESSAGE
176+
// Should have: WELCOME_MESSAGE + DEFAULT_SHOP_QUERY + 2 defaultQueries
176177
expect(defaultTabs).toHaveLength(4)
177-
expect(defaultTabs[1].query).toContain('query products')
178-
expect(defaultTabs[2].query).toContain('query orders')
179-
expect(defaultTabs[2].variables).toBe('{"first": 10}')
178+
expect(defaultTabs[2].query).toContain('query products')
179+
expect(defaultTabs[3].query).toContain('query orders')
180+
expect(defaultTabs[3].variables).toBe('{"first": 10}')
180181
})
181182

182183
test('adds preface to defaultQueries when provided', () => {
@@ -194,10 +195,10 @@ describe('<GraphiQLEditor />', () => {
194195
const graphiqlCall = mockGraphiQL.mock.calls[0][0]
195196
const defaultTabs = graphiqlCall.defaultTabs
196197

197-
expect(defaultTabs[1].query).toBe('# This is a test query\nquery test { shop { name } }')
198+
expect(defaultTabs[2].query).toBe('# This is a test query\nquery test { shop { name } }')
198199
})
199200

200-
test('WELCOME_MESSAGE is always the last tab', () => {
201+
test('WELCOME_MESSAGE is always the first tab', () => {
201202
const configWithMultipleQueries = {
202203
...baseConfig,
203204
query: 'query initial { shop { id } }',
@@ -211,9 +212,8 @@ describe('<GraphiQLEditor />', () => {
211212
const graphiqlCall = mockGraphiQL.mock.calls[0][0]
212213
const defaultTabs = graphiqlCall.defaultTabs
213214

214-
// Last tab should always be WELCOME_MESSAGE
215-
const lastTab = defaultTabs[defaultTabs.length - 1]
216-
expect(lastTab.query).toContain('Welcome to GraphiQL')
215+
// First tab should always be WELCOME_MESSAGE
216+
expect(defaultTabs[0].query).toContain('Welcome to GraphiQL')
217217
})
218218

219219
test('passes correct props to GraphiQL', () => {

packages/graphiql-console/src/components/GraphiQLEditor/GraphiQLEditor.tsx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,26 @@ export function GraphiQLEditor({config, apiVersion}: GraphiQLEditorProps) {
5858
const defaultTabs = useMemo(() => {
5959
const tabs = []
6060

61-
// 1. Add initial query from config FIRST (if provided)
61+
// 1. Add WELCOME_MESSAGE tab FIRST (in focus)
62+
tabs.push({
63+
query: WELCOME_MESSAGE,
64+
})
65+
66+
// 2. Add DEFAULT_SHOP_QUERY tab SECOND (always)
67+
tabs.push({
68+
query: DEFAULT_SHOP_QUERY,
69+
variables: '{}',
70+
})
71+
72+
// 3. Add initial query from config (if provided)
6273
if (config.query) {
6374
tabs.push({
6475
query: config.query,
6576
variables: config.variables ?? '{}',
6677
})
6778
}
6879

69-
// 2. Add DEFAULT_SHOP_QUERY SECOND (if not already in config)
70-
const hasShopQuery =
71-
config.query?.includes('query shopInfo') ?? config.defaultQueries?.some((q) => q.query.includes('query shopInfo'))
72-
if (!hasShopQuery) {
73-
tabs.push({
74-
query: DEFAULT_SHOP_QUERY,
75-
variables: '{}',
76-
})
77-
}
78-
79-
// 3. Add default queries from config
80+
// 4. Add default queries from config
8081
if (config.defaultQueries) {
8182
config.defaultQueries.forEach(({query, variables, preface}) => {
8283
tabs.push({
@@ -86,11 +87,6 @@ export function GraphiQLEditor({config, apiVersion}: GraphiQLEditorProps) {
8687
})
8788
}
8889

89-
// 4. WELCOME_MESSAGE tab LAST
90-
tabs.push({
91-
query: WELCOME_MESSAGE,
92-
})
93-
9490
return tabs
9591
}, [config.defaultQueries, config.query, config.variables])
9692

0 commit comments

Comments
 (0)