Skip to content

Commit

Permalink
Merge pull request #201 from wp-graphql/fix/wp-org-feedback
Browse files Browse the repository at this point in the history
fix: update hook names for consistency & fix bug with credentials being sent in headers when IDE is not authenticated
  • Loading branch information
josephfusco authored Sep 11, 2024
2 parents 7341c3b + eda911d commit 3020ef0
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-tools-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wpgraphql-ide": patch
---

Fixed bug where credentials were being sent in the headers unnecessarily under certain conditions
5 changes: 5 additions & 0 deletions .changeset/moody-mangos-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wpgraphql-ide": major
---

Updated the plugin's custom filter and action names to be consistent across the plugin
8 changes: 4 additions & 4 deletions ACTIONS_AND_FILTERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion plugins/help-panel/help-panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
2 changes: 1 addition & 1 deletion plugins/query-composer-panel/query-composer-panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
18 changes: 9 additions & 9 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/specs/editor-toolbar-buttons.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } ) => {
Expand Down
8 changes: 4 additions & 4 deletions wpgraphql-ide.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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' ),
]
Expand Down

0 comments on commit 3020ef0

Please sign in to comment.