From cf7d459db812ac91c8b63864cf8ecef98b950fc5 Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Wed, 11 Sep 2024 14:06:32 -0400 Subject: [PATCH 1/6] Consistent namespaces --- ACTIONS_AND_FILTERS.md | 8 ++++---- plugins/help-panel/help-panel.php | 2 +- plugins/query-composer-panel/query-composer-panel.php | 2 +- wpgraphql-ide.php | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ACTIONS_AND_FILTERS.md b/ACTIONS_AND_FILTERS.md index 7919f60..cf0793f 100644 --- a/ACTIONS_AND_FILTERS.md +++ b/ACTIONS_AND_FILTERS.md @@ -4,13 +4,13 @@ ## PHP Actions -- `wpgraphqlide_enqueue_script` ([enqueue_graphiql_extension](https://www.wpgraphql.com/docs/customizing-wpgraphiql#enqueue_graphiql_extension)) +- `wpgraphql_ide_enqueue_script` ([enqueue_graphiql_extension](https://www.wpgraphql.com/docs/customizing-wpgraphiql#enqueue_graphiql_extension)) ## PHP Filters -- `wpgraphqlide_capability_required` -- `wpgraphqlide_context` -- `wpgraphqlide_external_fragments` ([graphiql_external_fragments](https://www.wpgraphql.com/docs/customizing-wpgraphiql#graphiql_external_fragments)) +- `wpgraphql_ide_capability_required` +- `wpgraphql_ide_context` +- `wpgraphql_ide_external_fragments` ([graphiql_external_fragments](https://www.wpgraphql.com/docs/customizing-wpgraphiql#graphiql_external_fragments)) ## JavaScript Actions diff --git a/plugins/help-panel/help-panel.php b/plugins/help-panel/help-panel.php index c3327cf..c2b55a0 100644 --- a/plugins/help-panel/help-panel.php +++ b/plugins/help-panel/help-panel.php @@ -39,4 +39,4 @@ function enqueue_assets(): void { ); } -add_action( 'wpgraphqlide_enqueue_script', __NAMESPACE__ . '\enqueue_assets' ); +add_action( 'wpgraphql_ide_enqueue_script', __NAMESPACE__ . '\enqueue_assets' ); diff --git a/plugins/query-composer-panel/query-composer-panel.php b/plugins/query-composer-panel/query-composer-panel.php index c134a34..a820a96 100644 --- a/plugins/query-composer-panel/query-composer-panel.php +++ b/plugins/query-composer-panel/query-composer-panel.php @@ -45,4 +45,4 @@ function enqueue_assets(): void { $asset_file['version'] ); } -add_action( 'wpgraphqlide_enqueue_script', __NAMESPACE__ . '\enqueue_assets' ); +add_action( 'wpgraphql_ide_enqueue_script', __NAMESPACE__ . '\enqueue_assets' ); diff --git a/wpgraphql-ide.php b/wpgraphql-ide.php index 4791e35..9340c03 100644 --- a/wpgraphql-ide.php +++ b/wpgraphql-ide.php @@ -178,7 +178,7 @@ function save_capabilities_hash( $current_hash ): void { * @return bool Whether the user has the required capability. */ function user_has_graphql_ide_capability(): bool { - $capability_required = apply_filters( 'wpgraphqlide_capability_required', 'manage_graphql_ide' ); + $capability_required = apply_filters( 'wpgraphql_ide_capability_required', 'manage_graphql_ide' ); return current_user_can( $capability_required ); } @@ -453,7 +453,7 @@ function enqueue_react_app_with_styles(): void { // Extensions looking to extend GraphiQL can hook in here, // after the window object is established, but before the App renders - do_action( 'wpgraphqlide_enqueue_script', $app_context ); + do_action( 'wpgraphql_ide_enqueue_script', $app_context ); wp_enqueue_script( 'wpgraphql-ide-render', @@ -517,11 +517,11 @@ function get_app_context(): array { $avatar_url = $current_user->exists() ? get_avatar_url( $current_user->ID ) : ''; return apply_filters( - 'wpgraphqlide_context', + 'wpgraphql_ide_context', [ 'pluginVersion' => get_plugin_header( 'Version' ), 'pluginName' => get_plugin_header( 'Name' ), - 'externalFragments' => apply_filters( 'wpgraphqlide_external_fragments', [] ), + 'externalFragments' => apply_filters( 'wpgraphql_ide_external_fragments', [] ), 'avatarUrl' => $avatar_url, 'drawerButtonLabel' => __( 'GraphQL IDE', 'wpgraphql-ide' ), ] From a68d190a2efc9fae3a4e2d0a60ccab0ce330fc9a Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Wed, 11 Sep 2024 14:35:12 -0400 Subject: [PATCH 2/6] Remove hardcoded auth details from debugging --- src/components/App.jsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/App.jsx b/src/components/App.jsx index b305ab4..81da0a2 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -58,7 +58,7 @@ export function App() { Field( node ) { if ( node.name.value === '__schema' || - node.name.value === '__typename' + node.name.value === '__type' ) { isIntrospectionQuery = true; return visit.BREAK; // Early exit if introspection query is detected @@ -71,22 +71,22 @@ export function App() { const { graphqlEndpoint } = window.WPGRAPHQL_IDE_DATA; - const base64Credentials = btoa( `growth:growth` ); - const headers = { 'Content-Type': 'application/json', - Authorization: `Basic ${ base64Credentials }`, }; + const credentials = isIntrospectionQuery + ? 'include' + : isAuthenticated + ? 'include' + : 'omit'; + + console.log({credentials}); const response = await fetch( graphqlEndpoint, { method: 'POST', headers, body: JSON.stringify( graphQLParams ), - credentials: isIntrospectionQuery - ? 'include' - : isAuthenticated - ? 'include' - : 'omit', + credentials, } ); return response.json(); From 65efb36e4e01c94c62a885a0e5d5496a20d8ef34 Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Wed, 11 Sep 2024 14:35:20 -0400 Subject: [PATCH 3/6] Update tests --- tests/e2e/specs/editor-toolbar-buttons.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/specs/editor-toolbar-buttons.spec.js b/tests/e2e/specs/editor-toolbar-buttons.spec.js index 9a85d68..ed4cfd1 100644 --- a/tests/e2e/specs/editor-toolbar-buttons.spec.js +++ b/tests/e2e/specs/editor-toolbar-buttons.spec.js @@ -53,7 +53,7 @@ describe( 'Toolbar Buttons', () => { describe( 'Auth button', () => { beforeEach( async ( { page } ) => { - await typeQuery( page, 'query { viewer { name } }' ); + await typeQuery( page, 'query { viewer { __typename, name } }' ); } ); test( 'Default state is authenticated', async ( { page } ) => { From 0d086db6cde11d74f446fb8170702899f2f542c1 Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Wed, 11 Sep 2024 14:35:30 -0400 Subject: [PATCH 4/6] Revert "Remove hardcoded auth details from debugging" This reverts commit a68d190a2efc9fae3a4e2d0a60ccab0ce330fc9a. --- src/components/App.jsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/App.jsx b/src/components/App.jsx index 81da0a2..b305ab4 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -58,7 +58,7 @@ export function App() { Field( node ) { if ( node.name.value === '__schema' || - node.name.value === '__type' + node.name.value === '__typename' ) { isIntrospectionQuery = true; return visit.BREAK; // Early exit if introspection query is detected @@ -71,22 +71,22 @@ export function App() { const { graphqlEndpoint } = window.WPGRAPHQL_IDE_DATA; + const base64Credentials = btoa( `growth:growth` ); + const headers = { 'Content-Type': 'application/json', + Authorization: `Basic ${ base64Credentials }`, }; - const credentials = isIntrospectionQuery - ? 'include' - : isAuthenticated - ? 'include' - : 'omit'; - - console.log({credentials}); const response = await fetch( graphqlEndpoint, { method: 'POST', headers, body: JSON.stringify( graphQLParams ), - credentials, + credentials: isIntrospectionQuery + ? 'include' + : isAuthenticated + ? 'include' + : 'omit', } ); return response.json(); From 795b738db070de5e255421b1fffb899b014f3b58 Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Wed, 11 Sep 2024 14:44:50 -0400 Subject: [PATCH 5/6] Reapply "Remove hardcoded auth details from debugging" This reverts commit 0d086db6cde11d74f446fb8170702899f2f542c1. --- src/components/App.jsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/App.jsx b/src/components/App.jsx index b305ab4..81da0a2 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -58,7 +58,7 @@ export function App() { Field( node ) { if ( node.name.value === '__schema' || - node.name.value === '__typename' + node.name.value === '__type' ) { isIntrospectionQuery = true; return visit.BREAK; // Early exit if introspection query is detected @@ -71,22 +71,22 @@ export function App() { const { graphqlEndpoint } = window.WPGRAPHQL_IDE_DATA; - const base64Credentials = btoa( `growth:growth` ); - const headers = { 'Content-Type': 'application/json', - Authorization: `Basic ${ base64Credentials }`, }; + const credentials = isIntrospectionQuery + ? 'include' + : isAuthenticated + ? 'include' + : 'omit'; + + console.log({credentials}); const response = await fetch( graphqlEndpoint, { method: 'POST', headers, body: JSON.stringify( graphQLParams ), - credentials: isIntrospectionQuery - ? 'include' - : isAuthenticated - ? 'include' - : 'omit', + credentials, } ); return response.json(); From eda911dd7e0c901638e6bb361ee1859e372c5740 Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Wed, 11 Sep 2024 14:53:42 -0400 Subject: [PATCH 6/6] Update changesets --- .changeset/friendly-tools-sin.md | 5 +++++ .changeset/moody-mangos-check.md | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 .changeset/friendly-tools-sin.md create mode 100644 .changeset/moody-mangos-check.md diff --git a/.changeset/friendly-tools-sin.md b/.changeset/friendly-tools-sin.md new file mode 100644 index 0000000..3907aea --- /dev/null +++ b/.changeset/friendly-tools-sin.md @@ -0,0 +1,5 @@ +--- +"wpgraphql-ide": patch +--- + +Fixed bug where credentials were being sent in the headers unnecessarily under certain conditions diff --git a/.changeset/moody-mangos-check.md b/.changeset/moody-mangos-check.md new file mode 100644 index 0000000..22df61a --- /dev/null +++ b/.changeset/moody-mangos-check.md @@ -0,0 +1,5 @@ +--- +"wpgraphql-ide": major +--- + +Updated the plugin's custom filter and action names to be consistent across the plugin