Skip to content

Commit

Permalink
set current site in gql (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcs- authored Sep 16, 2024
1 parent 0563802 commit d0024e5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions DIFF-TO-CORE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ This document tracks the changes made to the [Statamic core](https://github.com/
| Scroll to frontend component on input focus | [Compare](https://github.com/teamnovu/cms/compare/be09925eff972904ecf1a9c7337fbd4970387564..62143bddaf232443e789ff4fe33f6804ca973b22) | | | unknown | | [statamic/ideas#805](https://github.com/statamic/ideas/issues/805) |
| Allow overwriting breadcrumb url in user edit component | [Compare](https://github.com/teamnovu/cms/commit/08cb919e782e32e46e3f8bc0833a94ea296f6e82) | | hep | unknown | | Probably not the way it should be done. Could be done with an addon using a separate and custom edit page instead. Still a PR to core could be opened. |
| Add advanced GraphQL Config | [Compare](https://github.com/teamnovu/cms/commit/8c6750cf4b67e755590d69dbe16a9d0867267a42) | | lernege | v.4.51 | | |
| Set current site in graphql | [Compare](https://github.com/teamnovu/cms/pull/16) | | estatus | v.5 | |
19 changes: 19 additions & 0 deletions src/GraphQL/Middleware/ResolveSite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Statamic\GraphQL\Middleware;

use Closure;
use GraphQL\Type\Definition\ResolveInfo;
use Rebing\GraphQL\Support\Middleware;
use Statamic\Facades\Site;

class ResolveSite extends Middleware
{
public function handle($root, array $args, $context, ResolveInfo $info, Closure $next)
{
$site = $args['site'] ?? Site::default()->handle();
Site::setCurrent($site);

return $next($root, $args, $context, $info);
}
}
9 changes: 9 additions & 0 deletions src/GraphQL/Queries/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Facades\Statamic\GraphQL\TypeRegistrar;
use GraphQL\Type\Definition\ResolveInfo;
use Rebing\GraphQL\Support\Query as BaseQuery;
use Statamic\GraphQL\Middleware\ResolveSite;

abstract class Query extends BaseQuery
{
Expand All @@ -29,4 +30,12 @@ public function authorize($root, array $args, $ctx, ?ResolveInfo $resolveInfo =

return true;
}

protected function getMiddleware(): array
{
return array_merge(
[ResolveSite::class],
$this->middleware
);
}
}

0 comments on commit d0024e5

Please sign in to comment.