Skip to content

Commit af7222b

Browse files
author
Combind
committed
Added support for Laravel 10
1 parent 875e887 commit af7222b

3 files changed

Lines changed: 25 additions & 17 deletions

File tree

.github/workflows/run-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ jobs:
1414
matrix:
1515
os: [ubuntu-latest]
1616
php: [8.2, 8.1]
17-
laravel: [9.*]
17+
laravel: [10.*]
1818
stability: [prefer-stable]
1919
include:
20-
- laravel: 9.*
21-
testbench: 7.*
20+
- laravel: 10.*
21+
testbench: 8.*
2222
carbon: ^2.63
2323

2424
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@
1919
"php": "^8.1",
2020
"artesaos/seotools": "^1.0",
2121
"gmostafa/php-graphql-client": "^1.13",
22-
"illuminate/contracts": "^9.0",
22+
"illuminate/contracts": "^9.0|^10.0",
2323
"spatie/laravel-missing-page-redirector": "^2.9",
2424
"spatie/laravel-package-tools": "^1.14.0"
2525
},
2626
"require-dev": {
2727
"laravel/pint": "^1.0",
2828
"nunomaduro/collision": "^6.0",
2929
"nunomaduro/larastan": "^2.0.1",
30-
"orchestra/testbench": "^7.0",
30+
"orchestra/testbench": "^7.0|^8.0",
3131
"pestphp/pest": "^1.21",
3232
"pestphp/pest-plugin-laravel": "^1.1",
3333
"phpstan/extension-installer": "^1.1",
3434
"phpstan/phpstan-deprecation-rules": "^1.0",
3535
"phpstan/phpstan-phpunit": "^1.0",
36-
"phpunit/phpunit": "^9.5"
36+
"phpunit/phpunit": "^9.6"
3737
},
3838
"autoload": {
3939
"psr-4": {

src/HygraphApi.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ class HygraphApi
1818

1919
protected int $ttl;
2020

21+
protected string $lang;
22+
2123
public function __construct()
2224
{
2325
$this->endpoint = config('hygraph.content_api');
2426
$this->token = config('hygraph.token');
2527
$this->ttl = config('hygraph.cache_ttl');
28+
$this->lang = substr(app()->getLocale(), 0, 2);
2629
}
2730

2831
protected function query(Query $query): array|object|null
@@ -60,9 +63,9 @@ public function pages(): array|object|null
6063

6164
public function page(string $id): array
6265
{
63-
return Cache::remember($id, $this->ttl, function () use ($id) {
66+
return Cache::remember($this->lang.'_'.$id, $this->ttl, function () use ($id) {
6467
$gql = (new Query('page'))
65-
->setArguments(['where' => new RawObject('{id: "'.$id.'"}')])
68+
->setArguments(['locales' => new RawObject($this->lang), 'where' => new RawObject('{id: "'.$id.'"}')])
6669
->setSelectionSet(
6770
[
6871
'id',
@@ -152,9 +155,9 @@ public function redirects(): array
152155

153156
public function posts(): array|Collection|null
154157
{
155-
return Cache::remember('allPosts', $this->ttl, function () {
158+
return Cache::remember($this->lang.'_'.'allPosts', $this->ttl, function () {
156159
$gql = (new Query('posts'))
157-
->setArguments(['orderBy' => new RawObject('publicationDate_DESC')])
160+
->setArguments(['locales' => new RawObject($this->lang), 'orderBy' => new RawObject('publicationDate_DESC')])
158161
->setSelectionSet(
159162
[
160163
'id',
@@ -175,9 +178,9 @@ public function posts(): array|Collection|null
175178

176179
public function categories(): array|null
177180
{
178-
return Cache::remember('allPostCategories', $this->ttl, function () {
181+
return Cache::remember($this->lang.'_'.'allPostCategories', $this->ttl, function () {
179182
$gql = (new Query('categories'))
180-
->setArguments(['orderBy' => new RawObject('name_ASC')])
183+
->setArguments(['locales' => new RawObject($this->lang), 'orderBy' => new RawObject('name_ASC')])
181184
->setSelectionSet(['id', 'name', 'slug']);
182185

183186
return $this->query($gql)->categories;
@@ -186,9 +189,9 @@ public function categories(): array|null
186189

187190
public function article(string $slug): object|null
188191
{
189-
return Cache::remember('article_'.$slug, $this->ttl, function () use ($slug) {
192+
return Cache::remember($this->lang.'_'.'article_'.$slug, $this->ttl, function () use ($slug) {
190193
$gql = (new Query('post'))
191-
->setArguments(['where' => new RawObject('{slug: "'.$slug.'"}')])
194+
->setArguments(['locales' => new RawObject($this->lang), 'where' => new RawObject('{slug: "'.$slug.'"}')])
192195
->setSelectionSet(
193196
[
194197
'id',
@@ -218,6 +221,11 @@ public function article(string $slug): object|null
218221
),
219222
(new Query('seo'))->setSelectionSet(['title', 'description', (new Query('image'))->setSelectionSet(['url'])]),
220223
(new Query('relatedPosts'))->setSelectionSet(['id']),
224+
(new Query('toc'))->setSelectionSet([
225+
'title',
226+
'slug',
227+
(new Query('tocLinks'))->setSelectionSet(['title', 'slug']),
228+
]),
221229
]
222230
);
223231

@@ -231,9 +239,9 @@ public function article(string $slug): object|null
231239

232240
public function featuredPosts(): array|null
233241
{
234-
return Cache::remember('featuredPosts', $this->ttl, function () {
242+
return Cache::remember($this->lang.'_'.'featuredPosts', $this->ttl, function () {
235243
$gql = (new Query('posts'))
236-
->setArguments(['where' => new RawObject('{isFeatured: true}'), 'orderBy' => new RawObject('publicationDate_DESC')])
244+
->setArguments(['locales' => new RawObject($this->lang), 'where' => new RawObject('{isFeatured: true}'), 'orderBy' => new RawObject('publicationDate_DESC')])
237245
->setSelectionSet(
238246
[
239247
'id',
@@ -254,7 +262,7 @@ public function featuredPosts(): array|null
254262
public function relatedPosts(array $ids): array|null
255263
{
256264
$gql = (new Query('posts'))
257-
->setArguments(['where' => new RawObject('{id_in: ["'.implode('","', $ids).'"]}')])
265+
->setArguments(['locales' => new RawObject($this->lang), 'where' => new RawObject('{id_in: ["'.implode('","', $ids).'"]}')])
258266
->setSelectionSet(
259267
[
260268
'id',

0 commit comments

Comments
 (0)