Skip to content

Conversation

@amcaplan
Copy link
Contributor

@amcaplan amcaplan commented Nov 6, 2025

WHY are these changes introduced?

This PR adds the core GraphiQL editor component, which is the heart of the GraphQL query editing experience. This is the fifth PR in the 8-PR migration stack.

Context: The GraphiQL library provides the interactive query editor, documentation explorer, and result viewer for GraphQL APIs. By integrating GraphiQL with Monaco editor, we get:

  • Advanced syntax highlighting for GraphQL queries
  • IntelliSense and auto-completion
  • Error detection and validation
  • Multiple query tabs
  • Modern, performant editing experience

This replaces the old template-based GraphiQL initialization with a React component that can be managed declaratively.

WHAT is this pull request doing?

This PR adds the main GraphiQLEditor component that wraps the GraphiQL library and configures it for use with the Shopify Admin API.

Key Changes:

GraphiQLEditor Component (src/components/GraphiQLEditor/):

  • Wraps the GraphiQL library in a React component
  • Configures Monaco editor for GraphQL syntax highlighting
  • Manages multiple query tabs with default content
  • Handles API requests with authentication and version selection

Core Features:

1. API Integration:

const fetcher = createGraphiQLFetcher({
  url: `${baseUrl}/graphiql/graphql.json?api_version=${apiVersion}`,
  headers: config.key ? { Authorization: `Bearer ${config.key}` } : {}
})
  • Dynamically constructs GraphQL endpoint URL with API version
  • Adds Bearer token authentication if config.key is provided
  • Re-creates fetcher when API version changes (forces schema introspection)

2. Tab Management:
Default tabs are created in this order:

  1. Welcome tab - Instructions and keyboard shortcuts (WELCOME_MESSAGE)
  2. Shop query tab - Basic shop information query (DEFAULT_SHOP_QUERY)
  3. Initial query tab - If config.query is provided
  4. Additional query tabs - From config.defaultQueries array

3. Ephemeral Storage:

const ephemeralStorage = {
  getItem(key) {
    if (key === 'tabs') return null  // Never load cached tabs
    return localStorage.getItem(key)
  },
  setItem(key, value) {
    if (key === 'tabs') return  // Never persist tabs
    localStorage.setItem(key, value)
  }
}
  • Prevents GraphiQL from caching tabs in localStorage
  • Ensures fresh tabs on every page load
  • Still allows other settings to persist (e.g., theme, editor preferences)

4. Configuration:

  • defaultEditorToolsVisibility: true - Show docs/history sidebar by default
  • isHeadersEditorEnabled: false - Hide headers editor (auth handled by fetcher)
  • forcedTheme: "light" - Match Shopify Admin theme
  • Uses Monaco editor for syntax highlighting (configured in vite.config.ts)

Props Interface:

interface GraphiQLEditorProps {
  config: GraphiQLConfig  // Server config with API endpoints and auth
  apiVersion: string      // Current API version (triggers re-fetch on change)
}

Testing:

  • 252 lines of comprehensive tests
  • Tests default tab creation
  • Tests API version changes
  • Tests authentication headers
  • Tests ephemeral storage behavior

Files Added:

  • src/components/GraphiQLEditor/GraphiQLEditor.tsx - Component implementation (103 lines)
  • src/components/GraphiQLEditor/GraphiQLEditor.test.tsx - Tests (252 lines)
  • src/components/GraphiQLEditor/index.ts - Barrel export

Dependencies

Builds on:

Used by:

  • Subsequent PRs will integrate this editor into the main application layout

How to test your changes?

# Run component tests
pnpm --filter @shopify/graphiql-console test GraphiQLEditor.test.tsx

# Type check
pnpm --filter @shopify/graphiql-console tsc --noEmit

# Build to verify Monaco workers compile correctly
pnpm --filter @shopify/graphiql-console build

# All 252 lines of tests should pass, covering:
# - Tab creation and ordering
# - API version fetcher updates
# - Authentication header injection
# - Ephemeral storage (no tab caching)

Manual Testing:
To test the editor interactively, add it to the App component:

import {GraphiQLEditor} from './components/GraphiQLEditor'

<GraphiQLEditor
  config={{
    baseUrl: 'http://localhost:3000',
    apiVersion: '2024-10',
    apiVersions: ['2024-10', '2025-01'],
    appName: 'Test App',
    appUrl: 'http://localhost:3000',
    storeFqdn: 'test.myshopify.com',
    key: 'optional-bearer-token',
  }}
  apiVersion="2024-10"
/>

