66use GraphQL \Exception \QueryError ;
77use GraphQL \Query ;
88use GraphQL \RawObject ;
9- use Illuminate \Support \Collection ;
109use Illuminate \Support \Facades \Cache ;
1110use Illuminate \Support \Facades \Log ;
1211
@@ -56,10 +55,6 @@ public function page(string $id): array
5655 'updatedAt ' ,
5756 (new Query ('content ' ))->setSelectionSet (['html ' ]),
5857 (new Query ('seo ' ))->setSelectionSet (['title ' , 'description ' , 'noIndex ' , (new Query ('image ' ))->setArguments (['locales ' => new RawObject ($ this ->defaultLocale )])->setSelectionSet (['url ' ])]),
59- (new Query ('hero ' ))->setSelectionSet (['title ' , 'label ' , 'description ' , 'catTitle ' , 'ctaLink ' , (new Query ('image ' ))->setArguments (['locales ' => new RawObject ($ this ->defaultLocale )])->setSelectionSet (['url ' ])]),
60- (new Query ('cta ' ))->setSelectionSet (['title ' , 'description ' , 'buttonTitle ' , 'buttonLink ' , (new Query ('image ' ))->setArguments (['locales ' => new RawObject ($ this ->defaultLocale )])->setSelectionSet (['url ' ])]),
61- (new Query ('sections ' ))->setSelectionSet (['id ' , 'title ' , (new Query ('content ' ))->setSelectionSet (['html ' , 'text ' ]), (new Query ('image ' ))->setArguments (['locales ' => new RawObject ($ this ->defaultLocale )])->setSelectionSet (['url ' ])]),
62- (new Query ('logos ' ))->setSelectionSet (['id ' , (new Query ('images ' ))->setArguments (['locales ' => new RawObject ($ this ->defaultLocale )])->setSelectionSet (['url ' ])]),
6358 ]
6459 );
6560 $ page = $ this ->query ($ gql )->page ;
@@ -72,10 +67,6 @@ public function page(string $id): array
7267 'meta_description ' => $ page ->seo ->description ,
7368 'noIndex ' => $ page ->seo ->noIndex ,
7469 'seo_image ' => $ page ->seo ->image ?->url,
75- 'hero ' => $ page ->hero ,
76- 'logos ' => $ page ->logos ,
77- 'cta ' => $ page ->cta ,
78- 'sections ' => $ page ->sections ,
7970 ];
8071 });
8172 }
@@ -142,128 +133,4 @@ public function redirects(): array
142133 return $ array ;
143134 });
144135 }
145-
146- public function posts (string $ lang = null ): array |Collection |null
147- {
148- return Cache::remember ('allPosts ' , $ this ->ttl , function () {
149- $ gql = (new Query ('posts ' ))
150- ->setArguments (['orderBy ' => new RawObject ('publicationDate_DESC ' )])
151- ->setSelectionSet (
152- [
153- 'id ' ,
154- 'title ' ,
155- 'slug ' ,
156- 'excerpt ' ,
157- 'publicationDate ' ,
158- 'modificationDate ' ,
159- (new Query ('coverImage ' ))->setArguments (['locales ' => new RawObject ($ this ->defaultLocale )])->setSelectionSet (['url ' ]),
160- (new Query ('categories ' ))->setSelectionSet (['name ' , 'slug ' ]),
161- ]
162- );
163-
164- return collect ($ this ->query ($ gql )->posts );
165- });
166- }
167-
168- public function announcements (string $ lang = null ): array |Collection |null
169- {
170- return Cache::remember ('allAnnouncements ' , $ this ->ttl , function () {
171- $ gql = (new Query ('announcements ' ))
172- ->setArguments (['orderBy ' => new RawObject ('publicationDate_DESC ' )])
173- ->setSelectionSet (
174- [
175- 'id ' ,
176- 'title ' ,
177- 'description ' ,
178- 'publicationDate ' ,
179- (new Query ('image ' ))->setArguments (['locales ' => new RawObject ($ this ->defaultLocale )])->setSelectionSet (['url ' ]),
180- ]
181- );
182-
183- return collect ($ this ->query ($ gql )->announcements );
184- });
185- }
186-
187- public function categories (): ?array
188- {
189- return Cache::remember ('allPostCategories ' , $ this ->ttl , function () {
190- $ gql = (new Query ('categories ' ))
191- ->setArguments (['orderBy ' => new RawObject ('name_ASC ' )])
192- ->setSelectionSet (['id ' , 'name ' , 'slug ' ]);
193-
194- return $ this ->query ($ gql )->categories ;
195- });
196- }
197-
198- public function article (string $ slug ): ?object
199- {
200- return Cache::remember ('article_ ' .$ slug , $ this ->ttl , function () use ($ slug ) {
201- $ gql = (new Query ('post ' ))
202- ->setArguments (['where ' => new RawObject ('{slug: " ' .$ slug .'"} ' )])
203- ->setSelectionSet (
204- [
205- 'id ' ,
206- 'title ' ,
207- 'slug ' ,
208- 'excerpt ' ,
209- 'publicationDate ' ,
210- 'modificationDate ' ,
211- 'tags ' ,
212- (new Query ('coverImage ' ))->setArguments (['locales ' => new RawObject ($ this ->defaultLocale )])->setSelectionSet (['url ' ]),
213- (new Query ('content ' ))->setSelectionSet (['html ' ]),
214- (new Query ('categories ' ))->setSelectionSet (['id ' , 'name ' , 'slug ' ]),
215- (new Query ('seo ' ))->setSelectionSet (['title ' , 'description ' , (new Query ('image ' ))->setArguments (['locales ' => new RawObject ($ this ->defaultLocale )])->setSelectionSet (['url ' ])]),
216- //(new Query('relatedPosts'))->setSelectionSet(['id']),
217- ]
218- );
219-
220- if (empty ($ this ->query ($ gql )->post )) {
221- abort ('404 ' );
222- }
223-
224- return $ this ->query ($ gql )->post ;
225- });
226- }
227-
228- public function featuredPosts (): ?array
229- {
230- return Cache::remember ('featuredPosts ' , $ this ->ttl , function () {
231- $ gql = (new Query ('posts ' ))
232- ->setArguments (['where ' => new RawObject ('{isFeatured: true} ' ), 'orderBy ' => new RawObject ('publicationDate_DESC ' )])
233- ->setSelectionSet (
234- [
235- 'id ' ,
236- 'title ' ,
237- 'slug ' ,
238- 'readingTime ' ,
239- 'excerpt ' ,
240- 'publicationDate ' ,
241- (new Query ('coverImage ' ))->setArguments (['locales ' => new RawObject ($ this ->defaultLocale )])->setSelectionSet (['url ' ]),
242- (new Query ('categories ' ))->setSelectionSet (['name ' , 'slug ' ]),
243- ]
244- );
245-
246- return $ this ->query ($ gql )->posts ;
247- });
248- }
249-
250- public function relatedPosts (array $ ids ): ?array
251- {
252- $ gql = (new Query ('posts ' ))
253- ->setArguments (['where ' => new RawObject ('{id_in: [" ' .implode ('"," ' , $ ids ).'"]} ' )])
254- ->setSelectionSet (
255- [
256- 'id ' ,
257- 'title ' ,
258- 'slug ' ,
259- 'excerpt ' ,
260- 'publicationDate ' ,
261- 'modificationDate ' ,
262- (new Query ('coverImage ' ))->setArguments (['locales ' => new RawObject ($ this ->defaultLocale )])->setSelectionSet (['url ' ]),
263- (new Query ('categories ' ))->setSelectionSet (['name ' , 'slug ' ]),
264- ]
265- );
266-
267- return $ this ->query ($ gql )->posts ;
268- }
269136}
0 commit comments