Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: WPGraphQL Settings page fails to load when "graphiql_enabled" setting is "off" #3137

Merged
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
11 changes: 10 additions & 1 deletion src/Admin/GraphiQL/GraphiQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,16 @@ public function init() {
* @return void
*/
public function register_admin_bar_menu( WP_Admin_Bar $admin_bar ) {
if ( ! current_user_can( 'manage_options' ) || 'off' === get_graphql_setting( 'show_graphiql_link_in_admin_bar' ) ) {

if ( 'off' === get_graphql_setting( 'graphiql_enabled' ) ) {
return;
}

if ( ! current_user_can( 'manage_options' ) ) {
return;
}

if ( 'off' === get_graphql_setting( 'show_graphiql_link_in_admin_bar' ) ) {
return;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Admin/Settings/SettingsRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public function get_settings_fields() {
* @return void
*/
public function admin_enqueue_scripts( string $hook_suffix ) {
if ( 'graphql_page_graphql-settings' !== $hook_suffix ) {

// if the page is not the GraphQL Settings page, bail
if ( 'graphql_page_graphql-settings' !== $hook_suffix && 'toplevel_page_graphql-settings' !== $hook_suffix ) {
return;
}

Expand Down
34 changes: 34 additions & 0 deletions tests/e2e/specs/settings-page.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { describe, test, expect, beforeEach } from '@playwright/test'
import { loginToWordPressAdmin, visitAdminFacingPage, wpAdminUrl } from '../utils'

const selectors = {
graphiqlEnabledCheckbox: '#wpuf-graphql_general_settings\\[graphiql_enabled\\]',
}

describe( 'Settings Page', () => {

beforeEach( async ({ page }) => {
await loginToWordPressAdmin( page );
await page.evaluate(() => localStorage.clear());
});

test( 'GraphiQL IDE can be disabled', async ({ page }) => {
await visitAdminFacingPage( page, wpAdminUrl + '/admin.php?page=graphql-settings' );
// await page.goto('http://localhost:8888/wp-login.php?redirect_to=http%3A%2F%2Flocalhost%3A8888%2Fwp-admin%2F&reauth=1');

await page.waitForTimeout( 500 );
await expect( page.locator(selectors.graphiqlEnabledCheckbox ) ).toBeChecked();
await page.locator(selectors.graphiqlEnabledCheckbox ).uncheck();
await page.getByRole('button', { name: 'Save Changes' }).click();
await page.waitForTimeout( 500 );
await expect(page.getByText('Settings saved.')).toBeVisible();
await expect( page.locator(selectors.graphiqlEnabledCheckbox ) ).not.toBeChecked();
await page.locator( selectors.graphiqlEnabledCheckbox ).check();
await page.getByRole('button', { name: 'Save Changes' }).click();
await page.waitForTimeout( 500 );
await expect(page.getByText('Settings saved.')).toBeVisible();
await expect( page.locator( selectors.graphiqlEnabledCheckbox ) ).toBeChecked();

});

});
Loading