You should see:

  • Welcome tab with keyboard shortcuts (focused by default)
  • Shop query tab with basic store query
  • Syntax highlighting and auto-completion working
  • Docs explorer on the right side

Measuring impact

  • n/a - this is the core editor component

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Copy link
Contributor Author

amcaplan commented Nov 6, 2025

@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 79.34% 13695/17261
🟡 Branches 73.27% 6714/9163
🟡 Functions 79.41% 3532/4448
🟡 Lines 79.7% 12934/16229

Test suite run success

3422 tests passing in 1395 suites.

Report generated by 🧪jest coverage report action from fbbce5d

@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_api_version_selector_component branch from d2661f2 to fc285da Compare November 6, 2025 16:53
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_graphiql_editor_with_monaco_integration branch from f1c8933 to b9ab875 Compare November 6, 2025 16:53
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_api_version_selector_component branch from fc285da to 9607030 Compare November 6, 2025 17:27
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_graphiql_editor_with_monaco_integration branch from b9ab875 to 5b82f74 Compare November 6, 2025 17:27
@amcaplan amcaplan changed the base branch from 11-06-feat_graphiql_add_api_version_selector_component to graphite-base/6582 November 6, 2025 21:20
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_graphiql_editor_with_monaco_integration branch from 5b82f74 to 37969e0 Compare November 6, 2025 21:21
@amcaplan amcaplan changed the base branch from graphite-base/6582 to 11-06-feat_graphiql_add_api_version_selector_component November 6, 2025 21:21
@amcaplan amcaplan changed the base branch from 11-06-feat_graphiql_add_api_version_selector_component to graphite-base/6582 November 6, 2025 21:28
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_graphiql_editor_with_monaco_integration branch from 37969e0 to dbe1b3f Compare November 6, 2025 21:28
@amcaplan amcaplan changed the base branch from graphite-base/6582 to 11-06-feat_graphiql_add_api_version_selector_component November 6, 2025 21:28
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_api_version_selector_component branch from 4af8d43 to c2551ad Compare November 6, 2025 21:44
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_graphiql_editor_with_monaco_integration branch from dbe1b3f to c95f764 Compare November 6, 2025 21:44
@amcaplan amcaplan changed the base branch from 11-06-feat_graphiql_add_api_version_selector_component to graphite-base/6582 November 6, 2025 21:49
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_graphiql_editor_with_monaco_integration branch from c95f764 to 757e3ef Compare November 6, 2025 21:50
@amcaplan amcaplan changed the base branch from graphite-base/6582 to 11-06-feat_graphiql_add_api_version_selector_component November 6, 2025 21:50
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_graphiql_editor_with_monaco_integration branch 2 times, most recently from 0cab9c2 to a436c2a Compare November 6, 2025 22:02
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_api_version_selector_component branch from 6dedd3f to cc588d6 Compare November 6, 2025 22:14
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_graphiql_editor_with_monaco_integration branch from a436c2a to 3e5ff33 Compare November 6, 2025 22:14
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_api_version_selector_component branch from cc588d6 to b5d1cb1 Compare November 6, 2025 22:27
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_graphiql_editor_with_monaco_integration branch from 3e5ff33 to 7479a72 Compare November 6, 2025 22:27
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_api_version_selector_component branch from b5d1cb1 to b2f9616 Compare November 6, 2025 22:46
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_graphiql_editor_with_monaco_integration branch 2 times, most recently from ba4433a to 34f9d5e Compare November 6, 2025 22:55
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_api_version_selector_component branch 2 times, most recently from b20c543 to 7f1b051 Compare November 6, 2025 23:17
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_graphiql_editor_with_monaco_integration branch from 34f9d5e to 4ff7e34 Compare November 6, 2025 23:17
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_api_version_selector_component branch from 7f1b051 to ab008f1 Compare November 6, 2025 23:21
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_graphiql_editor_with_monaco_integration branch from 4ff7e34 to 9cccb15 Compare November 6, 2025 23:21
Adds the core GraphiQL editor component with Monaco language support.

- Integrate GraphiQL library for query editing
- Configure Monaco editor for GraphQL syntax highlighting
- Add tab management for multiple queries
- Inject default queries (welcome message, shop query)
- Include comprehensive tests (252 lines)

All editor tests pass, Monaco workers build correctly
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_graphiql_editor_with_monaco_integration branch from 9cccb15 to fbbce5d Compare November 6, 2025 23:34
@amcaplan amcaplan force-pushed the 11-06-feat_graphiql_add_api_version_selector_component branch from ab008f1 to ecb6ff8 Compare November 6, 2025 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant