Skip to content

Commit

Permalink
Support more options for client headers
Browse files Browse the repository at this point in the history
  • Loading branch information
stayallive committed Jun 10, 2022
1 parent 07c1238 commit 1900f35
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ _Note: This submitter requires a configured Redis connection._
You should only have to install this package to benefit, unless you have disabled package auto discovery, in that case you will need to add the service provider to
your `config/app.php` manually.

You can optionally add the `graphql-client` header to your requests in the format `name:version` (like: `my-app:1.2.3`) to see client stats in
the [GraphQL Hive](https://graphql-hive.com/) dashboard. You can also opt to set `x-graphql-client-name` and `x-graphql-client-version` headers instead.

## Security Vulnerabilities

If you discover a security vulnerability within this package, please send an e-mail to Alex Bouma at `alex+security@bouma.me`. All security vulnerabilities will be swiftly
Expand Down
11 changes: 8 additions & 3 deletions src/Collector/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ public function __construct(

public function handleStartRequest(StartRequest $startRequest): void
{
$client = $startRequest->request->header('graphql-client');
$request = $startRequest->request;

if (!empty($client)) {
[$this->clientName, $this->clientVersion] = explode(':', $client . ':');
$clientHeader = $request->header('graphql-client');

if (!empty($clientHeader)) {
[$this->clientName, $this->clientVersion] = explode(':', "{$clientHeader}:");
} else {
$this->clientName = $request->header('x-graphql-client-name');
$this->clientVersion = $request->header('x-graphql-client-version');
}
}

Expand Down

0 comments on commit 1900f35

Please sign in to comment.