Skip to content

fix: GraphiQL IDE improvements for LocalWP and toolbar buttons#3486

Merged
jasonbahl merged 3 commits into
mainfrom
fix/graphiql-ide-improvements
Jan 17, 2026
Merged

fix: GraphiQL IDE improvements for LocalWP and toolbar buttons#3486
jasonbahl merged 3 commits into
mainfrom
fix/graphiql-ide-improvements

Conversation

@jasonbahl

@jasonbahl jasonbahl commented Jan 17, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR addresses several issues with the GraphiQL IDE that have been reported by users.

Changes

URL Mismatch Fix (Closes #3483)

  • Added URL mismatch detection between the current page origin and the GraphQL endpoint
  • Automatically adjusts the endpoint URL to use the current origin when a mismatch is detected
  • This fixes the blank Query Composer issue when using LocalWP or similar tools where WordPress is configured for a custom domain (e.g., http://mysite.local) but accessed via localhost with a port (e.g., http://localhost:10003)
  • Added helpful error messages when schema fails to load, including specific guidance for URL mismatch scenarios

Apollo Client Authentication

  • Updated the Apollo Client to include credentials: 'include' and X-WP-Nonce header for proper cookie-based authentication
  • This ensures introspection queries are properly authenticated when the user is logged into WordPress

Toolbar Buttons Fix (Fixes #3431)

  • Fixed Prettify and History buttons that were not working
  • Updated to use the proper @graphiql/react hooks (usePrettifyEditors, useHistoryContext) instead of the deprecated class instance methods (handlePrettifyQuery, handleToggleHistory)
  • Fixed ref handling in GraphiQL component to use proper React ref pattern (useRef + ref={graphiqlRef})

Error Handling Improvements

  • Added schemaError state to AppContext for better error tracking
  • Improved error capture and display in Router component
  • Query Composer now shows meaningful error messages with troubleshooting guidance instead of just "No Schema Available"

Testing

  1. LocalWP URL Mismatch: Install WPGraphQL in a LocalWP site, access via the localhost URL with port, and verify the Query Composer loads correctly
  2. Prettify Button: Click the Prettify button and verify it formats the query
  3. History Button: Click the History button and verify the history panel opens
  4. Error Display: If schema loading fails, verify a helpful error message is shown

Related Issues

This commit addresses several issues with the GraphiQL IDE:

## URL Mismatch Fix (Closes #3483)
- Added URL mismatch detection between the current page origin and the GraphQL endpoint
- Automatically adjusts the endpoint URL to use the current origin when a mismatch is detected
- This fixes the blank Query Composer issue when using LocalWP or similar tools where WordPress is configured for a custom domain but accessed via localhost with a port
- Added helpful error messages when schema fails to load, including specific guidance for URL mismatch scenarios

## Apollo Client Authentication
- Updated the Apollo Client to include credentials and X-WP-Nonce header for proper cookie-based authentication
- This ensures introspection queries are properly authenticated

## Toolbar Buttons Fix (Fixes #3431)
- Fixed Prettify and History buttons that were not working
- Updated to use the proper @graphiql/react hooks (usePrettifyEditors, useHistoryContext) instead of deprecated class instance methods
- Fixed ref handling in GraphiQL component to use proper React ref pattern

## Error Handling Improvements
- Added schemaError state to AppContext for better error tracking
- Improved error capture and display in Router component
- Query Composer now shows meaningful error messages with troubleshooting guidance
- Added test to verify Prettify button formats unformatted queries
- Added test to verify History button toggles the history panel
- Tests ensure the toolbar buttons work correctly after the fix
Comment thread plugins/wp-graphql/tests/e2e/specs/graphiql.spec.js Fixed
Comment thread plugins/wp-graphql/tests/e2e/specs/graphiql.spec.js Fixed
Comment thread plugins/wp-graphql/tests/e2e/specs/graphiql.spec.js Fixed
- Remove unused queryBefore variable in prettify test
- Remove unused historyPanel locator in history test
- Remove unused isHistoryInitiallyVisible variable in history test
@jasonbahl jasonbahl merged commit 8230dad into main Jan 17, 2026
23 checks passed
@jasonbahl jasonbahl deleted the fix/graphiql-ide-improvements branch January 17, 2026 04:45
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.

Query Composer blank on v2.6.0 GraphiQL editor cursor jumps to start while typing and "Prettify" button not working

1 participant