Skip to content

Commit

Permalink
Better graphql request detection
Browse files Browse the repository at this point in the history
  • Loading branch information
esamattis committed Dec 11, 2019
1 parent 961547b commit 3f0f7df
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,26 @@ function is_graphql_request()
return true;
}

if (defined('GRAPHQL_HTTP_REQUEST')) {
return GRAPHQL_HTTP_REQUEST;
}

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_GET[\WPGraphQL\Router::$route])) {
return true;
}

$path = explode('?', $_SERVER['REQUEST_URI'])[0];

if ($this->endsWith($path, '/' . \WPGraphQL\Router::$route)) {
return true;
// Copied from https://github.com/wp-graphql/wp-graphql/pull/1067
// For now as the existing version is buggy.
if ( isset( $_GET[ \WPGraphQL\Router::$route ] ) ) {
return true;
}

// If before 'init' check $_SERVER.
if ( isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ) {
$haystack = wp_unslash( $_SERVER['HTTP_HOST'] )
. wp_unslash( $_SERVER['REQUEST_URI'] );
$needle = \home_url( \WPGraphQL\Router::$route );

// Strip protocol.
$haystack = preg_replace( '#^(http(s)?://)#', '', $haystack );
$needle = preg_replace( '#^(http(s)?://)#', '', $needle );
$len = strlen( $needle );
return ( substr( $haystack, 0, $len ) === $needle );
}

return false;

}
}

0 comments on commit 3f0f7df

Please sign in to comment.