From 81f52f3d6224b3f7993add9f8c66d95d62179a07 Mon Sep 17 00:00:00 2001 From: Thiago Matos Date: Fri, 10 Apr 2026 17:30:50 -0400 Subject: [PATCH 1/8] feat(graphql): sync client with current thoth schema --- README.md | 5 +- docs/README-es.md | 5 +- docs/README-pt_BR.md | 5 +- src/GraphQL/Client.php | 492 +++++++++++-- src/GraphQL/Models/AbstractModel.php | 15 + src/GraphQL/Models/AbstractText.php | 7 + src/GraphQL/Models/AdditionalResource.php | 16 + src/GraphQL/Models/Award.php | 7 + src/GraphQL/Models/Biography.php | 7 + src/GraphQL/Models/BookReview.php | 7 + src/GraphQL/Models/Contact.php | 7 + src/GraphQL/Models/Endorsement.php | 7 + src/GraphQL/Models/File.php | 7 + src/GraphQL/Models/FileUploadResponse.php | 7 + src/GraphQL/Models/Funding.php | 4 +- src/GraphQL/Models/Me.php | 7 + src/GraphQL/Models/Publisher.php | 4 +- src/GraphQL/Models/Title.php | 7 + src/GraphQL/Models/WorkFeaturedVideo.php | 7 + src/GraphQL/MutationBuilder.php | 672 ++++++++++++++---- src/GraphQL/Queries/AbstractTextQuery.php | 67 ++ .../Queries/AdditionalResourceQuery.php | 74 ++ src/GraphQL/Queries/AwardQuery.php | 74 ++ src/GraphQL/Queries/BiographyQuery.php | 66 ++ src/GraphQL/Queries/BookReviewQuery.php | 79 ++ src/GraphQL/Queries/ContactQuery.php | 69 ++ src/GraphQL/Queries/ContributionQuery.php | 7 +- src/GraphQL/Queries/EndorsementQuery.php | 72 ++ src/GraphQL/Queries/FileQuery.php | 38 + src/GraphQL/Queries/FundingQuery.php | 1 - src/GraphQL/Queries/ImprintQuery.php | 6 + src/GraphQL/Queries/IssueQuery.php | 1 + src/GraphQL/Queries/LanguageQuery.php | 1 - src/GraphQL/Queries/MeQuery.php | 39 + src/GraphQL/Queries/PublicationQuery.php | 4 + src/GraphQL/Queries/PublisherQuery.php | 3 + src/GraphQL/Queries/SeriesQuery.php | 4 +- src/GraphQL/Queries/TitleQuery.php | 68 ++ .../Queries/WorkFeaturedVideoQuery.php | 69 ++ src/GraphQL/Queries/WorkQuery.php | 21 +- src/GraphQL/QueryProvider.php | 34 +- tests/GraphQL/MutationBuilderTest.php | 44 +- .../GraphQL/Queries/ContributionQueryTest.php | 7 +- tests/GraphQL/Queries/FundingQueryTest.php | 1 - tests/GraphQL/Queries/ImprintQueryTest.php | 6 + tests/GraphQL/Queries/IssueQueryTest.php | 1 + tests/GraphQL/Queries/LanguageQueryTest.php | 1 - .../GraphQL/Queries/PublicationQueryTest.php | 4 + tests/GraphQL/Queries/PublisherQueryTest.php | 3 + tests/GraphQL/Queries/SeriesQueryTest.php | 4 +- tests/GraphQL/Queries/WorkQueryTest.php | 21 +- 51 files changed, 1917 insertions(+), 267 deletions(-) create mode 100644 src/GraphQL/Models/AbstractText.php create mode 100644 src/GraphQL/Models/AdditionalResource.php create mode 100644 src/GraphQL/Models/Award.php create mode 100644 src/GraphQL/Models/Biography.php create mode 100644 src/GraphQL/Models/BookReview.php create mode 100644 src/GraphQL/Models/Contact.php create mode 100644 src/GraphQL/Models/Endorsement.php create mode 100644 src/GraphQL/Models/File.php create mode 100644 src/GraphQL/Models/FileUploadResponse.php create mode 100644 src/GraphQL/Models/Me.php create mode 100644 src/GraphQL/Models/Title.php create mode 100644 src/GraphQL/Models/WorkFeaturedVideo.php create mode 100644 src/GraphQL/Queries/AbstractTextQuery.php create mode 100644 src/GraphQL/Queries/AdditionalResourceQuery.php create mode 100644 src/GraphQL/Queries/AwardQuery.php create mode 100644 src/GraphQL/Queries/BiographyQuery.php create mode 100644 src/GraphQL/Queries/BookReviewQuery.php create mode 100644 src/GraphQL/Queries/ContactQuery.php create mode 100644 src/GraphQL/Queries/EndorsementQuery.php create mode 100644 src/GraphQL/Queries/FileQuery.php create mode 100644 src/GraphQL/Queries/MeQuery.php create mode 100644 src/GraphQL/Queries/TitleQuery.php create mode 100644 src/GraphQL/Queries/WorkFeaturedVideoQuery.php diff --git a/README.md b/README.md index f39778e..933893f 100644 --- a/README.md +++ b/README.md @@ -104,8 +104,7 @@ A QueryException is thrown in case of an error in the request to the GraphQL API ```php try { $work = new \ThothApi\GraphQL\Models\Work([ - 'fullTitle' => 'Foo Bar', - 'title' => 'Foo', + 'doi' => 'https://doi.org/10.00000/00000000', ]); $workId = $client->createWork($work); } catch (\ThothApi\Exception\QueryException $exception) { @@ -222,4 +221,4 @@ Licensed under the Apache License, Version 2.0 - [See the License file.](/LICENS Copyright (c) 2024 Lepidus Tecnologia -Copyright (c) 2024 Thoth \ No newline at end of file +Copyright (c) 2024 Thoth diff --git a/docs/README-es.md b/docs/README-es.md index a67a5c0..43ff000 100644 --- a/docs/README-es.md +++ b/docs/README-es.md @@ -96,8 +96,7 @@ Se lanza una excepción del tipo *QueryException* en caso de error en la solicit ```php try { $work = new \ThothApi\GraphQL\Models\Work([ - 'fullTitle' => 'Foo Bar', - 'title' => 'Foo', + 'doi' => 'https://doi.org/10.00000/00000000', ]); $workId = $client->createWork($work); } catch (\ThothApi\Exception\QueryException $exception) { @@ -214,4 +213,4 @@ Licenciado bajo la Licencia Apache, Versión 2.0 - [Consulta el archivo de licen Copyright (c) 2024 Lepidus Tecnologia -Copyright (c) 2024 Thoth \ No newline at end of file +Copyright (c) 2024 Thoth diff --git a/docs/README-pt_BR.md b/docs/README-pt_BR.md index ec21a20..772eda4 100644 --- a/docs/README-pt_BR.md +++ b/docs/README-pt_BR.md @@ -96,8 +96,7 @@ Uma exceção do tipo *QueryException* é lançada em caso de erro na solicitaç ```php try { $work = new \ThothApi\GraphQL\Models\Work([ - 'fullTitle' => 'Foo Bar', - 'title' => 'Foo', + 'doi' => 'https://doi.org/10.00000/00000000', ]); $workId = $client->createWork($work); } catch (\ThothApi\Exception\QueryException $exception) { @@ -214,4 +213,4 @@ Licenciado sob a Licença Apache, Versão 2.0 - [Veja o arquivo de licença.](/L Copyright (c) 2024 Lepidus Tecnologia -Copyright (c) 2024 Thoth \ No newline at end of file +Copyright (c) 2024 Thoth diff --git a/src/GraphQL/Client.php b/src/GraphQL/Client.php index 0d7ed6d..90d181d 100644 --- a/src/GraphQL/Client.php +++ b/src/GraphQL/Client.php @@ -3,22 +3,34 @@ namespace ThothApi\GraphQL; use ThothApi\GraphQL\Models\AbstractModel; +use ThothApi\GraphQL\Models\AbstractText; +use ThothApi\GraphQL\Models\AdditionalResource; use ThothApi\GraphQL\Models\Affiliation; +use ThothApi\GraphQL\Models\Award; +use ThothApi\GraphQL\Models\Biography; +use ThothApi\GraphQL\Models\BookReview; +use ThothApi\GraphQL\Models\Contact; use ThothApi\GraphQL\Models\Contribution; use ThothApi\GraphQL\Models\Contributor; +use ThothApi\GraphQL\Models\Endorsement; +use ThothApi\GraphQL\Models\File; +use ThothApi\GraphQL\Models\FileUploadResponse; use ThothApi\GraphQL\Models\Funding; use ThothApi\GraphQL\Models\Imprint; use ThothApi\GraphQL\Models\Institution; use ThothApi\GraphQL\Models\Issue; use ThothApi\GraphQL\Models\Language; use ThothApi\GraphQL\Models\Location; +use ThothApi\GraphQL\Models\Me; use ThothApi\GraphQL\Models\Price; use ThothApi\GraphQL\Models\Publication; use ThothApi\GraphQL\Models\Publisher; use ThothApi\GraphQL\Models\Reference; use ThothApi\GraphQL\Models\Series; use ThothApi\GraphQL\Models\Subject; +use ThothApi\GraphQL\Models\Title; use ThothApi\GraphQL\Models\Work; +use ThothApi\GraphQL\Models\WorkFeaturedVideo; use ThothApi\GraphQL\Models\WorkRelation; class Client @@ -54,6 +66,21 @@ public function accountDetails(): array return (new Account($this->request))->details($this->token); } + public function additionalResource(string $additionalResourceId): AdditionalResource + { + return $this->get('additionalResource', $additionalResourceId); + } + + public function additionalResources(array $args = []): array + { + return $this->getMany('additionalResource', $args); + } + + public function additionalResourceCount(): int + { + return $this->count('additionalResource'); + } + public function affiliation(string $affiliationId): Affiliation { return $this->get('affiliation', $affiliationId); @@ -69,6 +96,41 @@ public function affiliationCount(): int return $this->count('affiliation'); } + public function abstract(string $abstractId, ?string $markupFormat = null): AbstractText + { + return $this->get('abstract', $abstractId, ['markupFormat' => $markupFormat]); + } + + public function abstracts(array $args = []): array + { + return $this->getMany('abstract', $args); + } + + public function award(string $awardId): Award + { + return $this->get('award', $awardId); + } + + public function awards(array $args = []): array + { + return $this->getMany('award', $args); + } + + public function awardCount(): int + { + return $this->count('award'); + } + + public function biography(string $biographyId, ?string $markupFormat = null): Biography + { + return $this->get('biography', $biographyId, ['markupFormat' => $markupFormat]); + } + + public function biographies(array $args = []): array + { + return $this->getMany('biography', $args); + } + public function books(array $args = []): array { return $this->getMany('book', $args); @@ -79,9 +141,24 @@ public function bookByDoi(string $doi): Work return $this->getByDoi('book', $doi); } - public function bookCount(): int + public function bookCount(array $args = []): int + { + return $this->count('book', $args); + } + + public function bookReview(string $bookReviewId): BookReview + { + return $this->get('bookReview', $bookReviewId); + } + + public function bookReviews(array $args = []): array + { + return $this->getMany('bookReview', $args); + } + + public function bookReviewCount(): int { - return $this->count('book'); + return $this->count('bookReview'); } public function chapters(array $args = []): array @@ -94,9 +171,24 @@ public function chapterByDoi(string $doi): Work return $this->getByDoi('chapter', $doi); } - public function chapterCount(): int + public function chapterCount(array $args = []): int + { + return $this->count('chapter', $args); + } + + public function contact(string $contactId): Contact { - return $this->count('chapter'); + return $this->get('contact', $contactId); + } + + public function contacts(array $args = []): array + { + return $this->getMany('contact', $args); + } + + public function contactCount(array $args = []): int + { + return $this->count('contact', $args); } public function contribution(string $contributionId): Contribution @@ -109,9 +201,9 @@ public function contributions(array $args = []): array return $this->getMany('contribution', $args); } - public function contributionCount(): int + public function contributionCount(array $args = []): int { - return $this->count('contribution'); + return $this->count('contribution', $args); } public function contributor(string $contributorId): Contributor @@ -124,9 +216,29 @@ public function contributors(array $args = []): array return $this->getMany('contributor', $args); } - public function contributorCount(): int + public function contributorCount(array $args = []): int { - return $this->count('contributor'); + return $this->count('contributor', $args); + } + + public function endorsement(string $endorsementId): Endorsement + { + return $this->get('endorsement', $endorsementId); + } + + public function endorsements(array $args = []): array + { + return $this->getMany('endorsement', $args); + } + + public function endorsementCount(): int + { + return $this->count('endorsement'); + } + + public function file(string $fileId): File + { + return $this->get('file', $fileId); } public function funding(string $fundingId): Funding @@ -154,9 +266,9 @@ public function imprints(array $args = []): array return $this->getMany('imprint', $args); } - public function imprintCount(): int + public function imprintCount(array $args = []): int { - return $this->count('imprint'); + return $this->count('imprint', $args); } public function institution(string $institutionId): Institution @@ -169,9 +281,9 @@ public function institutions(array $args = []): array return $this->getMany('institution', $args); } - public function institutionCount(): int + public function institutionCount(array $args = []): int { - return $this->count('institution'); + return $this->count('institution', $args); } public function issue(string $issueId): Issue @@ -199,9 +311,9 @@ public function languages(array $args = []): array return $this->getMany('language', $args); } - public function languageCount(): int + public function languageCount(array $args = []): int { - return $this->count('language'); + return $this->count('language', $args); } public function location(string $locationId): Location @@ -214,9 +326,15 @@ public function locations(array $args = []): array return $this->getMany('location', $args); } - public function locationCount(): int + public function locationCount(array $args = []): int + { + return $this->count('location', $args); + } + + public function me(): Me { - return $this->count('location'); + $result = $this->query('me', [], $this->token); + return new Me($result['me']); } public function price(string $priceId): Price @@ -229,9 +347,9 @@ public function prices(array $args = []): array return $this->getMany('price', $args); } - public function priceCount(): int + public function priceCount(array $args = []): int { - return $this->count('price'); + return $this->count('price', $args); } public function publication(string $publicationId): Publication @@ -244,9 +362,9 @@ public function publications(array $args = []): array return $this->getMany('publication', $args); } - public function publicationCount(): int + public function publicationCount(array $args = []): int { - return $this->count('publication'); + return $this->count('publication', $args); } public function publisher(string $publisherId): Publisher @@ -259,9 +377,9 @@ public function publishers(array $args = []): array return $this->getMany('publisher', $args); } - public function publisherCount(): int + public function publisherCount(array $args = []): int { - return $this->count('publisher'); + return $this->count('publisher', $args); } public function reference(string $referenceId): Reference @@ -289,9 +407,9 @@ public function serieses(array $args = []): array return $this->getMany('series', $args); } - public function seriesCount(): int + public function seriesCount(array $args = []): int { - return $this->count('series'); + return $this->count('series', $args); } public function subject(string $subjectId): Subject @@ -304,9 +422,19 @@ public function subjects(array $args = []): array return $this->getMany('subject', $args); } - public function subjectCount(): int + public function subjectCount(array $args = []): int + { + return $this->count('subject', $args); + } + + public function title(string $titleId, ?string $markupFormat = null): Title + { + return $this->get('title', $titleId, ['markupFormat' => $markupFormat]); + } + + public function titles(array $args = []): array { - return $this->count('subject'); + return $this->getMany('title', $args); } public function work(string $workId): Work @@ -324,9 +452,53 @@ public function workByDoi(string $doi): Work return $this->getByDoi('work', $doi); } - public function workCount(): int + public function workCount(array $args = []): int + { + return $this->count('work', $args); + } + + public function workFeaturedVideo(string $workFeaturedVideoId): WorkFeaturedVideo + { + return $this->get('workFeaturedVideo', $workFeaturedVideoId); + } + + public function workFeaturedVideos(array $args = []): array + { + return $this->getMany('workFeaturedVideo', $args); + } + + public function workFeaturedVideoCount(): int + { + return $this->count('workFeaturedVideo'); + } + + public function createAdditionalResource(AdditionalResource $additionalResource, ?string $markupFormat = null): string + { + return $this->mutation( + 'createAdditionalResource', + $additionalResource->getAllData(), + 'workResourceId', + ['markupFormat' => $markupFormat] + ); + } + + public function updateAdditionalResource(AdditionalResource $additionalResource, ?string $markupFormat = null): string { - return $this->count('work'); + return $this->mutation( + 'updateAdditionalResource', + $additionalResource->getAllData(), + 'workResourceId', + ['markupFormat' => $markupFormat] + ); + } + + public function deleteAdditionalResource(string $additionalResourceId): string + { + return $this->mutation( + 'deleteAdditionalResource', + ['additionalResourceId' => $additionalResourceId], + 'workResourceId' + ); } public function createAffiliation(Affiliation $affiliation): string @@ -344,6 +516,81 @@ public function deleteAffiliation(string $affiliationId): string return $this->mutation('deleteAffiliation', ['affiliationId' => $affiliationId], 'affiliationId'); } + public function createAbstract(AbstractText $abstract, ?string $markupFormat = null): string + { + return $this->mutation('createAbstract', $abstract->getAllData(), 'abstractId', ['markupFormat' => $markupFormat]); + } + + public function updateAbstract(AbstractText $abstract, ?string $markupFormat = null): string + { + return $this->mutation('updateAbstract', $abstract->getAllData(), 'abstractId', ['markupFormat' => $markupFormat]); + } + + public function deleteAbstract(string $abstractId): string + { + return $this->mutation('deleteAbstract', ['abstractId' => $abstractId], 'abstractId'); + } + + public function createAward(Award $award, ?string $markupFormat = null): string + { + return $this->mutation('createAward', $award->getAllData(), 'awardId', ['markupFormat' => $markupFormat]); + } + + public function updateAward(Award $award, ?string $markupFormat = null): string + { + return $this->mutation('updateAward', $award->getAllData(), 'awardId', ['markupFormat' => $markupFormat]); + } + + public function deleteAward(string $awardId): string + { + return $this->mutation('deleteAward', ['awardId' => $awardId], 'awardId'); + } + + public function createBiography(Biography $biography, ?string $markupFormat = null): string + { + return $this->mutation('createBiography', $biography->getAllData(), 'biographyId', ['markupFormat' => $markupFormat]); + } + + public function updateBiography(Biography $biography, ?string $markupFormat = null): string + { + return $this->mutation('updateBiography', $biography->getAllData(), 'biographyId', ['markupFormat' => $markupFormat]); + } + + public function deleteBiography(string $biographyId): string + { + return $this->mutation('deleteBiography', ['biographyId' => $biographyId], 'biographyId'); + } + + public function createBookReview(BookReview $bookReview, ?string $markupFormat = null): string + { + return $this->mutation('createBookReview', $bookReview->getAllData(), 'bookReviewId', ['markupFormat' => $markupFormat]); + } + + public function updateBookReview(BookReview $bookReview, ?string $markupFormat = null): string + { + return $this->mutation('updateBookReview', $bookReview->getAllData(), 'bookReviewId', ['markupFormat' => $markupFormat]); + } + + public function deleteBookReview(string $bookReviewId): string + { + return $this->mutation('deleteBookReview', ['bookReviewId' => $bookReviewId], 'bookReviewId'); + } + + public function createContact(Contact $contact): string + { + return $this->mutation('createContact', $contact->getAllData(), 'contactId'); + } + + public function updateContact(Contact $contact): string + { + return $this->mutation('updateContact', $contact->getAllData(), 'contactId'); + } + + public function deleteContact(string $contactId): string + { + return $this->mutation('deleteContact', ['contactId' => $contactId], 'contactId'); + } + public function createContribution(Contribution $contribution): string { return $this->mutation('createContribution', $contribution->getAllData(), 'contributionId'); @@ -374,6 +621,31 @@ public function deleteContributor(string $contributorId): string return $this->mutation('deleteContributor', ['contributorId' => $contributorId], 'contributorId'); } + public function createEndorsement(Endorsement $endorsement, ?string $markupFormat = null): string + { + return $this->mutation( + 'createEndorsement', + $endorsement->getAllData(), + 'endorsementId', + ['markupFormat' => $markupFormat] + ); + } + + public function updateEndorsement(Endorsement $endorsement, ?string $markupFormat = null): string + { + return $this->mutation( + 'updateEndorsement', + $endorsement->getAllData(), + 'endorsementId', + ['markupFormat' => $markupFormat] + ); + } + + public function deleteEndorsement(string $endorsementId): string + { + return $this->mutation('deleteEndorsement', ['endorsementId' => $endorsementId], 'endorsementId'); + } + public function createFunding(Funding $funding): string { return $this->mutation('createFunding', $funding->getAllData(), 'fundingId'); @@ -554,6 +826,21 @@ public function deleteSubject(string $subjectId): string return $this->mutation('deleteSubject', ['subjectId' => $subjectId], 'subjectId'); } + public function createTitle(Title $title, ?string $markupFormat = null): string + { + return $this->mutation('createTitle', $title->getAllData(), 'titleId', ['markupFormat' => $markupFormat]); + } + + public function updateTitle(Title $title, ?string $markupFormat = null): string + { + return $this->mutation('updateTitle', $title->getAllData(), 'titleId', ['markupFormat' => $markupFormat]); + } + + public function deleteTitle(string $titleId): string + { + return $this->mutation('deleteTitle', ['titleId' => $titleId], 'titleId'); + } + public function createWork(Work $work): string { return $this->mutation('createWork', $work->getAllData(), 'workId'); @@ -569,6 +856,21 @@ public function deleteWork(string $workId): string return $this->mutation('deleteWork', ['workId' => $workId], 'workId'); } + public function createWorkFeaturedVideo(WorkFeaturedVideo $workFeaturedVideo): string + { + return $this->mutation('createWorkFeaturedVideo', $workFeaturedVideo->getAllData(), 'workFeaturedVideoId'); + } + + public function updateWorkFeaturedVideo(WorkFeaturedVideo $workFeaturedVideo): string + { + return $this->mutation('updateWorkFeaturedVideo', $workFeaturedVideo->getAllData(), 'workFeaturedVideoId'); + } + + public function deleteWorkFeaturedVideo(string $workFeaturedVideoId): string + { + return $this->mutation('deleteWorkFeaturedVideo', ['workFeaturedVideoId' => $workFeaturedVideoId], 'workFeaturedVideoId'); + } + public function createWorkRelation(WorkRelation $workRelation): string { return $this->mutation('createWorkRelation', $workRelation->getAllData(), 'workRelationId'); @@ -584,20 +886,96 @@ public function deleteWorkRelation(string $workRelationId): string return $this->mutation('deleteWorkRelation', ['workRelationId' => $workRelationId], 'workRelationId'); } + public function moveAffiliation(string $affiliationId, int $newOrdinal): string + { + return $this->mutation('moveAffiliation', compact('affiliationId', 'newOrdinal'), 'affiliationId'); + } + + public function moveContribution(string $contributionId, int $newOrdinal): string + { + return $this->mutation('moveContribution', compact('contributionId', 'newOrdinal'), 'contributionId'); + } + + public function moveIssue(string $issueId, int $newOrdinal): string + { + return $this->mutation('moveIssue', compact('issueId', 'newOrdinal'), 'issueId'); + } + + public function moveReference(string $referenceId, int $newOrdinal): string + { + return $this->mutation('moveReference', compact('referenceId', 'newOrdinal'), 'referenceId'); + } + + public function moveAdditionalResource(string $additionalResourceId, int $newOrdinal): string + { + return $this->mutation('moveAdditionalResource', compact('additionalResourceId', 'newOrdinal'), 'workResourceId'); + } + + public function moveAward(string $awardId, int $newOrdinal): string + { + return $this->mutation('moveAward', compact('awardId', 'newOrdinal'), 'awardId'); + } + + public function moveEndorsement(string $endorsementId, int $newOrdinal): string + { + return $this->mutation('moveEndorsement', compact('endorsementId', 'newOrdinal'), 'endorsementId'); + } + + public function moveBookReview(string $bookReviewId, int $newOrdinal): string + { + return $this->mutation('moveBookReview', compact('bookReviewId', 'newOrdinal'), 'bookReviewId'); + } + + public function moveSubject(string $subjectId, int $newOrdinal): string + { + return $this->mutation('moveSubject', compact('subjectId', 'newOrdinal'), 'subjectId'); + } + + public function moveWorkRelation(string $workRelationId, int $newOrdinal): string + { + return $this->mutation('moveWorkRelation', compact('workRelationId', 'newOrdinal'), 'workRelationId'); + } + + public function initPublicationFileUpload(array $data): FileUploadResponse + { + return new FileUploadResponse($this->runMutation('initPublicationFileUpload', $data)); + } + + public function initFrontcoverFileUpload(array $data): FileUploadResponse + { + return new FileUploadResponse($this->runMutation('initFrontcoverFileUpload', $data)); + } + + public function initAdditionalResourceFileUpload(array $data): FileUploadResponse + { + return new FileUploadResponse($this->runMutation('initAdditionalResourceFileUpload', $data)); + } + + public function initWorkFeaturedVideoFileUpload(array $data): FileUploadResponse + { + return new FileUploadResponse($this->runMutation('initWorkFeaturedVideoFileUpload', $data)); + } + + public function completeFileUpload(array $data): File + { + return new File($this->runMutation('completeFileUpload', $data)); + } + public function rawQuery(string $rawQuery, array $args = []): array { $response = $this->request->runQuery($rawQuery, $args); return $response->getData(); } - private function get(string $entityName, string $entityId): AbstractModel + private function get(string $entityName, string $entityId, array $args = []): AbstractModel { $entityClass = $this->getModelClass($entityName); - $args = [ - $entityName . 'Id' => $entityId - ]; + $args = array_merge( + [$this->getIdentifierField($entityName) => $entityId], + array_filter($args, fn ($value) => $value !== null) + ); - $result = $this->query($entityName, $args); + $result = $this->query($entityName, $args, $entityName === 'me' ? $this->token : null); return new $entityClass($result[$entityName]); } @@ -613,7 +991,6 @@ private function getMany(string $entityName, array $args = []): array private function count(string $entityName, array $args = []): int { $queryName = $entityName . 'Count'; - $result = $this->query($queryName, $args); return $result[$queryName]; } @@ -622,34 +999,51 @@ private function getByDoi(string $entityName, string $doi): AbstractModel { $entityClass = $this->getModelClass($entityName); $queryName = $entityName . 'ByDoi'; - $args = [ - 'doi' => $doi - ]; - - $result = $this->query($queryName, $args); + $result = $this->query($queryName, ['doi' => $doi]); return new $entityClass($result[$queryName]); } - private function mutation(string $mutationName, array $data, string $returnValue): string + private function mutation(string $mutationName, array $data, string $returnValue, array $extraArgs = []): string + { + $result = $this->runMutation($mutationName, $data, $extraArgs); + return $result[$returnValue]; + } + + private function runMutation(string $mutationName, array $data, array $extraArgs = []): array { - $mutation = MutationBuilder::build($mutationName, $data); + $mutation = MutationBuilder::build($mutationName, $data, $extraArgs); $response = $this->request->runQuery($mutation, null, $this->token); - $data = $response->getData(); - return $data[$mutationName][$returnValue]; + $body = $response->getData(); + return $body[$mutationName]; } private function getModelClass(string $entityName): string { - if ($entityName == 'book' || $entityName == 'chapter') { - $entityName = 'work'; - } - return '\\ThothApi\\GraphQL\\Models\\' . ucfirst($entityName); + $mapping = [ + 'abstract' => AbstractText::class, + 'additionalResource' => AdditionalResource::class, + 'book' => Work::class, + 'chapter' => Work::class, + 'me' => Me::class, + ]; + + return $mapping[$entityName] ?? '\\ThothApi\\GraphQL\\Models\\' . ucfirst($entityName); + } + + private function getIdentifierField(string $entityName): string + { + return match ($entityName) { + 'additionalResource' => 'additionalResourceId', + 'bookReview' => 'bookReviewId', + 'workFeaturedVideo' => 'workFeaturedVideoId', + default => $entityName . 'Id', + }; } - private function query(string $queryName, array $args = []): array + private function query(string $queryName, array $args = [], ?string $token = null): array { $query = QueryProvider::get($queryName); - $response = $this->request->runQuery($query, $args); + $response = $this->request->runQuery($query, array_filter($args, fn ($value) => $value !== null), $token); return $response->getData(); } } diff --git a/src/GraphQL/Models/AbstractModel.php b/src/GraphQL/Models/AbstractModel.php index bc7b6b7..73866b5 100644 --- a/src/GraphQL/Models/AbstractModel.php +++ b/src/GraphQL/Models/AbstractModel.php @@ -32,4 +32,19 @@ public function setData($key, $value) unset($this->data[$key]); } } + + public function __call(string $name, array $arguments) + { + if (preg_match('/^(get|set|is)(.+)$/', $name, $matches) !== 1) { + throw new \BadMethodCallException("Method '{$name}' does not exist."); + } + + $field = lcfirst($matches[2]); + if ($matches[1] === 'set') { + $this->setData($field, $arguments[0] ?? null); + return; + } + + return $this->getData($field); + } } diff --git a/src/GraphQL/Models/AbstractText.php b/src/GraphQL/Models/AbstractText.php new file mode 100644 index 0000000..fcb5bde --- /dev/null +++ b/src/GraphQL/Models/AbstractText.php @@ -0,0 +1,7 @@ +getData('workResourceId'); + } + + public function setAdditionalResourceId(?string $additionalResourceId): void + { + $this->setData('workResourceId', $additionalResourceId); + } +} diff --git a/src/GraphQL/Models/Award.php b/src/GraphQL/Models/Award.php new file mode 100644 index 0000000..a131bfb --- /dev/null +++ b/src/GraphQL/Models/Award.php @@ -0,0 +1,7 @@ +getData('projectShortName'); + return $this->getData('projectShortname'); } public function setProjectShortName(?string $projectShortName): void { - $this->setData('projectShortName', $projectShortName); + $this->setData('projectShortname', $projectShortName); } public function getGrantNumber(): ?string diff --git a/src/GraphQL/Models/Me.php b/src/GraphQL/Models/Me.php new file mode 100644 index 0000000..19e1dc8 --- /dev/null +++ b/src/GraphQL/Models/Me.php @@ -0,0 +1,7 @@ +getData('publisherShortName'); + return $this->getData('publisherShortname'); } public function setPublisherShortName(?string $publisherShortName): void { - $this->setData('publisherShortName', $publisherShortName); + $this->setData('publisherShortname', $publisherShortName); } public function getPublisherUrl(): ?string diff --git a/src/GraphQL/Models/Title.php b/src/GraphQL/Models/Title.php new file mode 100644 index 0000000..e1204e1 --- /dev/null +++ b/src/GraphQL/Models/Title.php @@ -0,0 +1,7 @@ + $value !== ''); $mutationStr = << true]; + $uploadFields = [ + 'declaredMimeType' => false, + 'declaredExtension' => false, + 'declaredSha256' => false, + ]; + $mapping = [ + 'createAdditionalResource' => [ + 'fields' => [ + 'workId' => false, + 'title' => false, + 'description' => false, + 'attribution' => false, + 'resourceType' => true, + 'doi' => false, + 'handle' => false, + 'url' => false, + 'date' => false, + 'resourceOrdinal' => false, + ], + 'extraArgs' => $markupArg, + 'returnValue' => 'workResourceId', + ], + 'updateAdditionalResource' => [ + 'fields' => [ + 'additionalResourceId' => false, + 'workId' => false, + 'title' => false, + 'description' => false, + 'attribution' => false, + 'resourceType' => true, + 'doi' => false, + 'handle' => false, + 'url' => false, + 'date' => false, + 'resourceOrdinal' => false, + ], + 'extraArgs' => $markupArg, + 'returnValue' => 'workResourceId', + ], + 'deleteAdditionalResource' => [ + 'fields' => ['additionalResourceId' => false], + 'nested' => false, + 'returnValue' => 'workResourceId', + ], 'createAffiliation' => [ 'fields' => [ 'contributionId' => false, 'institutionId' => false, 'affiliationOrdinal' => false, - 'position' => false + 'position' => false, ], - 'returnValue' => 'affiliationId' + 'returnValue' => 'affiliationId', ], 'updateAffiliation' => [ 'fields' => [ @@ -48,15 +111,176 @@ private static function getMutationFields(string $mutationName): ?array 'contributionId' => false, 'institutionId' => false, 'affiliationOrdinal' => false, - 'position' => false + 'position' => false, ], - 'returnValue' => 'affiliationId' + 'returnValue' => 'affiliationId', ], 'deleteAffiliation' => [ + 'fields' => ['affiliationId' => false], + 'nested' => false, + 'returnValue' => 'affiliationId', + ], + 'createAbstract' => [ 'fields' => [ - 'affiliationId' => false, + 'workId' => false, + 'content' => false, + 'localeCode' => true, + 'abstractType' => true, + 'canonical' => false, + ], + 'extraArgs' => $markupArg, + 'returnValue' => 'abstractId', + ], + 'updateAbstract' => [ + 'fields' => [ + 'abstractId' => false, + 'workId' => false, + 'content' => false, + 'localeCode' => true, + 'abstractType' => true, + 'canonical' => false, + ], + 'extraArgs' => $markupArg, + 'returnValue' => 'abstractId', + ], + 'deleteAbstract' => [ + 'fields' => ['abstractId' => false], + 'nested' => false, + 'returnValue' => 'abstractId', + ], + 'createAward' => [ + 'fields' => [ + 'workId' => false, + 'title' => false, + 'url' => false, + 'category' => false, + 'year' => false, + 'jury' => false, + 'country' => true, + 'prizeStatement' => false, + 'role' => true, + 'awardOrdinal' => false, + ], + 'extraArgs' => $markupArg, + 'returnValue' => 'awardId', + ], + 'updateAward' => [ + 'fields' => [ + 'awardId' => false, + 'workId' => false, + 'title' => false, + 'url' => false, + 'category' => false, + 'year' => false, + 'jury' => false, + 'country' => true, + 'prizeStatement' => false, + 'role' => true, + 'awardOrdinal' => false, + ], + 'extraArgs' => $markupArg, + 'returnValue' => 'awardId', + ], + 'deleteAward' => [ + 'fields' => ['awardId' => false], + 'nested' => false, + 'returnValue' => 'awardId', + ], + 'createBiography' => [ + 'fields' => [ + 'contributionId' => false, + 'content' => false, + 'canonical' => false, + 'localeCode' => true, + ], + 'extraArgs' => $markupArg, + 'returnValue' => 'biographyId', + ], + 'updateBiography' => [ + 'fields' => [ + 'biographyId' => false, + 'contributionId' => false, + 'content' => false, + 'canonical' => false, + 'localeCode' => true, + ], + 'extraArgs' => $markupArg, + 'returnValue' => 'biographyId', + ], + 'deleteBiography' => [ + 'fields' => ['biographyId' => false], + 'nested' => false, + 'returnValue' => 'biographyId', + ], + 'createBookReview' => [ + 'fields' => [ + 'workId' => false, + 'title' => false, + 'authorName' => false, + 'reviewerOrcid' => false, + 'reviewerInstitutionId' => false, + 'url' => false, + 'doi' => false, + 'reviewDate' => false, + 'journalName' => false, + 'journalVolume' => false, + 'journalNumber' => false, + 'journalIssn' => false, + 'pageRange' => false, + 'text' => false, + 'reviewOrdinal' => false, ], - 'returnValue' => 'affiliationId' + 'extraArgs' => $markupArg, + 'returnValue' => 'bookReviewId', + ], + 'updateBookReview' => [ + 'fields' => [ + 'bookReviewId' => false, + 'workId' => false, + 'title' => false, + 'authorName' => false, + 'reviewerOrcid' => false, + 'reviewerInstitutionId' => false, + 'url' => false, + 'doi' => false, + 'reviewDate' => false, + 'journalName' => false, + 'journalVolume' => false, + 'journalNumber' => false, + 'journalIssn' => false, + 'pageRange' => false, + 'text' => false, + 'reviewOrdinal' => false, + ], + 'extraArgs' => $markupArg, + 'returnValue' => 'bookReviewId', + ], + 'deleteBookReview' => [ + 'fields' => ['bookReviewId' => false], + 'nested' => false, + 'returnValue' => 'bookReviewId', + ], + 'createContact' => [ + 'fields' => [ + 'publisherId' => false, + 'contactType' => true, + 'email' => false, + ], + 'returnValue' => 'contactId', + ], + 'updateContact' => [ + 'fields' => [ + 'contactId' => false, + 'publisherId' => false, + 'contactType' => true, + 'email' => false, + ], + 'returnValue' => 'contactId', + ], + 'deleteContact' => [ + 'fields' => ['contactId' => false], + 'nested' => false, + 'returnValue' => 'contactId', ], 'createContribution' => [ 'fields' => [ @@ -68,9 +292,8 @@ private static function getMutationFields(string $mutationName): ?array 'firstName' => false, 'lastName' => false, 'fullName' => false, - 'biography' => false ], - 'returnValue' => 'contributionId' + 'returnValue' => 'contributionId', ], 'updateContribution' => [ 'fields' => [ @@ -83,15 +306,13 @@ private static function getMutationFields(string $mutationName): ?array 'firstName' => false, 'lastName' => false, 'fullName' => false, - 'biography' => false ], - 'returnValue' => 'contributionId' + 'returnValue' => 'contributionId', ], 'deleteContribution' => [ - 'fields' => [ - 'contributionId' => false, - ], - 'returnValue' => 'contributionId' + 'fields' => ['contributionId' => false], + 'nested' => false, + 'returnValue' => 'contributionId', ], 'createContributor' => [ 'fields' => [ @@ -99,9 +320,9 @@ private static function getMutationFields(string $mutationName): ?array 'lastName' => false, 'fullName' => false, 'orcid' => false, - 'website' => false + 'website' => false, ], - 'returnValue' => 'contributorId' + 'returnValue' => 'contributorId', ], 'updateContributor' => [ 'fields' => [ @@ -110,15 +331,48 @@ private static function getMutationFields(string $mutationName): ?array 'lastName' => false, 'fullName' => false, 'orcid' => false, - 'website' => false + 'website' => false, ], - 'returnValue' => 'contributorId' + 'returnValue' => 'contributorId', ], 'deleteContributor' => [ + 'fields' => ['contributorId' => false], + 'nested' => false, + 'returnValue' => 'contributorId', + ], + 'createEndorsement' => [ 'fields' => [ - 'contributorId' => false, + 'workId' => false, + 'authorName' => false, + 'authorRole' => false, + 'authorOrcid' => false, + 'authorInstitutionId' => false, + 'url' => false, + 'text' => false, + 'endorsementOrdinal' => false, + ], + 'extraArgs' => $markupArg, + 'returnValue' => 'endorsementId', + ], + 'updateEndorsement' => [ + 'fields' => [ + 'endorsementId' => false, + 'workId' => false, + 'authorName' => false, + 'authorRole' => false, + 'authorOrcid' => false, + 'authorInstitutionId' => false, + 'url' => false, + 'text' => false, + 'endorsementOrdinal' => false, ], - 'returnValue' => 'contributorId' + 'extraArgs' => $markupArg, + 'returnValue' => 'endorsementId', + ], + 'deleteEndorsement' => [ + 'fields' => ['endorsementId' => false], + 'nested' => false, + 'returnValue' => 'endorsementId', ], 'createFunding' => [ 'fields' => [ @@ -128,9 +382,8 @@ private static function getMutationFields(string $mutationName): ?array 'projectName' => false, 'projectShortname' => false, 'grantNumber' => false, - 'jurisdiction' => false ], - 'returnValue' => 'fundingId' + 'returnValue' => 'fundingId', ], 'updateFunding' => [ 'fields' => [ @@ -141,24 +394,28 @@ private static function getMutationFields(string $mutationName): ?array 'projectName' => false, 'projectShortname' => false, 'grantNumber' => false, - 'jurisdiction' => false ], - 'returnValue' => 'fundingId' + 'returnValue' => 'fundingId', ], 'deleteFunding' => [ - 'fields' => [ - 'fundingId' => false, - ], - 'returnValue' => 'fundingId' + 'fields' => ['fundingId' => false], + 'nested' => false, + 'returnValue' => 'fundingId', ], 'createImprint' => [ 'fields' => [ 'publisherId' => false, 'imprintName' => false, 'imprintUrl' => false, - 'crossmarkDoi' => false + 'crossmarkDoi' => false, + 's3Bucket' => false, + 'cdnDomain' => false, + 'cloudfrontDistId' => false, + 'defaultCurrency' => true, + 'defaultPlace' => false, + 'defaultLocale' => true, ], - 'returnValue' => 'imprintId' + 'returnValue' => 'imprintId', ], 'updateImprint' => [ 'fields' => [ @@ -166,24 +423,29 @@ private static function getMutationFields(string $mutationName): ?array 'publisherId' => false, 'imprintName' => false, 'imprintUrl' => false, - 'crossmarkDoi' => false + 'crossmarkDoi' => false, + 's3Bucket' => false, + 'cdnDomain' => false, + 'cloudfrontDistId' => false, + 'defaultCurrency' => true, + 'defaultPlace' => false, + 'defaultLocale' => true, ], - 'returnValue' => 'imprintId' + 'returnValue' => 'imprintId', ], 'deleteImprint' => [ - 'fields' => [ - 'imprintId' => false, - ], - 'returnValue' => 'imprintId' + 'fields' => ['imprintId' => false], + 'nested' => false, + 'returnValue' => 'imprintId', ], 'createInstitution' => [ 'fields' => [ 'institutionName' => false, 'institutionDoi' => false, 'countryCode' => true, - 'ror' => false + 'ror' => false, ], - 'returnValue' => 'institutionId' + 'returnValue' => 'institutionId', ], 'updateInstitution' => [ 'fields' => [ @@ -191,47 +453,46 @@ private static function getMutationFields(string $mutationName): ?array 'institutionName' => false, 'institutionDoi' => false, 'countryCode' => true, - 'ror' => false + 'ror' => false, ], - 'returnValue' => 'institutionId' + 'returnValue' => 'institutionId', ], 'deleteInstitution' => [ - 'fields' => [ - 'institutionId' => false, - ], - 'returnValue' => 'institutionId' + 'fields' => ['institutionId' => false], + 'nested' => false, + 'returnValue' => 'institutionId', ], 'createIssue' => [ 'fields' => [ 'seriesId' => false, 'workId' => false, - 'issueOrdinal' => false + 'issueOrdinal' => false, + 'issueNumber' => false, ], - 'returnValue' => 'issueId' + 'returnValue' => 'issueId', ], 'updateIssue' => [ 'fields' => [ 'issueId' => false, 'seriesId' => false, 'workId' => false, - 'issueOrdinal' => false + 'issueOrdinal' => false, + 'issueNumber' => false, ], - 'returnValue' => 'issueId' + 'returnValue' => 'issueId', ], 'deleteIssue' => [ - 'fields' => [ - 'issueId' => false, - ], - 'returnValue' => 'issueId' + 'fields' => ['issueId' => false], + 'nested' => false, + 'returnValue' => 'issueId', ], 'createLanguage' => [ 'fields' => [ 'workId' => false, 'languageCode' => true, 'languageRelation' => true, - 'mainLanguage' => false ], - 'returnValue' => 'languageId' + 'returnValue' => 'languageId', ], 'updateLanguage' => [ 'fields' => [ @@ -239,15 +500,13 @@ private static function getMutationFields(string $mutationName): ?array 'workId' => false, 'languageCode' => true, 'languageRelation' => true, - 'mainLanguage' => false ], - 'returnValue' => 'languageId' + 'returnValue' => 'languageId', ], 'deleteLanguage' => [ - 'fields' => [ - 'languageId' => false, - ], - 'returnValue' => 'languageId' + 'fields' => ['languageId' => false], + 'nested' => false, + 'returnValue' => 'languageId', ], 'createLocation' => [ 'fields' => [ @@ -255,9 +514,9 @@ private static function getMutationFields(string $mutationName): ?array 'locationPlatform' => true, 'canonical' => false, 'landingPage' => false, - 'fullTextUrl' => false + 'fullTextUrl' => false, ], - 'returnValue' => 'locationId' + 'returnValue' => 'locationId', ], 'updateLocation' => [ 'fields' => [ @@ -266,38 +525,36 @@ private static function getMutationFields(string $mutationName): ?array 'locationPlatform' => true, 'canonical' => false, 'landingPage' => false, - 'fullTextUrl' => false + 'fullTextUrl' => false, ], - 'returnValue' => 'locationId' + 'returnValue' => 'locationId', ], 'deleteLocation' => [ - 'fields' => [ - 'locationId' => false, - ], - 'returnValue' => 'locationId' + 'fields' => ['locationId' => false], + 'nested' => false, + 'returnValue' => 'locationId', ], 'createPrice' => [ 'fields' => [ 'publicationId' => false, 'currencyCode' => true, - 'unitPrice' => false + 'unitPrice' => false, ], - 'returnValue' => 'priceId' + 'returnValue' => 'priceId', ], 'updatePrice' => [ 'fields' => [ 'priceId' => false, 'publicationId' => false, 'currencyCode' => true, - 'unitPrice' => false + 'unitPrice' => false, ], - 'returnValue' => 'priceId' + 'returnValue' => 'priceId', ], 'deletePrice' => [ - 'fields' => [ - 'priceId' => false, - ], - 'returnValue' => 'priceId' + 'fields' => ['priceId' => false], + 'nested' => false, + 'returnValue' => 'priceId', ], 'createPublication' => [ 'fields' => [ @@ -311,9 +568,13 @@ private static function getMutationFields(string $mutationName): ?array 'heightIn' => false, 'weightG' => false, 'weightOz' => false, - 'isbn' => false + 'isbn' => false, + 'accessibilityStandard' => true, + 'accessibilityAdditionalStandard' => true, + 'accessibilityException' => true, + 'accessibilityReportUrl' => false, ], - 'returnValue' => 'publicationId' + 'returnValue' => 'publicationId', ], 'updatePublication' => [ 'fields' => [ @@ -328,38 +589,44 @@ private static function getMutationFields(string $mutationName): ?array 'heightIn' => false, 'weightG' => false, 'weightOz' => false, - 'isbn' => false + 'isbn' => false, + 'accessibilityStandard' => true, + 'accessibilityAdditionalStandard' => true, + 'accessibilityException' => true, + 'accessibilityReportUrl' => false, ], - 'returnValue' => 'publicationId' + 'returnValue' => 'publicationId', ], 'deletePublication' => [ - 'fields' => [ - 'publicationId' => false, - ], - 'returnValue' => 'publicationId' + 'fields' => ['publicationId' => false], + 'nested' => false, + 'returnValue' => 'publicationId', ], 'createPublisher' => [ 'fields' => [ 'publisherName' => false, 'publisherShortname' => false, - 'publisherUrl' => false + 'publisherUrl' => false, + 'accessibilityStatement' => false, + 'accessibilityReportUrl' => false, ], - 'returnValue' => 'publisherId' + 'returnValue' => 'publisherId', ], 'updatePublisher' => [ 'fields' => [ 'publisherId' => false, 'publisherName' => false, 'publisherShortname' => false, - 'publisherUrl' => false + 'publisherUrl' => false, + 'accessibilityStatement' => false, + 'accessibilityReportUrl' => false, ], - 'returnValue' => 'publisherId' + 'returnValue' => 'publisherId', ], 'deletePublisher' => [ - 'fields' => [ - 'publisherId' => false, - ], - 'returnValue' => 'publisherId' + 'fields' => ['publisherId' => false], + 'nested' => false, + 'returnValue' => 'publisherId', ], 'createReference' => [ 'fields' => [ @@ -384,9 +651,9 @@ private static function getMutationFields(string $mutationName): ?array 'standardsBodyAcronym' => false, 'url' => false, 'publicationDate' => false, - 'retrievalDate' => false + 'retrievalDate' => false, ], - 'returnValue' => 'referenceId' + 'returnValue' => 'referenceId', ], 'updateReference' => [ 'fields' => [ @@ -412,15 +679,14 @@ private static function getMutationFields(string $mutationName): ?array 'standardsBodyAcronym' => false, 'url' => false, 'publicationDate' => false, - 'retrievalDate' => false + 'retrievalDate' => false, ], - 'returnValue' => 'referenceId' + 'returnValue' => 'referenceId', ], 'deleteReference' => [ - 'fields' => [ - 'referenceId' => false, - ], - 'returnValue' => 'referenceId' + 'fields' => ['referenceId' => false], + 'nested' => false, + 'returnValue' => 'referenceId', ], 'createSeries' => [ 'fields' => [ @@ -431,9 +697,9 @@ private static function getMutationFields(string $mutationName): ?array 'issnDigital' => false, 'seriesUrl' => false, 'seriesDescription' => false, - 'seriesCfpUrl' => false + 'seriesCfpUrl' => false, ], - 'returnValue' => 'seriesId' + 'returnValue' => 'seriesId', ], 'updateSeries' => [ 'fields' => [ @@ -445,24 +711,23 @@ private static function getMutationFields(string $mutationName): ?array 'issnDigital' => false, 'seriesUrl' => false, 'seriesDescription' => false, - 'seriesCfpUrl' => false + 'seriesCfpUrl' => false, ], - 'returnValue' => 'seriesId' + 'returnValue' => 'seriesId', ], 'deleteSeries' => [ - 'fields' => [ - 'seriesId' => false, - ], - 'returnValue' => 'seriesId' + 'fields' => ['seriesId' => false], + 'nested' => false, + 'returnValue' => 'seriesId', ], 'createSubject' => [ 'fields' => [ 'workId' => false, 'subjectType' => true, 'subjectCode' => false, - 'subjectOrdinal' => false + 'subjectOrdinal' => false, ], - 'returnValue' => 'subjectId' + 'returnValue' => 'subjectId', ], 'updateSubject' => [ 'fields' => [ @@ -470,23 +735,49 @@ private static function getMutationFields(string $mutationName): ?array 'workId' => false, 'subjectType' => true, 'subjectCode' => false, - 'subjectOrdinal' => false + 'subjectOrdinal' => false, ], - 'returnValue' => 'subjectId' + 'returnValue' => 'subjectId', ], 'deleteSubject' => [ + 'fields' => ['subjectId' => false], + 'nested' => false, + 'returnValue' => 'subjectId', + ], + 'createTitle' => [ 'fields' => [ - 'subjectId' => false, + 'workId' => false, + 'localeCode' => true, + 'fullTitle' => false, + 'title' => false, + 'subtitle' => false, + 'canonical' => false, ], - 'returnValue' => 'subjectId' + 'extraArgs' => $markupArg, + 'returnValue' => 'titleId', ], - 'createWork' => [ + 'updateTitle' => [ 'fields' => [ - 'workType' => true, - 'workStatus' => true, + 'titleId' => false, + 'workId' => false, + 'localeCode' => true, 'fullTitle' => false, 'title' => false, 'subtitle' => false, + 'canonical' => false, + ], + 'extraArgs' => $markupArg, + 'returnValue' => 'titleId', + ], + 'deleteTitle' => [ + 'fields' => ['titleId' => false], + 'nested' => false, + 'returnValue' => 'titleId', + ], + 'createWork' => [ + 'fields' => [ + 'workType' => true, + 'workStatus' => true, 'reference' => false, 'edition' => false, 'imprintId' => false, @@ -505,27 +796,23 @@ private static function getMutationFields(string $mutationName): ?array 'landingPage' => false, 'lccn' => false, 'oclc' => false, - 'shortAbstract' => false, - 'longAbstract' => false, 'generalNote' => false, 'bibliographyNote' => false, 'toc' => false, + 'resourcesDescription' => false, 'coverUrl' => false, 'coverCaption' => false, 'firstPage' => false, 'lastPage' => false, - 'pageInterval' => false + 'pageInterval' => false, ], - 'returnValue' => 'workId' + 'returnValue' => 'workId', ], 'updateWork' => [ 'fields' => [ 'workId' => false, 'workType' => true, 'workStatus' => true, - 'fullTitle' => false, - 'title' => false, - 'subtitle' => false, 'reference' => false, 'edition' => false, 'imprintId' => false, @@ -544,33 +831,57 @@ private static function getMutationFields(string $mutationName): ?array 'landingPage' => false, 'lccn' => false, 'oclc' => false, - 'shortAbstract' => false, - 'longAbstract' => false, 'generalNote' => false, 'bibliographyNote' => false, 'toc' => false, + 'resourcesDescription' => false, 'coverUrl' => false, 'coverCaption' => false, 'firstPage' => false, 'lastPage' => false, - 'pageInterval' => false + 'pageInterval' => false, ], - 'returnValue' => 'workId' + 'returnValue' => 'workId', ], 'deleteWork' => [ + 'fields' => ['workId' => false], + 'nested' => false, + 'returnValue' => 'workId', + ], + 'createWorkFeaturedVideo' => [ + 'fields' => [ + 'workId' => false, + 'title' => false, + 'url' => false, + 'width' => false, + 'height' => false, + ], + 'returnValue' => 'workFeaturedVideoId', + ], + 'updateWorkFeaturedVideo' => [ 'fields' => [ + 'workFeaturedVideoId' => false, 'workId' => false, + 'title' => false, + 'url' => false, + 'width' => false, + 'height' => false, ], - 'returnValue' => 'workId' + 'returnValue' => 'workFeaturedVideoId', + ], + 'deleteWorkFeaturedVideo' => [ + 'fields' => ['workFeaturedVideoId' => false], + 'nested' => false, + 'returnValue' => 'workFeaturedVideoId', ], 'createWorkRelation' => [ 'fields' => [ 'relatorWorkId' => false, 'relatedWorkId' => false, 'relationType' => true, - 'relationOrdinal' => false + 'relationOrdinal' => false, ], - 'returnValue' => 'workRelationId' + 'returnValue' => 'workRelationId', ], 'updateWorkRelation' => [ 'fields' => [ @@ -578,16 +889,85 @@ private static function getMutationFields(string $mutationName): ?array 'relatorWorkId' => false, 'relatedWorkId' => false, 'relationType' => true, - 'relationOrdinal' => false + 'relationOrdinal' => false, ], - 'returnValue' => 'workRelationId' + 'returnValue' => 'workRelationId', ], 'deleteWorkRelation' => [ - 'fields' => [ - 'workRelationId' => false, - ], - 'returnValue' => 'workRelationId' - ] + 'fields' => ['workRelationId' => false], + 'nested' => false, + 'returnValue' => 'workRelationId', + ], + 'moveAffiliation' => [ + 'fields' => ['affiliationId' => false, 'newOrdinal' => false], + 'nested' => false, + 'returnValue' => 'affiliationId', + ], + 'moveContribution' => [ + 'fields' => ['contributionId' => false, 'newOrdinal' => false], + 'nested' => false, + 'returnValue' => 'contributionId', + ], + 'moveIssue' => [ + 'fields' => ['issueId' => false, 'newOrdinal' => false], + 'nested' => false, + 'returnValue' => 'issueId', + ], + 'moveReference' => [ + 'fields' => ['referenceId' => false, 'newOrdinal' => false], + 'nested' => false, + 'returnValue' => 'referenceId', + ], + 'moveAdditionalResource' => [ + 'fields' => ['additionalResourceId' => false, 'newOrdinal' => false], + 'nested' => false, + 'returnValue' => 'workResourceId', + ], + 'moveAward' => [ + 'fields' => ['awardId' => false, 'newOrdinal' => false], + 'nested' => false, + 'returnValue' => 'awardId', + ], + 'moveEndorsement' => [ + 'fields' => ['endorsementId' => false, 'newOrdinal' => false], + 'nested' => false, + 'returnValue' => 'endorsementId', + ], + 'moveBookReview' => [ + 'fields' => ['bookReviewId' => false, 'newOrdinal' => false], + 'nested' => false, + 'returnValue' => 'bookReviewId', + ], + 'moveSubject' => [ + 'fields' => ['subjectId' => false, 'newOrdinal' => false], + 'nested' => false, + 'returnValue' => 'subjectId', + ], + 'moveWorkRelation' => [ + 'fields' => ['workRelationId' => false, 'newOrdinal' => false], + 'nested' => false, + 'returnValue' => 'workRelationId', + ], + 'initPublicationFileUpload' => [ + 'fields' => ['publicationId' => false] + $uploadFields, + 'returnValue' => 'fileUploadId', + ], + 'initFrontcoverFileUpload' => [ + 'fields' => ['workId' => false] + $uploadFields, + 'returnValue' => 'fileUploadId', + ], + 'initAdditionalResourceFileUpload' => [ + 'fields' => ['additionalResourceId' => false] + $uploadFields, + 'returnValue' => 'fileUploadId', + ], + 'initWorkFeaturedVideoFileUpload' => [ + 'fields' => ['workFeaturedVideoId' => false] + $uploadFields, + 'returnValue' => 'fileUploadId', + ], + 'completeFileUpload' => [ + 'fields' => ['fileUploadId' => false], + 'returnValue' => 'fileId', + ], ]; return $mapping[$mutationName] ?? null; diff --git a/src/GraphQL/Queries/AbstractTextQuery.php b/src/GraphQL/Queries/AbstractTextQuery.php new file mode 100644 index 0000000..88ce488 --- /dev/null +++ b/src/GraphQL/Queries/AbstractTextQuery.php @@ -0,0 +1,67 @@ +buildQuery( + <<buildQuery( + <<buildQuery( + <<buildQuery( + <<buildQuery( + <<buildQuery( + <<buildQuery( + <<buildQuery( + <<buildQuery( + <<buildQuery( + <<buildQuery( + <<buildQuery( + <<buildQuery( + <<buildQuery( + <<buildQuery( + <<buildQuery( + <<buildQuery( <<buildQuery( + <<buildQuery( + <<buildQuery( + <<buildQuery( + << (new FileQuery())->getQuery(), + 'me' => (new MeQuery())->getQuery(), + ] ); } @@ -83,4 +107,12 @@ private static function mapWorkQueries(WorkQuery $workQuery): array 'workCount' => $workQuery->getCountQuery(), ]; } + + private static function mapMarkupQuery(AbstractQuery $queryObject, string $name): array + { + return [ + $name => $queryObject->getQuery(), + $name . 's' => $queryObject->getManyQuery(), + ]; + } } diff --git a/tests/GraphQL/MutationBuilderTest.php b/tests/GraphQL/MutationBuilderTest.php index b13807c..2b5faf0 100644 --- a/tests/GraphQL/MutationBuilderTest.php +++ b/tests/GraphQL/MutationBuilderTest.php @@ -109,8 +109,7 @@ public function testBuildCreateContributionMutation(): void 'contributionOrdinal: 1, ' . 'firstName: "John", ' . 'lastName: "Doe", ' . - 'fullName: "John Doe", ' . - 'biography: "Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae."'; + 'fullName: "John Doe"'; $returnValue = 'contributionId'; $expectedMutation = << 'John', 'lastName' => 'Doe', 'fullName' => 'John Doe', - 'biography' => 'Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae.', ]); $this->assertSame($expectedMutation, $mutation); @@ -149,8 +147,7 @@ public function testBuildUpdateContributionMutation(): void 'contributionOrdinal: 1, ' . 'firstName: "John", ' . 'lastName: "Doe", ' . - 'fullName: "John Doe", ' . - 'biography: "Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae."'; + 'fullName: "John Doe"'; $returnValue = 'contributionId'; $expectedMutation = << 'John', 'lastName' => 'Doe', 'fullName' => 'John Doe', - 'biography' => 'Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae.', ]); $this->assertSame($expectedMutation, $mutation); @@ -301,8 +297,7 @@ public function testBuildCreateFundingMutation(): void 'program: "FSE", ' . 'projectName: "Marine Renewable Energy as Alien", ' . 'projectShortname: "Alien Energy", ' . - 'grantNumber: "0602-02551B", ' . - 'jurisdiction: "DK"'; + 'grantNumber: "0602-02551B"'; $returnValue = 'fundingId'; $expectedMutation = << 'Marine Renewable Energy as Alien', 'projectShortname' => 'Alien Energy', 'grantNumber' => '0602-02551B', - 'jurisdiction' => 'DK' ]); $this->assertSame($expectedMutation, $mutation); @@ -337,8 +331,7 @@ public function testBuildUpdateFundingMutation(): void 'program: "FSE", ' . 'projectName: "Marine Renewable Energy as Alien", ' . 'projectShortname: "Alien Energy", ' . - 'grantNumber: "0602-02551B", ' . - 'jurisdiction: "DK"'; + 'grantNumber: "0602-02551B"'; $returnValue = 'fundingId'; $expectedMutation = << 'Marine Renewable Energy as Alien', 'projectShortname' => 'Alien Energy', 'grantNumber' => '0602-02551B', - 'jurisdiction' => 'DK' ]); $this->assertSame($expectedMutation, $mutation); @@ -646,8 +638,7 @@ public function testBuildCreateLanguageMutation(): void $mutationName = 'createLanguage'; $data = 'workId: "dcff2c6a-a81d-4af5-a08b-cef22928911b", ' . 'languageCode: AAR, ' . - 'languageRelation: ORIGINAL, ' . - 'mainLanguage: true'; + 'languageRelation: ORIGINAL'; $returnValue = 'languageId'; $expectedMutation = << 'dcff2c6a-a81d-4af5-a08b-cef22928911b', 'languageCode' => 'AAR', 'languageRelation' => 'ORIGINAL', - 'mainLanguage' => true ]); $this->assertSame($expectedMutation, $mutation); @@ -676,8 +666,7 @@ public function testBuildUpdateLanguageMutation(): void $data = 'languageId: "c5fe1926-d702-468b-b98e-984e1b49acf9", ' . 'workId: "dcff2c6a-a81d-4af5-a08b-cef22928911b", ' . 'languageCode: AAR, ' . - 'languageRelation: ORIGINAL, ' . - 'mainLanguage: true'; + 'languageRelation: ORIGINAL'; $returnValue = 'languageId'; $expectedMutation = << 'dcff2c6a-a81d-4af5-a08b-cef22928911b', 'languageCode' => 'AAR', 'languageRelation' => 'ORIGINAL', - 'mainLanguage' => true ]); $this->assertSame($expectedMutation, $mutation); @@ -1426,9 +1414,6 @@ public function testBuildCreateWorkMutation(): void $mutationName = 'createWork'; $data = 'workType: BOOK_CHAPTER, ' . 'workStatus: FORTHCOMING, ' . - 'fullTitle: "Lorem ipsum: Neque porro quisquam est", ' . - 'title: "Lorem ipsum", ' . - 'subtitle: "Neque porro quisquam est", ' . 'reference: "foo", ' . 'edition: 10, ' . 'imprintId: "dd0410c9-d5f9-43c9-8289-adfd9fc8bded", ' . @@ -1447,8 +1432,6 @@ public function testBuildCreateWorkMutation(): void 'landingPage: "https:\/\/foo.bar\/lorem-ipsum\/", ' . 'lccn: "2014471418", ' . 'oclc: "1086518639", ' . - 'shortAbstract: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam viverra ut finibus suscipit", ' . - 'longAbstract: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam viverra nulla ut finibus suscipit. Etiam dictum cursus dolor, in fringilla felis placerat sed. Fusce aliquam orci ut sapie lobortis, id cursus dolor dapibus. Nunc vitae ligula nec ex ornare pretium. Donec et purus ac ipsumfinibus faucibus. Fusce at ipsum velit.", ' . 'generalNote: "Sed nunc dui, semper eu semper vel, bibendum in nulla.", ' . 'bibliographyNote: "Phasellus ac gravida odio. Mauris nec sodales odio", ' . 'toc: "0. Introduction\n1. Lorem ipsum dolor sit amet\n2. Nullam viverra ut finibus suscipit\n3. Etiam dictum cursus dolor\n4. Conclusions", ' . @@ -1472,15 +1455,11 @@ public function testBuildCreateWorkMutation(): void $mutation = MutationBuilder::build('createWork', [ 'workType' => 'BOOK_CHAPTER', 'workStatus' => 'FORTHCOMING', - 'fullTitle' => 'Lorem ipsum: Neque porro quisquam est', - 'title' => 'Lorem ipsum', 'imprintId' => 'dd0410c9-d5f9-43c9-8289-adfd9fc8bded', 'withdrawnDate' => '2020-12-12', 'videoCount' => 10, 'toc' => "0. Introduction\n1. Lorem ipsum dolor sit amet\n2. Nullam viverra ut finibus suscipit\n3. Etiam dictum cursus dolor\n4. Conclusions", 'tableCount' => 10, - 'subtitle' => 'Neque porro quisquam est', - 'shortAbstract' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam viverra ut finibus suscipit', 'reference' => 'foo', 'publicationDate' => '2020-01-01', 'place' => 'Earth, Milky Way', @@ -1488,7 +1467,6 @@ public function testBuildCreateWorkMutation(): void 'pageCount' => 10, 'pageBreakdown' => '0', 'oclc' => '1086518639', - 'longAbstract' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam viverra nulla ut finibus suscipit. Etiam dictum cursus dolor, in fringilla felis placerat sed. Fusce aliquam orci ut sapie lobortis, id cursus dolor dapibus. Nunc vitae ligula nec ex ornare pretium. Donec et purus ac ipsumfinibus faucibus. Fusce at ipsum velit.', 'license' => 'https://creativecommons.org/licenses/by-nc/4.0/', 'lccn' => '2014471418', 'lastPage' => '326', @@ -1514,9 +1492,6 @@ public function testBuildUpdateWorkMutation(): void $data = 'workId: "de7387a8-dd91-44ec-87c5-f8dba3f82b99", ' . 'workType: BOOK_CHAPTER, ' . 'workStatus: FORTHCOMING, ' . - 'fullTitle: "Lorem ipsum: Neque porro quisquam est", ' . - 'title: "Lorem ipsum", ' . - 'subtitle: "Neque porro quisquam est", ' . 'reference: "foo", ' . 'edition: 10, ' . 'imprintId: "dd0410c9-d5f9-43c9-8289-adfd9fc8bded", ' . @@ -1535,8 +1510,6 @@ public function testBuildUpdateWorkMutation(): void 'landingPage: "https:\/\/foo.bar\/lorem-ipsum\/", ' . 'lccn: "2014471418", ' . 'oclc: "1086518639", ' . - 'shortAbstract: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam viverra ut finibus suscipit", ' . - 'longAbstract: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam viverra nulla ut finibus suscipit. Etiam dictum cursus dolor, in fringilla felis placerat sed. Fusce aliquam orci ut sapie lobortis, id cursus dolor dapibus. Nunc vitae ligula nec ex ornare pretium. Donec et purus ac ipsumfinibus faucibus. Fusce at ipsum velit.", ' . 'generalNote: "Sed nunc dui, semper eu semper vel, bibendum in nulla.", ' . 'bibliographyNote: "Phasellus ac gravida odio. Mauris nec sodales odio", ' . 'toc: "0. Introduction\n1. Lorem ipsum dolor sit amet\n2. Nullam viverra ut finibus suscipit\n3. Etiam dictum cursus dolor\n4. Conclusions", ' . @@ -1561,15 +1534,11 @@ public function testBuildUpdateWorkMutation(): void 'workId' => 'de7387a8-dd91-44ec-87c5-f8dba3f82b99', 'workType' => 'BOOK_CHAPTER', 'workStatus' => 'FORTHCOMING', - 'fullTitle' => 'Lorem ipsum: Neque porro quisquam est', - 'title' => 'Lorem ipsum', 'imprintId' => 'dd0410c9-d5f9-43c9-8289-adfd9fc8bded', 'withdrawnDate' => '2020-12-12', 'videoCount' => 10, 'toc' => "0. Introduction\n1. Lorem ipsum dolor sit amet\n2. Nullam viverra ut finibus suscipit\n3. Etiam dictum cursus dolor\n4. Conclusions", 'tableCount' => 10, - 'subtitle' => 'Neque porro quisquam est', - 'shortAbstract' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam viverra ut finibus suscipit', 'reference' => 'foo', 'publicationDate' => '2020-01-01', 'place' => 'Earth, Milky Way', @@ -1577,7 +1546,6 @@ public function testBuildUpdateWorkMutation(): void 'pageCount' => 10, 'pageBreakdown' => '0', 'oclc' => '1086518639', - 'longAbstract' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam viverra nulla ut finibus suscipit. Etiam dictum cursus dolor, in fringilla felis placerat sed. Fusce aliquam orci ut sapie lobortis, id cursus dolor dapibus. Nunc vitae ligula nec ex ornare pretium. Donec et purus ac ipsumfinibus faucibus. Fusce at ipsum velit.', 'license' => 'https://creativecommons.org/licenses/by-nc/4.0/', 'lccn' => '2014471418', 'lastPage' => '326', diff --git a/tests/GraphQL/Queries/ContributionQueryTest.php b/tests/GraphQL/Queries/ContributionQueryTest.php index 31ba752..c36d548 100644 --- a/tests/GraphQL/Queries/ContributionQueryTest.php +++ b/tests/GraphQL/Queries/ContributionQueryTest.php @@ -83,11 +83,16 @@ private function getFieldsFragment(): string workId contributionType mainContribution - biography firstName lastName fullName contributionOrdinal + biographies { + biographyId + localeCode + content + canonical + } } GQL; } diff --git a/tests/GraphQL/Queries/FundingQueryTest.php b/tests/GraphQL/Queries/FundingQueryTest.php index 5689224..e879f8b 100644 --- a/tests/GraphQL/Queries/FundingQueryTest.php +++ b/tests/GraphQL/Queries/FundingQueryTest.php @@ -83,7 +83,6 @@ private function getFieldsFragment(): string projectName projectShortname grantNumber - jurisdiction } GQL; } diff --git a/tests/GraphQL/Queries/ImprintQueryTest.php b/tests/GraphQL/Queries/ImprintQueryTest.php index b0e9ff6..dd10d85 100644 --- a/tests/GraphQL/Queries/ImprintQueryTest.php +++ b/tests/GraphQL/Queries/ImprintQueryTest.php @@ -89,6 +89,12 @@ public function getFieldsFragment(): string imprintName imprintUrl crossmarkDoi + s3Bucket + cdnDomain + cloudfrontDistId + defaultCurrency + defaultPlace + defaultLocale } GQL; } diff --git a/tests/GraphQL/Queries/IssueQueryTest.php b/tests/GraphQL/Queries/IssueQueryTest.php index 9d16398..1c29094 100644 --- a/tests/GraphQL/Queries/IssueQueryTest.php +++ b/tests/GraphQL/Queries/IssueQueryTest.php @@ -80,6 +80,7 @@ public function getFieldsFragment(): string workId seriesId issueOrdinal + issueNumber } GQL; } diff --git a/tests/GraphQL/Queries/LanguageQueryTest.php b/tests/GraphQL/Queries/LanguageQueryTest.php index ae060f4..925d405 100644 --- a/tests/GraphQL/Queries/LanguageQueryTest.php +++ b/tests/GraphQL/Queries/LanguageQueryTest.php @@ -90,7 +90,6 @@ public function getFieldsFragment(): string workId languageCode languageRelation - mainLanguage } GQL; } diff --git a/tests/GraphQL/Queries/PublicationQueryTest.php b/tests/GraphQL/Queries/PublicationQueryTest.php index 831c5c6..5bdb4c9 100644 --- a/tests/GraphQL/Queries/PublicationQueryTest.php +++ b/tests/GraphQL/Queries/PublicationQueryTest.php @@ -102,6 +102,10 @@ public function getFieldsFragment(): string height(units: \$lengthUnit) depth(units: \$lengthUnit) weight(units: \$weightUnit) + accessibilityStandard + accessibilityAdditionalStandard + accessibilityException + accessibilityReportUrl } GQL; } diff --git a/tests/GraphQL/Queries/PublisherQueryTest.php b/tests/GraphQL/Queries/PublisherQueryTest.php index 0157991..dc5333b 100644 --- a/tests/GraphQL/Queries/PublisherQueryTest.php +++ b/tests/GraphQL/Queries/PublisherQueryTest.php @@ -88,6 +88,9 @@ public function getFieldsFragment(): string publisherName publisherShortname publisherUrl + zitadelId + accessibilityStatement + accessibilityReportUrl } GQL; } diff --git a/tests/GraphQL/Queries/SeriesQueryTest.php b/tests/GraphQL/Queries/SeriesQueryTest.php index ea86c85..b0ba2a5 100644 --- a/tests/GraphQL/Queries/SeriesQueryTest.php +++ b/tests/GraphQL/Queries/SeriesQueryTest.php @@ -18,8 +18,8 @@ public function testGetSeriesQuery(): void { $fragment = $this->getFieldsFragment(); $expectedQuery = << Date: Fri, 10 Apr 2026 17:33:49 -0400 Subject: [PATCH 2/8] fix(graphql): remove legacy account login support --- README.md | 4 +- docs/README-es.md | 4 +- docs/README-pt_BR.md | 4 +- src/GraphQL/Account.php | 33 -------------- src/GraphQL/Client.php | 11 ----- tests/GraphQL/AccountTest.php | 81 ----------------------------------- tests/GraphQL/ClientTest.php | 17 -------- 7 files changed, 6 insertions(+), 148 deletions(-) delete mode 100644 src/GraphQL/Account.php delete mode 100644 tests/GraphQL/AccountTest.php diff --git a/README.md b/README.md index 933893f..0631a4d 100644 --- a/README.md +++ b/README.md @@ -75,10 +75,10 @@ $works = $client->works([ #### Mutations -To execute mutations, authentication with a Thoth account's credentials is required. +To execute mutations, provide a valid Thoth API bearer token to the client. ```php -$client->login($email, $password); +$client->setToken($token); ``` Mutations can be executed by providing an instance of the model class corresponding to the mutation type. To delete mutations, only the object's ID is required. When the operation is successful, the object's ID is returned. diff --git a/docs/README-es.md b/docs/README-es.md index 43ff000..b69dcea 100644 --- a/docs/README-es.md +++ b/docs/README-es.md @@ -67,10 +67,10 @@ $works = $client->works([ #### Mutaciones -Para ejecutar mutaciones es necesario autenticarse con las credenciales de una cuenta de Thoth. +Para ejecutar mutaciones, proporcione al cliente un token bearer valido de la API de Thoth. ```php -$client->login($email, $password); +$client->setToken($token); ``` Las mutaciones pueden ejecutarse proporcionando una instancia de la clase modelo correspondiente al tipo de mutación. Para las mutaciones de eliminación, solo es necesario proporcionar la ID del objeto. Cuando la operación se realiza con éxito, se devuelve la ID del objeto. diff --git a/docs/README-pt_BR.md b/docs/README-pt_BR.md index 772eda4..36a1490 100644 --- a/docs/README-pt_BR.md +++ b/docs/README-pt_BR.md @@ -67,10 +67,10 @@ $works = $client->works([ #### Mutações -Para executar mutações é necessário realizar a autenticação com as credenciais de uma conta Thoth. +Para executar mutações, forneça ao cliente um token bearer válido da API Thoth. ```php -$client->login($email, $password); +$client->setToken($token); ``` Mutações podem ser executadas fornecendo uma instância da classe modelo correspondente ao tipo da mutação. Para mutações de exclusão, é necessário apenas fornecer o ID do objeto. Quando a operação é bem-sucedida, o ID do objeto é retornado. diff --git a/src/GraphQL/Account.php b/src/GraphQL/Account.php deleted file mode 100644 index 0016d87..0000000 --- a/src/GraphQL/Account.php +++ /dev/null @@ -1,33 +0,0 @@ -request = $request; - } - - public function login(string $email, string $password): string - { - $response = $this->request->execute('POST', self::THOTH_ACCOUNT_ENDPOINT . '/login', ['json' => [ - 'email' => $email, 'password' => $password - ]]); - - return json_decode($response->getBody())->token; - } - - public function details(string $token): array - { - $response = $this->request->execute('GET', self::THOTH_ACCOUNT_ENDPOINT, ['headers' => [ - 'Authorization' => 'Bearer ' . $token - ]]); - - return json_decode($response->getBody(), true); - } -} diff --git a/src/GraphQL/Client.php b/src/GraphQL/Client.php index 90d181d..cda0d15 100644 --- a/src/GraphQL/Client.php +++ b/src/GraphQL/Client.php @@ -55,17 +55,6 @@ public function setToken(string $token): self return $this; } - public function login(string $email, string $password): self - { - $this->token = (new Account($this->request))->login($email, $password); - return $this; - } - - public function accountDetails(): array - { - return (new Account($this->request))->details($this->token); - } - public function additionalResource(string $additionalResourceId): AdditionalResource { return $this->get('additionalResource', $additionalResourceId); diff --git a/tests/GraphQL/AccountTest.php b/tests/GraphQL/AccountTest.php deleted file mode 100644 index e001e06..0000000 --- a/tests/GraphQL/AccountTest.php +++ /dev/null @@ -1,81 +0,0 @@ -mockHandler = new MockHandler(); - $handler = HandlerStack::create($this->mockHandler); - $request = new Request(['handler' => $handler]); - $this->account = new Account($request); - } - - public function testLogin(): void - { - $this->mockHandler->append(new Response(200, [], $this->getAccountResponse())); - - $token = $this->account->login('johndoe@mailinator.com', 'secret123'); - $this->assertSame('someVeryLongJWT', $token); - } - - public function testLoginWithInvalidCredentials(): void - { - $this->mockHandler->append(new ClientException( - '', - new GuzzleRequest('post', ''), - new Response(400, [], json_encode(['Invalid credentials.'])) - )); - - $this->expectException(QueryException::class); - $this->expectExceptionMessage('Invalid credentials.'); - $token = $this->account->login('johndoe@mailinator.com', 'secret123'); - } - - public function testGetAccountDetails(): void - { - $expectedDetails = $this->getAccountResponse(); - $this->mockHandler->append(new Response(200, [], $expectedDetails)); - - $details = $this->account->details('bot@mailinator.com', 'invalidpassword'); - $this->assertSame(json_decode($expectedDetails, true), $details); - } - - private function getAccountResponse(): string - { - return '{ - "accountId":"60828981-63c3-40c1-83e5-42d19565cde5", - "name":"John", - "surname":"Doe", - "email":"johndoe@mailinator.com", - "token":"someVeryLongJWT", - "createdAt":"2020-01-01T21:56:58.271962Z", - "updatedAt":"2020-01-07T23:42:08.317293Z", - "resourceAccess": { - "isSuperuser":true, - "isBot":false, - "linkedPublishers":[ - { - "publisherId":"ffea0d2d-6ead-4cf6-95f2-6d675836e948", - "isAdmin":true - } - ] - } - }'; - } -} diff --git a/tests/GraphQL/ClientTest.php b/tests/GraphQL/ClientTest.php index e132c69..d082f07 100644 --- a/tests/GraphQL/ClientTest.php +++ b/tests/GraphQL/ClientTest.php @@ -38,23 +38,6 @@ protected function setUp(): void $this->client = new Client(['handler' => $handler]); } - public function testGetAccountDetails(): void - { - $expectedDetails = [ - 'accountId' => 'c00ac1b7-5fda-468d-8634-707cd069f560' - ]; - $this->mockHandler->append(new Response(200, [], json_encode([ - 'token' => 'someLongToken' - ]))); - $this->mockHandler->append(new Response(200, [], json_encode($expectedDetails))); - - $email = 'user@mailinator.com'; - $password = 'secret'; - - $accountDetails = $this->client->login($email, $password)->accountDetails(); - $this->assertSame($expectedDetails, $accountDetails); - } - public function testAffiliation(): void { $affiliation = new Affiliation(['affiliationId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); From 218d53bdb274b759dfc3aa2e569c07c16ab7cf3f Mon Sep 17 00:00:00 2001 From: Thiago Matos Date: Fri, 10 Apr 2026 18:12:49 -0400 Subject: [PATCH 3/8] refactor(graphql): split client operations into traits --- src/GraphQL/Client.php | 925 +-------- .../Concerns/HasMutationOperations.php | 524 +++++ src/GraphQL/Concerns/HasQueryOperations.php | 440 ++++ tests/GraphQL/ClientTest.php | 1770 +---------------- .../Concerns/HasClientMutationTests.php | 773 +++++++ .../GraphQL/Concerns/HasClientQueryTests.php | 1024 ++++++++++ 6 files changed, 2771 insertions(+), 2685 deletions(-) create mode 100644 src/GraphQL/Concerns/HasMutationOperations.php create mode 100644 src/GraphQL/Concerns/HasQueryOperations.php create mode 100644 tests/GraphQL/Concerns/HasClientMutationTests.php create mode 100644 tests/GraphQL/Concerns/HasClientQueryTests.php diff --git a/src/GraphQL/Client.php b/src/GraphQL/Client.php index cda0d15..fde35cd 100644 --- a/src/GraphQL/Client.php +++ b/src/GraphQL/Client.php @@ -2,39 +2,19 @@ namespace ThothApi\GraphQL; +use ThothApi\GraphQL\Concerns\HasMutationOperations; +use ThothApi\GraphQL\Concerns\HasQueryOperations; use ThothApi\GraphQL\Models\AbstractModel; use ThothApi\GraphQL\Models\AbstractText; use ThothApi\GraphQL\Models\AdditionalResource; -use ThothApi\GraphQL\Models\Affiliation; -use ThothApi\GraphQL\Models\Award; -use ThothApi\GraphQL\Models\Biography; -use ThothApi\GraphQL\Models\BookReview; -use ThothApi\GraphQL\Models\Contact; -use ThothApi\GraphQL\Models\Contribution; -use ThothApi\GraphQL\Models\Contributor; -use ThothApi\GraphQL\Models\Endorsement; -use ThothApi\GraphQL\Models\File; -use ThothApi\GraphQL\Models\FileUploadResponse; -use ThothApi\GraphQL\Models\Funding; -use ThothApi\GraphQL\Models\Imprint; -use ThothApi\GraphQL\Models\Institution; -use ThothApi\GraphQL\Models\Issue; -use ThothApi\GraphQL\Models\Language; -use ThothApi\GraphQL\Models\Location; use ThothApi\GraphQL\Models\Me; -use ThothApi\GraphQL\Models\Price; -use ThothApi\GraphQL\Models\Publication; -use ThothApi\GraphQL\Models\Publisher; -use ThothApi\GraphQL\Models\Reference; -use ThothApi\GraphQL\Models\Series; -use ThothApi\GraphQL\Models\Subject; -use ThothApi\GraphQL\Models\Title; use ThothApi\GraphQL\Models\Work; -use ThothApi\GraphQL\Models\WorkFeaturedVideo; -use ThothApi\GraphQL\Models\WorkRelation; class Client { + use HasMutationOperations; + use HasQueryOperations; + private Request $request; private string $token = ''; @@ -55,901 +35,6 @@ public function setToken(string $token): self return $this; } - public function additionalResource(string $additionalResourceId): AdditionalResource - { - return $this->get('additionalResource', $additionalResourceId); - } - - public function additionalResources(array $args = []): array - { - return $this->getMany('additionalResource', $args); - } - - public function additionalResourceCount(): int - { - return $this->count('additionalResource'); - } - - public function affiliation(string $affiliationId): Affiliation - { - return $this->get('affiliation', $affiliationId); - } - - public function affiliations(array $args = []): array - { - return $this->getMany('affiliation', $args); - } - - public function affiliationCount(): int - { - return $this->count('affiliation'); - } - - public function abstract(string $abstractId, ?string $markupFormat = null): AbstractText - { - return $this->get('abstract', $abstractId, ['markupFormat' => $markupFormat]); - } - - public function abstracts(array $args = []): array - { - return $this->getMany('abstract', $args); - } - - public function award(string $awardId): Award - { - return $this->get('award', $awardId); - } - - public function awards(array $args = []): array - { - return $this->getMany('award', $args); - } - - public function awardCount(): int - { - return $this->count('award'); - } - - public function biography(string $biographyId, ?string $markupFormat = null): Biography - { - return $this->get('biography', $biographyId, ['markupFormat' => $markupFormat]); - } - - public function biographies(array $args = []): array - { - return $this->getMany('biography', $args); - } - - public function books(array $args = []): array - { - return $this->getMany('book', $args); - } - - public function bookByDoi(string $doi): Work - { - return $this->getByDoi('book', $doi); - } - - public function bookCount(array $args = []): int - { - return $this->count('book', $args); - } - - public function bookReview(string $bookReviewId): BookReview - { - return $this->get('bookReview', $bookReviewId); - } - - public function bookReviews(array $args = []): array - { - return $this->getMany('bookReview', $args); - } - - public function bookReviewCount(): int - { - return $this->count('bookReview'); - } - - public function chapters(array $args = []): array - { - return $this->getMany('chapter', $args); - } - - public function chapterByDoi(string $doi): Work - { - return $this->getByDoi('chapter', $doi); - } - - public function chapterCount(array $args = []): int - { - return $this->count('chapter', $args); - } - - public function contact(string $contactId): Contact - { - return $this->get('contact', $contactId); - } - - public function contacts(array $args = []): array - { - return $this->getMany('contact', $args); - } - - public function contactCount(array $args = []): int - { - return $this->count('contact', $args); - } - - public function contribution(string $contributionId): Contribution - { - return $this->get('contribution', $contributionId); - } - - public function contributions(array $args = []): array - { - return $this->getMany('contribution', $args); - } - - public function contributionCount(array $args = []): int - { - return $this->count('contribution', $args); - } - - public function contributor(string $contributorId): Contributor - { - return $this->get('contributor', $contributorId); - } - - public function contributors(array $args = []): array - { - return $this->getMany('contributor', $args); - } - - public function contributorCount(array $args = []): int - { - return $this->count('contributor', $args); - } - - public function endorsement(string $endorsementId): Endorsement - { - return $this->get('endorsement', $endorsementId); - } - - public function endorsements(array $args = []): array - { - return $this->getMany('endorsement', $args); - } - - public function endorsementCount(): int - { - return $this->count('endorsement'); - } - - public function file(string $fileId): File - { - return $this->get('file', $fileId); - } - - public function funding(string $fundingId): Funding - { - return $this->get('funding', $fundingId); - } - - public function fundings(array $args = []): array - { - return $this->getMany('funding', $args); - } - - public function fundingCount(): int - { - return $this->count('funding'); - } - - public function imprint(string $imprintId): Imprint - { - return $this->get('imprint', $imprintId); - } - - public function imprints(array $args = []): array - { - return $this->getMany('imprint', $args); - } - - public function imprintCount(array $args = []): int - { - return $this->count('imprint', $args); - } - - public function institution(string $institutionId): Institution - { - return $this->get('institution', $institutionId); - } - - public function institutions(array $args = []): array - { - return $this->getMany('institution', $args); - } - - public function institutionCount(array $args = []): int - { - return $this->count('institution', $args); - } - - public function issue(string $issueId): Issue - { - return $this->get('issue', $issueId); - } - - public function issues(array $args = []): array - { - return $this->getMany('issue', $args); - } - - public function issueCount(): int - { - return $this->count('issue'); - } - - public function language(string $languageId): Language - { - return $this->get('language', $languageId); - } - - public function languages(array $args = []): array - { - return $this->getMany('language', $args); - } - - public function languageCount(array $args = []): int - { - return $this->count('language', $args); - } - - public function location(string $locationId): Location - { - return $this->get('location', $locationId); - } - - public function locations(array $args = []): array - { - return $this->getMany('location', $args); - } - - public function locationCount(array $args = []): int - { - return $this->count('location', $args); - } - - public function me(): Me - { - $result = $this->query('me', [], $this->token); - return new Me($result['me']); - } - - public function price(string $priceId): Price - { - return $this->get('price', $priceId); - } - - public function prices(array $args = []): array - { - return $this->getMany('price', $args); - } - - public function priceCount(array $args = []): int - { - return $this->count('price', $args); - } - - public function publication(string $publicationId): Publication - { - return $this->get('publication', $publicationId); - } - - public function publications(array $args = []): array - { - return $this->getMany('publication', $args); - } - - public function publicationCount(array $args = []): int - { - return $this->count('publication', $args); - } - - public function publisher(string $publisherId): Publisher - { - return $this->get('publisher', $publisherId); - } - - public function publishers(array $args = []): array - { - return $this->getMany('publisher', $args); - } - - public function publisherCount(array $args = []): int - { - return $this->count('publisher', $args); - } - - public function reference(string $referenceId): Reference - { - return $this->get('reference', $referenceId); - } - - public function references(array $args = []): array - { - return $this->getMany('reference', $args); - } - - public function referenceCount(): int - { - return $this->count('reference'); - } - - public function series(string $seriesId): Series - { - return $this->get('series', $seriesId); - } - - public function serieses(array $args = []): array - { - return $this->getMany('series', $args); - } - - public function seriesCount(array $args = []): int - { - return $this->count('series', $args); - } - - public function subject(string $subjectId): Subject - { - return $this->get('subject', $subjectId); - } - - public function subjects(array $args = []): array - { - return $this->getMany('subject', $args); - } - - public function subjectCount(array $args = []): int - { - return $this->count('subject', $args); - } - - public function title(string $titleId, ?string $markupFormat = null): Title - { - return $this->get('title', $titleId, ['markupFormat' => $markupFormat]); - } - - public function titles(array $args = []): array - { - return $this->getMany('title', $args); - } - - public function work(string $workId): Work - { - return $this->get('work', $workId); - } - - public function works(array $args = []): array - { - return $this->getMany('work', $args); - } - - public function workByDoi(string $doi): Work - { - return $this->getByDoi('work', $doi); - } - - public function workCount(array $args = []): int - { - return $this->count('work', $args); - } - - public function workFeaturedVideo(string $workFeaturedVideoId): WorkFeaturedVideo - { - return $this->get('workFeaturedVideo', $workFeaturedVideoId); - } - - public function workFeaturedVideos(array $args = []): array - { - return $this->getMany('workFeaturedVideo', $args); - } - - public function workFeaturedVideoCount(): int - { - return $this->count('workFeaturedVideo'); - } - - public function createAdditionalResource(AdditionalResource $additionalResource, ?string $markupFormat = null): string - { - return $this->mutation( - 'createAdditionalResource', - $additionalResource->getAllData(), - 'workResourceId', - ['markupFormat' => $markupFormat] - ); - } - - public function updateAdditionalResource(AdditionalResource $additionalResource, ?string $markupFormat = null): string - { - return $this->mutation( - 'updateAdditionalResource', - $additionalResource->getAllData(), - 'workResourceId', - ['markupFormat' => $markupFormat] - ); - } - - public function deleteAdditionalResource(string $additionalResourceId): string - { - return $this->mutation( - 'deleteAdditionalResource', - ['additionalResourceId' => $additionalResourceId], - 'workResourceId' - ); - } - - public function createAffiliation(Affiliation $affiliation): string - { - return $this->mutation('createAffiliation', $affiliation->getAllData(), 'affiliationId'); - } - - public function updateAffiliation(Affiliation $affiliation): string - { - return $this->mutation('updateAffiliation', $affiliation->getAllData(), 'affiliationId'); - } - - public function deleteAffiliation(string $affiliationId): string - { - return $this->mutation('deleteAffiliation', ['affiliationId' => $affiliationId], 'affiliationId'); - } - - public function createAbstract(AbstractText $abstract, ?string $markupFormat = null): string - { - return $this->mutation('createAbstract', $abstract->getAllData(), 'abstractId', ['markupFormat' => $markupFormat]); - } - - public function updateAbstract(AbstractText $abstract, ?string $markupFormat = null): string - { - return $this->mutation('updateAbstract', $abstract->getAllData(), 'abstractId', ['markupFormat' => $markupFormat]); - } - - public function deleteAbstract(string $abstractId): string - { - return $this->mutation('deleteAbstract', ['abstractId' => $abstractId], 'abstractId'); - } - - public function createAward(Award $award, ?string $markupFormat = null): string - { - return $this->mutation('createAward', $award->getAllData(), 'awardId', ['markupFormat' => $markupFormat]); - } - - public function updateAward(Award $award, ?string $markupFormat = null): string - { - return $this->mutation('updateAward', $award->getAllData(), 'awardId', ['markupFormat' => $markupFormat]); - } - - public function deleteAward(string $awardId): string - { - return $this->mutation('deleteAward', ['awardId' => $awardId], 'awardId'); - } - - public function createBiography(Biography $biography, ?string $markupFormat = null): string - { - return $this->mutation('createBiography', $biography->getAllData(), 'biographyId', ['markupFormat' => $markupFormat]); - } - - public function updateBiography(Biography $biography, ?string $markupFormat = null): string - { - return $this->mutation('updateBiography', $biography->getAllData(), 'biographyId', ['markupFormat' => $markupFormat]); - } - - public function deleteBiography(string $biographyId): string - { - return $this->mutation('deleteBiography', ['biographyId' => $biographyId], 'biographyId'); - } - - public function createBookReview(BookReview $bookReview, ?string $markupFormat = null): string - { - return $this->mutation('createBookReview', $bookReview->getAllData(), 'bookReviewId', ['markupFormat' => $markupFormat]); - } - - public function updateBookReview(BookReview $bookReview, ?string $markupFormat = null): string - { - return $this->mutation('updateBookReview', $bookReview->getAllData(), 'bookReviewId', ['markupFormat' => $markupFormat]); - } - - public function deleteBookReview(string $bookReviewId): string - { - return $this->mutation('deleteBookReview', ['bookReviewId' => $bookReviewId], 'bookReviewId'); - } - - public function createContact(Contact $contact): string - { - return $this->mutation('createContact', $contact->getAllData(), 'contactId'); - } - - public function updateContact(Contact $contact): string - { - return $this->mutation('updateContact', $contact->getAllData(), 'contactId'); - } - - public function deleteContact(string $contactId): string - { - return $this->mutation('deleteContact', ['contactId' => $contactId], 'contactId'); - } - - public function createContribution(Contribution $contribution): string - { - return $this->mutation('createContribution', $contribution->getAllData(), 'contributionId'); - } - - public function updateContribution(Contribution $contribution): string - { - return $this->mutation('updateContribution', $contribution->getAllData(), 'contributionId'); - } - - public function deleteContribution(string $contributionId): string - { - return $this->mutation('deleteContribution', ['contributionId' => $contributionId], 'contributionId'); - } - - public function createContributor(Contributor $contributor): string - { - return $this->mutation('createContributor', $contributor->getAllData(), 'contributorId'); - } - - public function updateContributor(Contributor $contributor): string - { - return $this->mutation('updateContributor', $contributor->getAllData(), 'contributorId'); - } - - public function deleteContributor(string $contributorId): string - { - return $this->mutation('deleteContributor', ['contributorId' => $contributorId], 'contributorId'); - } - - public function createEndorsement(Endorsement $endorsement, ?string $markupFormat = null): string - { - return $this->mutation( - 'createEndorsement', - $endorsement->getAllData(), - 'endorsementId', - ['markupFormat' => $markupFormat] - ); - } - - public function updateEndorsement(Endorsement $endorsement, ?string $markupFormat = null): string - { - return $this->mutation( - 'updateEndorsement', - $endorsement->getAllData(), - 'endorsementId', - ['markupFormat' => $markupFormat] - ); - } - - public function deleteEndorsement(string $endorsementId): string - { - return $this->mutation('deleteEndorsement', ['endorsementId' => $endorsementId], 'endorsementId'); - } - - public function createFunding(Funding $funding): string - { - return $this->mutation('createFunding', $funding->getAllData(), 'fundingId'); - } - - public function updateFunding(Funding $funding): string - { - return $this->mutation('updateFunding', $funding->getAllData(), 'fundingId'); - } - - public function deleteFunding(string $fundingId): string - { - return $this->mutation('deleteFunding', ['fundingId' => $fundingId], 'fundingId'); - } - - public function createImprint(Imprint $imprint): string - { - return $this->mutation('createImprint', $imprint->getAllData(), 'imprintId'); - } - - public function updateImprint(Imprint $imprint): string - { - return $this->mutation('updateImprint', $imprint->getAllData(), 'imprintId'); - } - - public function deleteImprint(string $imprintId): string - { - return $this->mutation('deleteImprint', ['imprintId' => $imprintId], 'imprintId'); - } - - public function createInstitution(Institution $institution): string - { - return $this->mutation('createInstitution', $institution->getAllData(), 'institutionId'); - } - - public function updateInstitution(Institution $institution): string - { - return $this->mutation('updateInstitution', $institution->getAllData(), 'institutionId'); - } - - public function deleteInstitution(string $institutionId): string - { - return $this->mutation('deleteInstitution', ['institutionId' => $institutionId], 'institutionId'); - } - - public function createIssue(Issue $issue): string - { - return $this->mutation('createIssue', $issue->getAllData(), 'issueId'); - } - - public function updateIssue(Issue $issue): string - { - return $this->mutation('updateIssue', $issue->getAllData(), 'issueId'); - } - - public function deleteIssue(string $issueId): string - { - return $this->mutation('deleteIssue', ['issueId' => $issueId], 'issueId'); - } - - public function createLanguage(Language $language): string - { - return $this->mutation('createLanguage', $language->getAllData(), 'languageId'); - } - - public function updateLanguage(Language $language): string - { - return $this->mutation('updateLanguage', $language->getAllData(), 'languageId'); - } - - public function deleteLanguage(string $languageId): string - { - return $this->mutation('deleteLanguage', ['languageId' => $languageId], 'languageId'); - } - - public function createLocation(Location $location): string - { - return $this->mutation('createLocation', $location->getAllData(), 'locationId'); - } - - public function updateLocation(Location $location): string - { - return $this->mutation('updateLocation', $location->getAllData(), 'locationId'); - } - - public function deleteLocation(string $locationId): string - { - return $this->mutation('deleteLocation', ['locationId' => $locationId], 'locationId'); - } - - public function createPrice(Price $price): string - { - return $this->mutation('createPrice', $price->getAllData(), 'priceId'); - } - - public function updatePrice(Price $price): string - { - return $this->mutation('updatePrice', $price->getAllData(), 'priceId'); - } - - public function deletePrice(string $priceId): string - { - return $this->mutation('deletePrice', ['priceId' => $priceId], 'priceId'); - } - - public function createPublication(Publication $publication): string - { - return $this->mutation('createPublication', $publication->getAllData(), 'publicationId'); - } - - public function updatePublication(Publication $publication): string - { - return $this->mutation('updatePublication', $publication->getAllData(), 'publicationId'); - } - - public function deletePublication(string $publicationId): string - { - return $this->mutation('deletePublication', ['publicationId' => $publicationId], 'publicationId'); - } - - public function createPublisher(Publisher $publisher): string - { - return $this->mutation('createPublisher', $publisher->getAllData(), 'publisherId'); - } - - public function updatePublisher(Publisher $publisher): string - { - return $this->mutation('updatePublisher', $publisher->getAllData(), 'publisherId'); - } - - public function deletePublisher(string $publisherId): string - { - return $this->mutation('deletePublisher', ['publisherId' => $publisherId], 'publisherId'); - } - - public function createReference(Reference $reference): string - { - return $this->mutation('createReference', $reference->getAllData(), 'referenceId'); - } - - public function updateReference(Reference $reference): string - { - return $this->mutation('updateReference', $reference->getAllData(), 'referenceId'); - } - - public function deleteReference(string $referenceId): string - { - return $this->mutation('deleteReference', ['referenceId' => $referenceId], 'referenceId'); - } - - public function createSeries(Series $series): string - { - return $this->mutation('createSeries', $series->getAllData(), 'seriesId'); - } - - public function updateSeries(Series $series): string - { - return $this->mutation('updateSeries', $series->getAllData(), 'seriesId'); - } - - public function deleteSeries(string $seriesId): string - { - return $this->mutation('deleteSeries', ['seriesId' => $seriesId], 'seriesId'); - } - - public function createSubject(Subject $subject): string - { - return $this->mutation('createSubject', $subject->getAllData(), 'subjectId'); - } - - public function updateSubject(Subject $subject): string - { - return $this->mutation('updateSubject', $subject->getAllData(), 'subjectId'); - } - - public function deleteSubject(string $subjectId): string - { - return $this->mutation('deleteSubject', ['subjectId' => $subjectId], 'subjectId'); - } - - public function createTitle(Title $title, ?string $markupFormat = null): string - { - return $this->mutation('createTitle', $title->getAllData(), 'titleId', ['markupFormat' => $markupFormat]); - } - - public function updateTitle(Title $title, ?string $markupFormat = null): string - { - return $this->mutation('updateTitle', $title->getAllData(), 'titleId', ['markupFormat' => $markupFormat]); - } - - public function deleteTitle(string $titleId): string - { - return $this->mutation('deleteTitle', ['titleId' => $titleId], 'titleId'); - } - - public function createWork(Work $work): string - { - return $this->mutation('createWork', $work->getAllData(), 'workId'); - } - - public function updateWork(Work $work): string - { - return $this->mutation('updateWork', $work->getAllData(), 'workId'); - } - - public function deleteWork(string $workId): string - { - return $this->mutation('deleteWork', ['workId' => $workId], 'workId'); - } - - public function createWorkFeaturedVideo(WorkFeaturedVideo $workFeaturedVideo): string - { - return $this->mutation('createWorkFeaturedVideo', $workFeaturedVideo->getAllData(), 'workFeaturedVideoId'); - } - - public function updateWorkFeaturedVideo(WorkFeaturedVideo $workFeaturedVideo): string - { - return $this->mutation('updateWorkFeaturedVideo', $workFeaturedVideo->getAllData(), 'workFeaturedVideoId'); - } - - public function deleteWorkFeaturedVideo(string $workFeaturedVideoId): string - { - return $this->mutation('deleteWorkFeaturedVideo', ['workFeaturedVideoId' => $workFeaturedVideoId], 'workFeaturedVideoId'); - } - - public function createWorkRelation(WorkRelation $workRelation): string - { - return $this->mutation('createWorkRelation', $workRelation->getAllData(), 'workRelationId'); - } - - public function updateWorkRelation(WorkRelation $workRelation): string - { - return $this->mutation('updateWorkRelation', $workRelation->getAllData(), 'workRelationId'); - } - - public function deleteWorkRelation(string $workRelationId): string - { - return $this->mutation('deleteWorkRelation', ['workRelationId' => $workRelationId], 'workRelationId'); - } - - public function moveAffiliation(string $affiliationId, int $newOrdinal): string - { - return $this->mutation('moveAffiliation', compact('affiliationId', 'newOrdinal'), 'affiliationId'); - } - - public function moveContribution(string $contributionId, int $newOrdinal): string - { - return $this->mutation('moveContribution', compact('contributionId', 'newOrdinal'), 'contributionId'); - } - - public function moveIssue(string $issueId, int $newOrdinal): string - { - return $this->mutation('moveIssue', compact('issueId', 'newOrdinal'), 'issueId'); - } - - public function moveReference(string $referenceId, int $newOrdinal): string - { - return $this->mutation('moveReference', compact('referenceId', 'newOrdinal'), 'referenceId'); - } - - public function moveAdditionalResource(string $additionalResourceId, int $newOrdinal): string - { - return $this->mutation('moveAdditionalResource', compact('additionalResourceId', 'newOrdinal'), 'workResourceId'); - } - - public function moveAward(string $awardId, int $newOrdinal): string - { - return $this->mutation('moveAward', compact('awardId', 'newOrdinal'), 'awardId'); - } - - public function moveEndorsement(string $endorsementId, int $newOrdinal): string - { - return $this->mutation('moveEndorsement', compact('endorsementId', 'newOrdinal'), 'endorsementId'); - } - - public function moveBookReview(string $bookReviewId, int $newOrdinal): string - { - return $this->mutation('moveBookReview', compact('bookReviewId', 'newOrdinal'), 'bookReviewId'); - } - - public function moveSubject(string $subjectId, int $newOrdinal): string - { - return $this->mutation('moveSubject', compact('subjectId', 'newOrdinal'), 'subjectId'); - } - - public function moveWorkRelation(string $workRelationId, int $newOrdinal): string - { - return $this->mutation('moveWorkRelation', compact('workRelationId', 'newOrdinal'), 'workRelationId'); - } - - public function initPublicationFileUpload(array $data): FileUploadResponse - { - return new FileUploadResponse($this->runMutation('initPublicationFileUpload', $data)); - } - - public function initFrontcoverFileUpload(array $data): FileUploadResponse - { - return new FileUploadResponse($this->runMutation('initFrontcoverFileUpload', $data)); - } - - public function initAdditionalResourceFileUpload(array $data): FileUploadResponse - { - return new FileUploadResponse($this->runMutation('initAdditionalResourceFileUpload', $data)); - } - - public function initWorkFeaturedVideoFileUpload(array $data): FileUploadResponse - { - return new FileUploadResponse($this->runMutation('initWorkFeaturedVideoFileUpload', $data)); - } - - public function completeFileUpload(array $data): File - { - return new File($this->runMutation('completeFileUpload', $data)); - } - public function rawQuery(string $rawQuery, array $args = []): array { $response = $this->request->runQuery($rawQuery, $args); diff --git a/src/GraphQL/Concerns/HasMutationOperations.php b/src/GraphQL/Concerns/HasMutationOperations.php new file mode 100644 index 0000000..47a377d --- /dev/null +++ b/src/GraphQL/Concerns/HasMutationOperations.php @@ -0,0 +1,524 @@ +mutation( + 'createAdditionalResource', + $additionalResource->getAllData(), + 'workResourceId', + ['markupFormat' => $markupFormat] + ); + } + + public function updateAdditionalResource(AdditionalResource $additionalResource, ?string $markupFormat = null): string + { + return $this->mutation( + 'updateAdditionalResource', + $additionalResource->getAllData(), + 'workResourceId', + ['markupFormat' => $markupFormat] + ); + } + + public function deleteAdditionalResource(string $additionalResourceId): string + { + return $this->mutation( + 'deleteAdditionalResource', + ['additionalResourceId' => $additionalResourceId], + 'workResourceId' + ); + } + + public function createAffiliation(Affiliation $affiliation): string + { + return $this->mutation('createAffiliation', $affiliation->getAllData(), 'affiliationId'); + } + + public function updateAffiliation(Affiliation $affiliation): string + { + return $this->mutation('updateAffiliation', $affiliation->getAllData(), 'affiliationId'); + } + + public function deleteAffiliation(string $affiliationId): string + { + return $this->mutation('deleteAffiliation', ['affiliationId' => $affiliationId], 'affiliationId'); + } + + public function createAbstract(AbstractText $abstract, ?string $markupFormat = null): string + { + return $this->mutation('createAbstract', $abstract->getAllData(), 'abstractId', ['markupFormat' => $markupFormat]); + } + + public function updateAbstract(AbstractText $abstract, ?string $markupFormat = null): string + { + return $this->mutation('updateAbstract', $abstract->getAllData(), 'abstractId', ['markupFormat' => $markupFormat]); + } + + public function deleteAbstract(string $abstractId): string + { + return $this->mutation('deleteAbstract', ['abstractId' => $abstractId], 'abstractId'); + } + + public function createAward(Award $award, ?string $markupFormat = null): string + { + return $this->mutation('createAward', $award->getAllData(), 'awardId', ['markupFormat' => $markupFormat]); + } + + public function updateAward(Award $award, ?string $markupFormat = null): string + { + return $this->mutation('updateAward', $award->getAllData(), 'awardId', ['markupFormat' => $markupFormat]); + } + + public function deleteAward(string $awardId): string + { + return $this->mutation('deleteAward', ['awardId' => $awardId], 'awardId'); + } + + public function createBiography(Biography $biography, ?string $markupFormat = null): string + { + return $this->mutation('createBiography', $biography->getAllData(), 'biographyId', ['markupFormat' => $markupFormat]); + } + + public function updateBiography(Biography $biography, ?string $markupFormat = null): string + { + return $this->mutation('updateBiography', $biography->getAllData(), 'biographyId', ['markupFormat' => $markupFormat]); + } + + public function deleteBiography(string $biographyId): string + { + return $this->mutation('deleteBiography', ['biographyId' => $biographyId], 'biographyId'); + } + + public function createBookReview(BookReview $bookReview, ?string $markupFormat = null): string + { + return $this->mutation('createBookReview', $bookReview->getAllData(), 'bookReviewId', ['markupFormat' => $markupFormat]); + } + + public function updateBookReview(BookReview $bookReview, ?string $markupFormat = null): string + { + return $this->mutation('updateBookReview', $bookReview->getAllData(), 'bookReviewId', ['markupFormat' => $markupFormat]); + } + + public function deleteBookReview(string $bookReviewId): string + { + return $this->mutation('deleteBookReview', ['bookReviewId' => $bookReviewId], 'bookReviewId'); + } + + public function createContact(Contact $contact): string + { + return $this->mutation('createContact', $contact->getAllData(), 'contactId'); + } + + public function updateContact(Contact $contact): string + { + return $this->mutation('updateContact', $contact->getAllData(), 'contactId'); + } + + public function deleteContact(string $contactId): string + { + return $this->mutation('deleteContact', ['contactId' => $contactId], 'contactId'); + } + + public function createContribution(Contribution $contribution): string + { + return $this->mutation('createContribution', $contribution->getAllData(), 'contributionId'); + } + + public function updateContribution(Contribution $contribution): string + { + return $this->mutation('updateContribution', $contribution->getAllData(), 'contributionId'); + } + + public function deleteContribution(string $contributionId): string + { + return $this->mutation('deleteContribution', ['contributionId' => $contributionId], 'contributionId'); + } + + public function createContributor(Contributor $contributor): string + { + return $this->mutation('createContributor', $contributor->getAllData(), 'contributorId'); + } + + public function updateContributor(Contributor $contributor): string + { + return $this->mutation('updateContributor', $contributor->getAllData(), 'contributorId'); + } + + public function deleteContributor(string $contributorId): string + { + return $this->mutation('deleteContributor', ['contributorId' => $contributorId], 'contributorId'); + } + + public function createEndorsement(Endorsement $endorsement, ?string $markupFormat = null): string + { + return $this->mutation( + 'createEndorsement', + $endorsement->getAllData(), + 'endorsementId', + ['markupFormat' => $markupFormat] + ); + } + + public function updateEndorsement(Endorsement $endorsement, ?string $markupFormat = null): string + { + return $this->mutation( + 'updateEndorsement', + $endorsement->getAllData(), + 'endorsementId', + ['markupFormat' => $markupFormat] + ); + } + + public function deleteEndorsement(string $endorsementId): string + { + return $this->mutation('deleteEndorsement', ['endorsementId' => $endorsementId], 'endorsementId'); + } + + public function createFunding(Funding $funding): string + { + return $this->mutation('createFunding', $funding->getAllData(), 'fundingId'); + } + + public function updateFunding(Funding $funding): string + { + return $this->mutation('updateFunding', $funding->getAllData(), 'fundingId'); + } + + public function deleteFunding(string $fundingId): string + { + return $this->mutation('deleteFunding', ['fundingId' => $fundingId], 'fundingId'); + } + + public function createImprint(Imprint $imprint): string + { + return $this->mutation('createImprint', $imprint->getAllData(), 'imprintId'); + } + + public function updateImprint(Imprint $imprint): string + { + return $this->mutation('updateImprint', $imprint->getAllData(), 'imprintId'); + } + + public function deleteImprint(string $imprintId): string + { + return $this->mutation('deleteImprint', ['imprintId' => $imprintId], 'imprintId'); + } + + public function createInstitution(Institution $institution): string + { + return $this->mutation('createInstitution', $institution->getAllData(), 'institutionId'); + } + + public function updateInstitution(Institution $institution): string + { + return $this->mutation('updateInstitution', $institution->getAllData(), 'institutionId'); + } + + public function deleteInstitution(string $institutionId): string + { + return $this->mutation('deleteInstitution', ['institutionId' => $institutionId], 'institutionId'); + } + + public function createIssue(Issue $issue): string + { + return $this->mutation('createIssue', $issue->getAllData(), 'issueId'); + } + + public function updateIssue(Issue $issue): string + { + return $this->mutation('updateIssue', $issue->getAllData(), 'issueId'); + } + + public function deleteIssue(string $issueId): string + { + return $this->mutation('deleteIssue', ['issueId' => $issueId], 'issueId'); + } + + public function createLanguage(Language $language): string + { + return $this->mutation('createLanguage', $language->getAllData(), 'languageId'); + } + + public function updateLanguage(Language $language): string + { + return $this->mutation('updateLanguage', $language->getAllData(), 'languageId'); + } + + public function deleteLanguage(string $languageId): string + { + return $this->mutation('deleteLanguage', ['languageId' => $languageId], 'languageId'); + } + + public function createLocation(Location $location): string + { + return $this->mutation('createLocation', $location->getAllData(), 'locationId'); + } + + public function updateLocation(Location $location): string + { + return $this->mutation('updateLocation', $location->getAllData(), 'locationId'); + } + + public function deleteLocation(string $locationId): string + { + return $this->mutation('deleteLocation', ['locationId' => $locationId], 'locationId'); + } + + public function createPrice(Price $price): string + { + return $this->mutation('createPrice', $price->getAllData(), 'priceId'); + } + + public function updatePrice(Price $price): string + { + return $this->mutation('updatePrice', $price->getAllData(), 'priceId'); + } + + public function deletePrice(string $priceId): string + { + return $this->mutation('deletePrice', ['priceId' => $priceId], 'priceId'); + } + + public function createPublication(Publication $publication): string + { + return $this->mutation('createPublication', $publication->getAllData(), 'publicationId'); + } + + public function updatePublication(Publication $publication): string + { + return $this->mutation('updatePublication', $publication->getAllData(), 'publicationId'); + } + + public function deletePublication(string $publicationId): string + { + return $this->mutation('deletePublication', ['publicationId' => $publicationId], 'publicationId'); + } + + public function createPublisher(Publisher $publisher): string + { + return $this->mutation('createPublisher', $publisher->getAllData(), 'publisherId'); + } + + public function updatePublisher(Publisher $publisher): string + { + return $this->mutation('updatePublisher', $publisher->getAllData(), 'publisherId'); + } + + public function deletePublisher(string $publisherId): string + { + return $this->mutation('deletePublisher', ['publisherId' => $publisherId], 'publisherId'); + } + + public function createReference(Reference $reference): string + { + return $this->mutation('createReference', $reference->getAllData(), 'referenceId'); + } + + public function updateReference(Reference $reference): string + { + return $this->mutation('updateReference', $reference->getAllData(), 'referenceId'); + } + + public function deleteReference(string $referenceId): string + { + return $this->mutation('deleteReference', ['referenceId' => $referenceId], 'referenceId'); + } + + public function createSeries(Series $series): string + { + return $this->mutation('createSeries', $series->getAllData(), 'seriesId'); + } + + public function updateSeries(Series $series): string + { + return $this->mutation('updateSeries', $series->getAllData(), 'seriesId'); + } + + public function deleteSeries(string $seriesId): string + { + return $this->mutation('deleteSeries', ['seriesId' => $seriesId], 'seriesId'); + } + + public function createSubject(Subject $subject): string + { + return $this->mutation('createSubject', $subject->getAllData(), 'subjectId'); + } + + public function updateSubject(Subject $subject): string + { + return $this->mutation('updateSubject', $subject->getAllData(), 'subjectId'); + } + + public function deleteSubject(string $subjectId): string + { + return $this->mutation('deleteSubject', ['subjectId' => $subjectId], 'subjectId'); + } + + public function createTitle(Title $title, ?string $markupFormat = null): string + { + return $this->mutation('createTitle', $title->getAllData(), 'titleId', ['markupFormat' => $markupFormat]); + } + + public function updateTitle(Title $title, ?string $markupFormat = null): string + { + return $this->mutation('updateTitle', $title->getAllData(), 'titleId', ['markupFormat' => $markupFormat]); + } + + public function deleteTitle(string $titleId): string + { + return $this->mutation('deleteTitle', ['titleId' => $titleId], 'titleId'); + } + + public function createWork(Work $work): string + { + return $this->mutation('createWork', $work->getAllData(), 'workId'); + } + + public function updateWork(Work $work): string + { + return $this->mutation('updateWork', $work->getAllData(), 'workId'); + } + + public function deleteWork(string $workId): string + { + return $this->mutation('deleteWork', ['workId' => $workId], 'workId'); + } + + public function createWorkFeaturedVideo(WorkFeaturedVideo $workFeaturedVideo): string + { + return $this->mutation('createWorkFeaturedVideo', $workFeaturedVideo->getAllData(), 'workFeaturedVideoId'); + } + + public function updateWorkFeaturedVideo(WorkFeaturedVideo $workFeaturedVideo): string + { + return $this->mutation('updateWorkFeaturedVideo', $workFeaturedVideo->getAllData(), 'workFeaturedVideoId'); + } + + public function deleteWorkFeaturedVideo(string $workFeaturedVideoId): string + { + return $this->mutation('deleteWorkFeaturedVideo', ['workFeaturedVideoId' => $workFeaturedVideoId], 'workFeaturedVideoId'); + } + + public function createWorkRelation(WorkRelation $workRelation): string + { + return $this->mutation('createWorkRelation', $workRelation->getAllData(), 'workRelationId'); + } + + public function updateWorkRelation(WorkRelation $workRelation): string + { + return $this->mutation('updateWorkRelation', $workRelation->getAllData(), 'workRelationId'); + } + + public function deleteWorkRelation(string $workRelationId): string + { + return $this->mutation('deleteWorkRelation', ['workRelationId' => $workRelationId], 'workRelationId'); + } + + public function moveAffiliation(string $affiliationId, int $newOrdinal): string + { + return $this->mutation('moveAffiliation', compact('affiliationId', 'newOrdinal'), 'affiliationId'); + } + + public function moveContribution(string $contributionId, int $newOrdinal): string + { + return $this->mutation('moveContribution', compact('contributionId', 'newOrdinal'), 'contributionId'); + } + + public function moveIssue(string $issueId, int $newOrdinal): string + { + return $this->mutation('moveIssue', compact('issueId', 'newOrdinal'), 'issueId'); + } + + public function moveReference(string $referenceId, int $newOrdinal): string + { + return $this->mutation('moveReference', compact('referenceId', 'newOrdinal'), 'referenceId'); + } + + public function moveAdditionalResource(string $additionalResourceId, int $newOrdinal): string + { + return $this->mutation('moveAdditionalResource', compact('additionalResourceId', 'newOrdinal'), 'workResourceId'); + } + + public function moveAward(string $awardId, int $newOrdinal): string + { + return $this->mutation('moveAward', compact('awardId', 'newOrdinal'), 'awardId'); + } + + public function moveEndorsement(string $endorsementId, int $newOrdinal): string + { + return $this->mutation('moveEndorsement', compact('endorsementId', 'newOrdinal'), 'endorsementId'); + } + + public function moveBookReview(string $bookReviewId, int $newOrdinal): string + { + return $this->mutation('moveBookReview', compact('bookReviewId', 'newOrdinal'), 'bookReviewId'); + } + + public function moveSubject(string $subjectId, int $newOrdinal): string + { + return $this->mutation('moveSubject', compact('subjectId', 'newOrdinal'), 'subjectId'); + } + + public function moveWorkRelation(string $workRelationId, int $newOrdinal): string + { + return $this->mutation('moveWorkRelation', compact('workRelationId', 'newOrdinal'), 'workRelationId'); + } + + public function initPublicationFileUpload(array $data): FileUploadResponse + { + return new FileUploadResponse($this->runMutation('initPublicationFileUpload', $data)); + } + + public function initFrontcoverFileUpload(array $data): FileUploadResponse + { + return new FileUploadResponse($this->runMutation('initFrontcoverFileUpload', $data)); + } + + public function initAdditionalResourceFileUpload(array $data): FileUploadResponse + { + return new FileUploadResponse($this->runMutation('initAdditionalResourceFileUpload', $data)); + } + + public function initWorkFeaturedVideoFileUpload(array $data): FileUploadResponse + { + return new FileUploadResponse($this->runMutation('initWorkFeaturedVideoFileUpload', $data)); + } + + public function completeFileUpload(array $data): File + { + return new File($this->runMutation('completeFileUpload', $data)); + } +} diff --git a/src/GraphQL/Concerns/HasQueryOperations.php b/src/GraphQL/Concerns/HasQueryOperations.php new file mode 100644 index 0000000..8c69b59 --- /dev/null +++ b/src/GraphQL/Concerns/HasQueryOperations.php @@ -0,0 +1,440 @@ +get('additionalResource', $additionalResourceId); + } + + public function additionalResources(array $args = []): array + { + return $this->getMany('additionalResource', $args); + } + + public function additionalResourceCount(): int + { + return $this->count('additionalResource'); + } + + public function affiliation(string $affiliationId): Affiliation + { + return $this->get('affiliation', $affiliationId); + } + + public function affiliations(array $args = []): array + { + return $this->getMany('affiliation', $args); + } + + public function affiliationCount(): int + { + return $this->count('affiliation'); + } + + public function abstract(string $abstractId, ?string $markupFormat = null): AbstractText + { + return $this->get('abstract', $abstractId, ['markupFormat' => $markupFormat]); + } + + public function abstracts(array $args = []): array + { + return $this->getMany('abstract', $args); + } + + public function award(string $awardId): Award + { + return $this->get('award', $awardId); + } + + public function awards(array $args = []): array + { + return $this->getMany('award', $args); + } + + public function awardCount(): int + { + return $this->count('award'); + } + + public function biography(string $biographyId, ?string $markupFormat = null): Biography + { + return $this->get('biography', $biographyId, ['markupFormat' => $markupFormat]); + } + + public function biographies(array $args = []): array + { + return $this->getMany('biography', $args); + } + + public function books(array $args = []): array + { + return $this->getMany('book', $args); + } + + public function bookByDoi(string $doi): Work + { + return $this->getByDoi('book', $doi); + } + + public function bookCount(array $args = []): int + { + return $this->count('book', $args); + } + + public function bookReview(string $bookReviewId): BookReview + { + return $this->get('bookReview', $bookReviewId); + } + + public function bookReviews(array $args = []): array + { + return $this->getMany('bookReview', $args); + } + + public function bookReviewCount(): int + { + return $this->count('bookReview'); + } + + public function chapters(array $args = []): array + { + return $this->getMany('chapter', $args); + } + + public function chapterByDoi(string $doi): Work + { + return $this->getByDoi('chapter', $doi); + } + + public function chapterCount(array $args = []): int + { + return $this->count('chapter', $args); + } + + public function contact(string $contactId): Contact + { + return $this->get('contact', $contactId); + } + + public function contacts(array $args = []): array + { + return $this->getMany('contact', $args); + } + + public function contactCount(array $args = []): int + { + return $this->count('contact', $args); + } + + public function contribution(string $contributionId): Contribution + { + return $this->get('contribution', $contributionId); + } + + public function contributions(array $args = []): array + { + return $this->getMany('contribution', $args); + } + + public function contributionCount(array $args = []): int + { + return $this->count('contribution', $args); + } + + public function contributor(string $contributorId): Contributor + { + return $this->get('contributor', $contributorId); + } + + public function contributors(array $args = []): array + { + return $this->getMany('contributor', $args); + } + + public function contributorCount(array $args = []): int + { + return $this->count('contributor', $args); + } + + public function endorsement(string $endorsementId): Endorsement + { + return $this->get('endorsement', $endorsementId); + } + + public function endorsements(array $args = []): array + { + return $this->getMany('endorsement', $args); + } + + public function endorsementCount(): int + { + return $this->count('endorsement'); + } + + public function file(string $fileId): File + { + return $this->get('file', $fileId); + } + + public function funding(string $fundingId): Funding + { + return $this->get('funding', $fundingId); + } + + public function fundings(array $args = []): array + { + return $this->getMany('funding', $args); + } + + public function fundingCount(): int + { + return $this->count('funding'); + } + + public function imprint(string $imprintId): Imprint + { + return $this->get('imprint', $imprintId); + } + + public function imprints(array $args = []): array + { + return $this->getMany('imprint', $args); + } + + public function imprintCount(array $args = []): int + { + return $this->count('imprint', $args); + } + + public function institution(string $institutionId): Institution + { + return $this->get('institution', $institutionId); + } + + public function institutions(array $args = []): array + { + return $this->getMany('institution', $args); + } + + public function institutionCount(array $args = []): int + { + return $this->count('institution', $args); + } + + public function issue(string $issueId): Issue + { + return $this->get('issue', $issueId); + } + + public function issues(array $args = []): array + { + return $this->getMany('issue', $args); + } + + public function issueCount(): int + { + return $this->count('issue'); + } + + public function language(string $languageId): Language + { + return $this->get('language', $languageId); + } + + public function languages(array $args = []): array + { + return $this->getMany('language', $args); + } + + public function languageCount(array $args = []): int + { + return $this->count('language', $args); + } + + public function location(string $locationId): Location + { + return $this->get('location', $locationId); + } + + public function locations(array $args = []): array + { + return $this->getMany('location', $args); + } + + public function locationCount(array $args = []): int + { + return $this->count('location', $args); + } + + public function me(): Me + { + $result = $this->query('me', [], $this->token); + return new Me($result['me']); + } + + public function price(string $priceId): Price + { + return $this->get('price', $priceId); + } + + public function prices(array $args = []): array + { + return $this->getMany('price', $args); + } + + public function priceCount(array $args = []): int + { + return $this->count('price', $args); + } + + public function publication(string $publicationId): Publication + { + return $this->get('publication', $publicationId); + } + + public function publications(array $args = []): array + { + return $this->getMany('publication', $args); + } + + public function publicationCount(array $args = []): int + { + return $this->count('publication', $args); + } + + public function publisher(string $publisherId): Publisher + { + return $this->get('publisher', $publisherId); + } + + public function publishers(array $args = []): array + { + return $this->getMany('publisher', $args); + } + + public function publisherCount(array $args = []): int + { + return $this->count('publisher', $args); + } + + public function reference(string $referenceId): Reference + { + return $this->get('reference', $referenceId); + } + + public function references(array $args = []): array + { + return $this->getMany('reference', $args); + } + + public function referenceCount(): int + { + return $this->count('reference'); + } + + public function series(string $seriesId): Series + { + return $this->get('series', $seriesId); + } + + public function serieses(array $args = []): array + { + return $this->getMany('series', $args); + } + + public function seriesCount(array $args = []): int + { + return $this->count('series', $args); + } + + public function subject(string $subjectId): Subject + { + return $this->get('subject', $subjectId); + } + + public function subjects(array $args = []): array + { + return $this->getMany('subject', $args); + } + + public function subjectCount(array $args = []): int + { + return $this->count('subject', $args); + } + + public function title(string $titleId, ?string $markupFormat = null): Title + { + return $this->get('title', $titleId, ['markupFormat' => $markupFormat]); + } + + public function titles(array $args = []): array + { + return $this->getMany('title', $args); + } + + public function work(string $workId): Work + { + return $this->get('work', $workId); + } + + public function works(array $args = []): array + { + return $this->getMany('work', $args); + } + + public function workByDoi(string $doi): Work + { + return $this->getByDoi('work', $doi); + } + + public function workCount(array $args = []): int + { + return $this->count('work', $args); + } + + public function workFeaturedVideo(string $workFeaturedVideoId): WorkFeaturedVideo + { + return $this->get('workFeaturedVideo', $workFeaturedVideoId); + } + + public function workFeaturedVideos(array $args = []): array + { + return $this->getMany('workFeaturedVideo', $args); + } + + public function workFeaturedVideoCount(): int + { + return $this->count('workFeaturedVideo'); + } +} diff --git a/tests/GraphQL/ClientTest.php b/tests/GraphQL/ClientTest.php index d082f07..bff9975 100644 --- a/tests/GraphQL/ClientTest.php +++ b/tests/GraphQL/ClientTest.php @@ -7,26 +7,14 @@ use GuzzleHttp\Psr7\Response; use PHPUnit\Framework\TestCase; use ThothApi\GraphQL\Client; -use ThothApi\GraphQL\Models\Affiliation; -use ThothApi\GraphQL\Models\Contribution; -use ThothApi\GraphQL\Models\Contributor; -use ThothApi\GraphQL\Models\Funding; -use ThothApi\GraphQL\Models\Imprint; -use ThothApi\GraphQL\Models\Institution; -use ThothApi\GraphQL\Models\Issue; -use ThothApi\GraphQL\Models\Language; -use ThothApi\GraphQL\Models\Location; -use ThothApi\GraphQL\Models\Price; -use ThothApi\GraphQL\Models\Publication; -use ThothApi\GraphQL\Models\Publisher; -use ThothApi\GraphQL\Models\Reference; -use ThothApi\GraphQL\Models\Series; -use ThothApi\GraphQL\Models\Subject; -use ThothApi\GraphQL\Models\Work; -use ThothApi\GraphQL\Models\WorkRelation; +use ThothApi\Tests\GraphQL\Concerns\HasClientMutationTests; +use ThothApi\Tests\GraphQL\Concerns\HasClientQueryTests; final class ClientTest extends TestCase { + use HasClientMutationTests; + use HasClientQueryTests; + private MockHandler $mockHandler; private Client $client; @@ -38,1754 +26,6 @@ protected function setUp(): void $this->client = new Client(['handler' => $handler]); } - public function testAffiliation(): void - { - $affiliation = new Affiliation(['affiliationId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'affiliation' => [ - 'affiliationId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' - ] - ] - ]))); - - $result = $this->client->affiliation('9afc6760-f556-46a1-a912-39ea5ebc921b'); - $this->assertEquals($affiliation, $result); - } - - public function testAffiliations(): void - { - $affiliations = [ - new Affiliation(['affiliationId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), - new Affiliation(['affiliationId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), - ]; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'affiliations' => [ - [ - 'affiliationId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' - ], - [ - 'affiliationId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' - ] - ] - ] - ]))); - - $result = $this->client->affiliations(); - $this->assertEquals($affiliations, $result); - } - - public function testAffiliationCount(): void - { - $expectedCount = 710; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'affiliationCount' => 710 - ] - ]))); - - $result = $this->client->affiliationCount(); - $this->assertSame($expectedCount, $result); - } - - public function testContribution(): void - { - $contribution = new Contribution(['contributionId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'contribution' => [ - 'contributionId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' - ] - ] - ]))); - - $result = $this->client->contribution('9afc6760-f556-46a1-a912-39ea5ebc921b'); - $this->assertEquals($contribution, $result); - } - - public function testBooks(): void - { - $books = [ - new Work(['workId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), - new Work(['workId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), - ]; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'books' => [ - [ - 'workId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' - ], - [ - 'workId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' - ] - ] - ] - ]))); - - $result = $this->client->books(); - $this->assertEquals($books, $result); - } - - public function testBookByDoi(): void - { - $book = new Work([ - 'workId' => '9afc6760-f556-46a1-a912-39ea5ebc921b', - 'doi' => 'https://doi.org/10.00000/00000000' - ]); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'bookByDoi' => [ - 'workId' => '9afc6760-f556-46a1-a912-39ea5ebc921b', - 'doi' => 'https://doi.org/10.00000/00000000' - ] - ] - ]))); - - $result = $this->client->bookByDoi('https://doi.org/10.00000/00000000'); - $this->assertEquals($book, $result); - } - - public function testBookCount(): void - { - $expectedCount = 710; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'bookCount' => 710 - ] - ]))); - - $result = $this->client->bookCount(); - $this->assertSame($expectedCount, $result); - } - - public function testChapters(): void - { - $chapters = [ - new Work(['workId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), - new Work(['workId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), - ]; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'chapters' => [ - [ - 'workId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' - ], - [ - 'workId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' - ] - ] - ] - ]))); - - $result = $this->client->chapters(); - $this->assertEquals($chapters, $result); - } - - public function testChapterByDoi(): void - { - $chapter = new Work([ - 'workId' => '9afc6760-f556-46a1-a912-39ea5ebc921b', - 'doi' => 'https://doi.org/10.00000/00000000' - ]); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'chapterByDoi' => [ - 'workId' => '9afc6760-f556-46a1-a912-39ea5ebc921b', - 'doi' => 'https://doi.org/10.00000/00000000' - ] - ] - ]))); - - $result = $this->client->chapterByDoi('https://doi.org/10.00000/00000000'); - $this->assertEquals($chapter, $result); - } - - public function testChapterCount(): void - { - $expectedCount = 710; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'chapterCount' => 710 - ] - ]))); - - $result = $this->client->chapterCount(); - $this->assertSame($expectedCount, $result); - } - - public function testContributions(): void - { - $contributions = [ - new Contribution(['contributionId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), - new Contribution(['contributionId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), - ]; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'contributions' => [ - [ - 'contributionId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' - ], - [ - 'contributionId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' - ] - ] - ] - ]))); - - $result = $this->client->contributions(); - $this->assertEquals($contributions, $result); - } - - public function testContributionCount(): void - { - $expectedCount = 710; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'contributionCount' => 710 - ] - ]))); - - $result = $this->client->contributionCount(); - $this->assertSame($expectedCount, $result); - } - - public function testContributor(): void - { - $contributor = new Contributor(['contributorId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'contributor' => [ - 'contributorId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' - ] - ] - ]))); - - $result = $this->client->contributor('9afc6760-f556-46a1-a912-39ea5ebc921b'); - $this->assertEquals($contributor, $result); - } - - public function testContributors(): void - { - $contributors = [ - new Contributor(['contributorId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), - new Contributor(['contributorId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), - ]; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'contributors' => [ - [ - 'contributorId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' - ], - [ - 'contributorId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' - ] - ] - ] - ]))); - - $result = $this->client->contributors(); - $this->assertEquals($contributors, $result); - } - - public function testContributorCount(): void - { - $expectedCount = 710; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'contributorCount' => 710 - ] - ]))); - - $result = $this->client->contributorCount(); - $this->assertSame($expectedCount, $result); - } - - public function testFunding(): void - { - $funding = new Funding(['fundingId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'funding' => [ - 'fundingId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' - ] - ] - ]))); - - $result = $this->client->funding('9afc6760-f556-46a1-a912-39ea5ebc921b'); - $this->assertEquals($funding, $result); - } - - public function testFundings(): void - { - $fundings = [ - new Funding(['fundingId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), - new Funding(['fundingId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), - ]; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'fundings' => [ - [ - 'fundingId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' - ], - [ - 'fundingId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' - ] - ] - ] - ]))); - - $result = $this->client->fundings(); - $this->assertEquals($fundings, $result); - } - - public function testFundingCount(): void - { - $expectedCount = 710; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'fundingCount' => 710 - ] - ]))); - - $result = $this->client->fundingCount(); - $this->assertSame($expectedCount, $result); - } - - public function testImprint(): void - { - $imprint = new Imprint(['imprintId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'imprint' => [ - 'imprintId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' - ] - ] - ]))); - - $result = $this->client->imprint('9afc6760-f556-46a1-a912-39ea5ebc921b'); - $this->assertEquals($imprint, $result); - } - - public function testImprints(): void - { - $imprints = [ - new Imprint(['imprintId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), - new Imprint(['imprintId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), - ]; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'imprints' => [ - [ - 'imprintId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' - ], - [ - 'imprintId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' - ] - ] - ] - ]))); - - $result = $this->client->imprints(); - $this->assertEquals($imprints, $result); - } - - public function testImprintCount(): void - { - $expectedCount = 710; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'imprintCount' => 710 - ] - ]))); - - $result = $this->client->imprintCount(); - $this->assertSame($expectedCount, $result); - } - - public function testInstitution(): void - { - $institution = new Institution(['institutionId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'institution' => [ - 'institutionId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' - ] - ] - ]))); - - $result = $this->client->institution('9afc6760-f556-46a1-a912-39ea5ebc921b'); - $this->assertEquals($institution, $result); - } - - public function testInstitutions(): void - { - $institutions = [ - new Institution(['institutionId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), - new Institution(['institutionId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), - ]; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'institutions' => [ - [ - 'institutionId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' - ], - [ - 'institutionId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' - ] - ] - ] - ]))); - - $result = $this->client->institutions(); - $this->assertEquals($institutions, $result); - } - - public function testInstitutionCount(): void - { - $expectedCount = 710; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'institutionCount' => 710 - ] - ]))); - - $result = $this->client->institutionCount(); - $this->assertSame($expectedCount, $result); - } - - public function testIssue(): void - { - $issue = new Issue(['issueId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'issue' => [ - 'issueId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' - ] - ] - ]))); - - $result = $this->client->issue('9afc6760-f556-46a1-a912-39ea5ebc921b'); - $this->assertEquals($issue, $result); - } - - public function testIssues(): void - { - $issues = [ - new Issue(['issueId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), - new Issue(['issueId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), - ]; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'issues' => [ - [ - 'issueId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' - ], - [ - 'issueId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' - ] - ] - ] - ]))); - - $result = $this->client->issues(); - $this->assertEquals($issues, $result); - } - - public function testIssueCount(): void - { - $expectedCount = 710; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'issueCount' => 710 - ] - ]))); - - $result = $this->client->issueCount(); - $this->assertSame($expectedCount, $result); - } - - public function testLanguage(): void - { - $language = new Language(['languageId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'language' => [ - 'languageId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' - ] - ] - ]))); - - $result = $this->client->language('9afc6760-f556-46a1-a912-39ea5ebc921b'); - $this->assertEquals($language, $result); - } - - public function testLanguages(): void - { - $languages = [ - new Language(['languageId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), - new Language(['languageId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), - ]; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'languages' => [ - [ - 'languageId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' - ], - [ - 'languageId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' - ] - ] - ] - ]))); - - $result = $this->client->languages(); - $this->assertEquals($languages, $result); - } - - public function testLanguageCount(): void - { - $expectedCount = 710; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'languageCount' => 710 - ] - ]))); - - $result = $this->client->languageCount(); - $this->assertSame($expectedCount, $result); - } - - public function testLocation(): void - { - $location = new Location(['locationId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'location' => [ - 'locationId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' - ] - ] - ]))); - - $result = $this->client->location('9afc6760-f556-46a1-a912-39ea5ebc921b'); - $this->assertEquals($location, $result); - } - - public function testLocations(): void - { - $locations = [ - new Location(['locationId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), - new Location(['locationId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), - ]; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'locations' => [ - [ - 'locationId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' - ], - [ - 'locationId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' - ] - ] - ] - ]))); - - $result = $this->client->locations(); - $this->assertEquals($locations, $result); - } - - public function testLocationCount(): void - { - $expectedCount = 710; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'locationCount' => 710 - ] - ]))); - - $result = $this->client->locationCount(); - $this->assertSame($expectedCount, $result); - } - - public function testPrice(): void - { - $price = new Price(['priceId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'price' => [ - 'priceId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' - ] - ] - ]))); - - $result = $this->client->price('9afc6760-f556-46a1-a912-39ea5ebc921b'); - $this->assertEquals($price, $result); - } - - public function testPrices(): void - { - $prices = [ - new Price(['priceId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), - new Price(['priceId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), - ]; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'prices' => [ - [ - 'priceId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' - ], - [ - 'priceId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' - ] - ] - ] - ]))); - - $result = $this->client->prices(); - $this->assertEquals($prices, $result); - } - - public function testPriceCount(): void - { - $expectedCount = 710; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'priceCount' => 710 - ] - ]))); - - $result = $this->client->priceCount(); - $this->assertSame($expectedCount, $result); - } - - public function testPublication(): void - { - $publication = new Publication(['publicationId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'publication' => [ - 'publicationId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' - ] - ] - ]))); - - $result = $this->client->publication('9afc6760-f556-46a1-a912-39ea5ebc921b'); - $this->assertEquals($publication, $result); - } - - public function testPublications(): void - { - $publications = [ - new Publication(['publicationId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), - new Publication(['publicationId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), - ]; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'publications' => [ - [ - 'publicationId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' - ], - [ - 'publicationId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' - ] - ] - ] - ]))); - - $result = $this->client->publications(); - $this->assertEquals($publications, $result); - } - - public function testPublicationCount(): void - { - $expectedCount = 710; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'publicationCount' => 710 - ] - ]))); - - $result = $this->client->publicationCount(); - $this->assertSame($expectedCount, $result); - } - - public function testPublisher(): void - { - $publisher = new Publisher(['publisherId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'publisher' => [ - 'publisherId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' - ] - ] - ]))); - - $result = $this->client->publisher('9afc6760-f556-46a1-a912-39ea5ebc921b'); - $this->assertEquals($publisher, $result); - } - - public function testPublishers(): void - { - $publishers = [ - new Publisher(['publisherId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), - new Publisher(['publisherId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), - ]; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'publishers' => [ - [ - 'publisherId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' - ], - [ - 'publisherId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' - ] - ] - ] - ]))); - - $result = $this->client->publishers(); - $this->assertEquals($publishers, $result); - } - - public function testPublisherCount(): void - { - $expectedCount = 710; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'publisherCount' => 710 - ] - ]))); - - $result = $this->client->publisherCount(); - $this->assertSame($expectedCount, $result); - } - - public function testReference(): void - { - $reference = new Reference(['referenceId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'reference' => [ - 'referenceId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' - ] - ] - ]))); - - $result = $this->client->reference('9afc6760-f556-46a1-a912-39ea5ebc921b'); - $this->assertEquals($reference, $result); - } - - public function testReferences(): void - { - $references = [ - new Reference(['referenceId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), - new Reference(['referenceId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), - ]; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'references' => [ - [ - 'referenceId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' - ], - [ - 'referenceId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' - ] - ] - ] - ]))); - - $result = $this->client->references(); - $this->assertEquals($references, $result); - } - - public function testReferenceCount(): void - { - $expectedCount = 710; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'referenceCount' => 710 - ] - ]))); - - $result = $this->client->referenceCount(); - $this->assertSame($expectedCount, $result); - } - - public function testSeries(): void - { - $series = new Series(['seriesId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'series' => [ - 'seriesId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' - ] - ] - ]))); - - $result = $this->client->series('9afc6760-f556-46a1-a912-39ea5ebc921b'); - $this->assertEquals($series, $result); - } - - public function testSerieses(): void - { - $serieses = [ - new Series(['seriesId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), - new Series(['seriesId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), - ]; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'serieses' => [ - [ - 'seriesId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' - ], - [ - 'seriesId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' - ] - ] - ] - ]))); - - $result = $this->client->serieses(); - $this->assertEquals($serieses, $result); - } - - public function testSeriesCount(): void - { - $expectedCount = 710; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'seriesCount' => 710 - ] - ]))); - - $result = $this->client->seriesCount(); - $this->assertSame($expectedCount, $result); - } - - public function testSubject(): void - { - $subject = new Subject(['subjectId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'subject' => [ - 'subjectId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' - ] - ] - ]))); - - $result = $this->client->subject('9afc6760-f556-46a1-a912-39ea5ebc921b'); - $this->assertEquals($subject, $result); - } - - public function testSubjects(): void - { - $subjects = [ - new Subject(['subjectId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), - new Subject(['subjectId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), - ]; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'subjects' => [ - [ - 'subjectId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' - ], - [ - 'subjectId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' - ] - ] - ] - ]))); - - $result = $this->client->subjects(); - $this->assertEquals($subjects, $result); - } - - public function testSubjectCount(): void - { - $expectedCount = 710; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'subjectCount' => 710 - ] - ]))); - - $result = $this->client->subjectCount(); - $this->assertSame($expectedCount, $result); - } - - public function testWork(): void - { - $work = new Work(['workId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'work' => [ - 'workId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' - ] - ] - ]))); - - $result = $this->client->work('9afc6760-f556-46a1-a912-39ea5ebc921b'); - $this->assertEquals($work, $result); - } - - public function testWorks(): void - { - $works = [ - new Work(['workId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), - new Work(['workId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), - ]; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'works' => [ - [ - 'workId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' - ], - [ - 'workId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' - ] - ] - ] - ]))); - - $result = $this->client->works(); - $this->assertEquals($works, $result); - } - - public function testWorkByDoi(): void - { - $work = new Work([ - 'workId' => '9afc6760-f556-46a1-a912-39ea5ebc921b', - 'doi' => 'https://doi.org/10.00000/00000000' - ]); - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'workByDoi' => [ - 'workId' => '9afc6760-f556-46a1-a912-39ea5ebc921b', - 'doi' => 'https://doi.org/10.00000/00000000' - ] - ] - ]))); - - $result = $this->client->workByDoi('https://doi.org/10.00000/00000000'); - $this->assertEquals($work, $result); - } - - public function testWorkCount(): void - { - $expectedCount = 710; - - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'workCount' => 710 - ] - ]))); - - $result = $this->client->workCount(); - $this->assertSame($expectedCount, $result); - } - - public function testCreateAffiliation(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'createAffiliation' => [ - 'affiliationId' => 'e435b256-681c-4118-a3b5-bba22cb6fe7f' - ] - ] - ]))); - - $affiliation = new Affiliation(); - $result = $this->client->createAffiliation($affiliation); - $this->assertSame('e435b256-681c-4118-a3b5-bba22cb6fe7f', $result); - } - - public function testUpdateAffiliation(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'updateAffiliation' => [ - 'affiliationId' => 'e435b256-681c-4118-a3b5-bba22cb6fe7f' - ] - ] - ]))); - - $affiliation = new Affiliation(); - $result = $this->client->updateAffiliation($affiliation); - $this->assertSame('e435b256-681c-4118-a3b5-bba22cb6fe7f', $result); - } - - public function testDeleteAffiliation(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'deleteAffiliation' => [ - 'affiliationId' => 'e435b256-681c-4118-a3b5-bba22cb6fe7f' - ] - ] - ]))); - - $result = $this->client->deleteAffiliation('e435b256-681c-4118-a3b5-bba22cb6fe7f'); - $this->assertSame('e435b256-681c-4118-a3b5-bba22cb6fe7f', $result); - } - - public function testCreateContribution(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'createContribution' => [ - 'contributionId' => '5448ca99-ae7d-4347-9170-b8ffa067ebbf' - ] - ] - ]))); - - $contribution = new Contribution(); - $result = $this->client->createContribution($contribution); - $this->assertSame('5448ca99-ae7d-4347-9170-b8ffa067ebbf', $result); - } - - public function testUpdateContribution(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'updateContribution' => [ - 'contributionId' => '5448ca99-ae7d-4347-9170-b8ffa067ebbf' - ] - ] - ]))); - - $contribution = new Contribution(); - $result = $this->client->updateContribution($contribution); - $this->assertSame('5448ca99-ae7d-4347-9170-b8ffa067ebbf', $result); - } - - public function testDeleteContribution(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'deleteContribution' => [ - 'contributionId' => '5448ca99-ae7d-4347-9170-b8ffa067ebbf' - ] - ] - ]))); - - $result = $this->client->deleteContribution('5448ca99-ae7d-4347-9170-b8ffa067ebbf'); - $this->assertSame('5448ca99-ae7d-4347-9170-b8ffa067ebbf', $result); - } - - public function testCreateContributor(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'createContributor' => [ - 'contributorId' => '2724eca4-0d31-44ba-bbf4-19061a9637ce' - ] - ] - ]))); - - $contributor = new Contributor(); - $result = $this->client->createContributor($contributor); - $this->assertSame('2724eca4-0d31-44ba-bbf4-19061a9637ce', $result); - } - - public function testUpdateContributor(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'updateContributor' => [ - 'contributorId' => '2724eca4-0d31-44ba-bbf4-19061a9637ce' - ] - ] - ]))); - - $contributor = new Contributor(); - $result = $this->client->updateContributor($contributor); - $this->assertSame('2724eca4-0d31-44ba-bbf4-19061a9637ce', $result); - } - - public function testDeleteContributor(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'deleteContributor' => [ - 'contributorId' => '2724eca4-0d31-44ba-bbf4-19061a9637ce' - ] - ] - ]))); - - $result = $this->client->deleteContributor('2724eca4-0d31-44ba-bbf4-19061a9637ce'); - $this->assertSame('2724eca4-0d31-44ba-bbf4-19061a9637ce', $result); - } - - public function testCreateFunding(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'createFunding' => [ - 'fundingId' => 'bba5f263-3442-4a4e-8b2b-752a238b9c03' - ] - ] - ]))); - - $funding = new Funding(); - $result = $this->client->createFunding($funding); - $this->assertSame('bba5f263-3442-4a4e-8b2b-752a238b9c03', $result); - } - - public function testUpdateFunding(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'updateFunding' => [ - 'fundingId' => 'bba5f263-3442-4a4e-8b2b-752a238b9c03' - ] - ] - ]))); - - $funding = new Funding(); - $result = $this->client->updateFunding($funding); - $this->assertSame('bba5f263-3442-4a4e-8b2b-752a238b9c03', $result); - } - - public function testDeleteFunding(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'deleteFunding' => [ - 'fundingId' => 'bba5f263-3442-4a4e-8b2b-752a238b9c03' - ] - ] - ]))); - - $result = $this->client->deleteFunding('bba5f263-3442-4a4e-8b2b-752a238b9c03'); - $this->assertSame('bba5f263-3442-4a4e-8b2b-752a238b9c03', $result); - } - - public function testCreateImprint(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'createImprint' => [ - 'imprintId' => '7485750d-c8cf-4a7e-9a6c-c080b932dbd9' - ] - ] - ]))); - - $imprint = new Imprint(); - $result = $this->client->createImprint($imprint); - $this->assertSame('7485750d-c8cf-4a7e-9a6c-c080b932dbd9', $result); - } - - public function testUpdateImprint(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'updateImprint' => [ - 'imprintId' => '7485750d-c8cf-4a7e-9a6c-c080b932dbd9' - ] - ] - ]))); - - $imprint = new imprint(); - $result = $this->client->updateImprint($imprint); - $this->assertSame('7485750d-c8cf-4a7e-9a6c-c080b932dbd9', $result); - } - - public function testDeleteImprint(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'deleteImprint' => [ - 'imprintId' => '7485750d-c8cf-4a7e-9a6c-c080b932dbd9' - ] - ] - ]))); - - $result = $this->client->deleteImprint('7485750d-c8cf-4a7e-9a6c-c080b932dbd9'); - $this->assertSame('7485750d-c8cf-4a7e-9a6c-c080b932dbd9', $result); - } - - public function testCreateInstitution(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'createInstitution' => [ - 'institutionId' => 'a71debc6-0172-4cf5-b4c4-f932915ffce3' - ] - ] - ]))); - - $institution = new Institution(); - $result = $this->client->createInstitution($institution); - $this->assertSame('a71debc6-0172-4cf5-b4c4-f932915ffce3', $result); - } - - public function testUpdateInstitution(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'updateInstitution' => [ - 'institutionId' => 'a71debc6-0172-4cf5-b4c4-f932915ffce3' - ] - ] - ]))); - - $institution = new Institution(); - $result = $this->client->updateInstitution($institution); - $this->assertSame('a71debc6-0172-4cf5-b4c4-f932915ffce3', $result); - } - - public function testDeleteInstitution(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'deleteInstitution' => [ - 'institutionId' => 'a71debc6-0172-4cf5-b4c4-f932915ffce3' - ] - ] - ]))); - - $result = $this->client->deleteInstitution('a71debc6-0172-4cf5-b4c4-f932915ffce3'); - $this->assertSame('a71debc6-0172-4cf5-b4c4-f932915ffce3', $result); - } - - public function testCreateIssue(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'createIssue' => [ - 'issueId' => 'df439ff0-a8ed-4972-aada-956fb0bb27ce' - ] - ] - ]))); - - $issue = new Issue(); - $result = $this->client->createIssue($issue); - $this->assertSame('df439ff0-a8ed-4972-aada-956fb0bb27ce', $result); - } - - public function testUpdateIssue(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'updateIssue' => [ - 'issueId' => 'df439ff0-a8ed-4972-aada-956fb0bb27ce' - ] - ] - ]))); - - $issue = new Issue(); - $result = $this->client->updateIssue($issue); - $this->assertSame('df439ff0-a8ed-4972-aada-956fb0bb27ce', $result); - } - - public function testDeleteIssue(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'deleteIssue' => [ - 'issueId' => 'df439ff0-a8ed-4972-aada-956fb0bb27ce' - ] - ] - ]))); - - $result = $this->client->deleteIssue('df439ff0-a8ed-4972-aada-956fb0bb27ce'); - $this->assertSame('df439ff0-a8ed-4972-aada-956fb0bb27ce', $result); - } - - public function testCreateLanguage(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'createLanguage' => [ - 'languageId' => '1584d8e2-b856-4519-a507-c2399af11af5' - ] - ] - ]))); - - $language = new Language(); - $result = $this->client->createLanguage($language); - $this->assertSame('1584d8e2-b856-4519-a507-c2399af11af5', $result); - } - - public function testUpdateLanguage(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'updateLanguage' => [ - 'languageId' => '1584d8e2-b856-4519-a507-c2399af11af5' - ] - ] - ]))); - - $language = new language(); - $result = $this->client->updateLanguage($language); - $this->assertSame('1584d8e2-b856-4519-a507-c2399af11af5', $result); - } - - public function testDeleteLanguage(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'deleteLanguage' => [ - 'languageId' => '1584d8e2-b856-4519-a507-c2399af11af5' - ] - ] - ]))); - - $result = $this->client->deleteLanguage('1584d8e2-b856-4519-a507-c2399af11af5'); - $this->assertSame('1584d8e2-b856-4519-a507-c2399af11af5', $result); - } - - public function testCreateLocation(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'createLocation' => [ - 'locationId' => 'c45e9a4a-80e1-46c2-8845-61bf4263255e' - ] - ] - ]))); - - $location = new location(); - $result = $this->client->createLocation($location); - $this->assertSame('c45e9a4a-80e1-46c2-8845-61bf4263255e', $result); - } - - public function testUpdateLocation(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'updateLocation' => [ - 'locationId' => 'c45e9a4a-80e1-46c2-8845-61bf4263255e' - ] - ] - ]))); - - $location = new Location(); - $result = $this->client->updateLocation($location); - $this->assertSame('c45e9a4a-80e1-46c2-8845-61bf4263255e', $result); - } - - public function testDeleteLocation(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'deleteLocation' => [ - 'locationId' => 'c45e9a4a-80e1-46c2-8845-61bf4263255e' - ] - ] - ]))); - - $result = $this->client->deleteLocation('c45e9a4a-80e1-46c2-8845-61bf4263255e'); - $this->assertSame('c45e9a4a-80e1-46c2-8845-61bf4263255e', $result); - } - - public function testCreatePrice(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'createPrice' => [ - 'priceId' => '38e96434-88a3-4f1c-9c39-b9160000c61a' - ] - ] - ]))); - - $price = new Price(); - $result = $this->client->createPrice($price); - $this->assertSame('38e96434-88a3-4f1c-9c39-b9160000c61a', $result); - } - - public function testUpdatePrice(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'updatePrice' => [ - 'priceId' => '38e96434-88a3-4f1c-9c39-b9160000c61a' - ] - ] - ]))); - - $price = new Price(); - $result = $this->client->updatePrice($price); - $this->assertSame('38e96434-88a3-4f1c-9c39-b9160000c61a', $result); - } - - public function testDeletePrice(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'deletePrice' => [ - 'priceId' => '38e96434-88a3-4f1c-9c39-b9160000c61a' - ] - ] - ]))); - - $result = $this->client->deletePrice('38e96434-88a3-4f1c-9c39-b9160000c61a'); - $this->assertSame('38e96434-88a3-4f1c-9c39-b9160000c61a', $result); - } - - public function testCreatePublication(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'createPublication' => [ - 'publicationId' => '01fec4e9-fbff-4c2e-9752-a0562a506e4d' - ] - ] - ]))); - - $publication = new Publication(); - $result = $this->client->createPublication($publication); - $this->assertSame('01fec4e9-fbff-4c2e-9752-a0562a506e4d', $result); - } - - public function testUpdatePublication(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'updatePublication' => [ - 'publicationId' => '01fec4e9-fbff-4c2e-9752-a0562a506e4d' - ] - ] - ]))); - - $publication = new Publication(); - $result = $this->client->updatePublication($publication); - $this->assertSame('01fec4e9-fbff-4c2e-9752-a0562a506e4d', $result); - } - - public function testDeletePublication(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'deletePublication' => [ - 'publicationId' => '01fec4e9-fbff-4c2e-9752-a0562a506e4d' - ] - ] - ]))); - - $result = $this->client->deletePublication('01fec4e9-fbff-4c2e-9752-a0562a506e4d'); - $this->assertSame('01fec4e9-fbff-4c2e-9752-a0562a506e4d', $result); - } - - public function testCreatePublisher(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'createPublisher' => [ - 'publisherId' => 'a77ef552-856c-4585-9d35-fd58d2190b1b' - ] - ] - ]))); - - $publisher = new Publisher(); - $result = $this->client->createPublisher($publisher); - $this->assertSame('a77ef552-856c-4585-9d35-fd58d2190b1b', $result); - } - - public function testUpdatePublisher(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'updatePublisher' => [ - 'publisherId' => 'a77ef552-856c-4585-9d35-fd58d2190b1b' - ] - ] - ]))); - - $publisher = new Publisher(); - $result = $this->client->updatePublisher($publisher); - $this->assertSame('a77ef552-856c-4585-9d35-fd58d2190b1b', $result); - } - - public function testDeletePublisher(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'deletePublisher' => [ - 'publisherId' => 'a77ef552-856c-4585-9d35-fd58d2190b1b' - ] - ] - ]))); - - $result = $this->client->deletePublisher('a77ef552-856c-4585-9d35-fd58d2190b1b'); - $this->assertSame('a77ef552-856c-4585-9d35-fd58d2190b1b', $result); - } - - public function testCreateReference(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'createReference' => [ - 'referenceId' => '6b4060ff-a89b-4bdc-b722-2b87ef9d057a' - ] - ] - ]))); - - $reference = new Reference(); - $result = $this->client->createReference($reference); - $this->assertSame('6b4060ff-a89b-4bdc-b722-2b87ef9d057a', $result); - } - - public function testUpdateReference(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'updateReference' => [ - 'referenceId' => '6b4060ff-a89b-4bdc-b722-2b87ef9d057a' - ] - ] - ]))); - - $reference = new Reference(); - $result = $this->client->updateReference($reference); - $this->assertSame('6b4060ff-a89b-4bdc-b722-2b87ef9d057a', $result); - } - - public function testDeleteReference(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'deleteReference' => [ - 'referenceId' => '6b4060ff-a89b-4bdc-b722-2b87ef9d057a' - ] - ] - ]))); - - $result = $this->client->deleteReference('6b4060ff-a89b-4bdc-b722-2b87ef9d057a'); - $this->assertSame('6b4060ff-a89b-4bdc-b722-2b87ef9d057a', $result); - } - - public function testCreateSeries(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'createSeries' => [ - 'seriesId' => 'dc4ed0f7-89a4-4760-aad3-adec7294706d' - ] - ] - ]))); - - $series = new Series(); - $result = $this->client->createSeries($series); - $this->assertSame('dc4ed0f7-89a4-4760-aad3-adec7294706d', $result); - } - - public function testUpdateSeries(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'updateSeries' => [ - 'seriesId' => 'dc4ed0f7-89a4-4760-aad3-adec7294706d' - ] - ] - ]))); - - $series = new Series(); - $result = $this->client->updateSeries($series); - $this->assertSame('dc4ed0f7-89a4-4760-aad3-adec7294706d', $result); - } - - public function testDeleteSeries(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'deleteSeries' => [ - 'seriesId' => 'dc4ed0f7-89a4-4760-aad3-adec7294706d' - ] - ] - ]))); - - $result = $this->client->deleteSeries('dc4ed0f7-89a4-4760-aad3-adec7294706d'); - $this->assertSame('dc4ed0f7-89a4-4760-aad3-adec7294706d', $result); - } - - public function testCreateSubject(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'createSubject' => [ - 'subjectId' => 'e7ab386e-186a-4b1c-aa6f-e974b8a1e3cd' - ] - ] - ]))); - - $subject = new Subject(); - $result = $this->client->createSubject($subject); - $this->assertSame('e7ab386e-186a-4b1c-aa6f-e974b8a1e3cd', $result); - } - - public function testUpdateSubject(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'updateSubject' => [ - 'subjectId' => 'e7ab386e-186a-4b1c-aa6f-e974b8a1e3cd' - ] - ] - ]))); - - $subject = new Subject(); - $result = $this->client->updateSubject($subject); - $this->assertSame('e7ab386e-186a-4b1c-aa6f-e974b8a1e3cd', $result); - } - - public function testDeleteSubject(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'deleteSubject' => [ - 'subjectId' => 'e7ab386e-186a-4b1c-aa6f-e974b8a1e3cd' - ] - ] - ]))); - - $result = $this->client->deleteSubject('e7ab386e-186a-4b1c-aa6f-e974b8a1e3cd'); - $this->assertSame('e7ab386e-186a-4b1c-aa6f-e974b8a1e3cd', $result); - } - - public function testCreateWork(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'createWork' => [ - 'workId' => 'd81bab71-d9fe-456b-9951-2308b91db2b4' - ] - ] - ]))); - - $work = new Work(); - $result = $this->client->createWork($work); - $this->assertSame('d81bab71-d9fe-456b-9951-2308b91db2b4', $result); - } - - public function testUpdateWork(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'updateWork' => [ - 'workId' => 'd81bab71-d9fe-456b-9951-2308b91db2b4' - ] - ] - ]))); - - $work = new Work(); - $result = $this->client->updateWork($work); - $this->assertSame('d81bab71-d9fe-456b-9951-2308b91db2b4', $result); - } - - public function testDeleteWork(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'deleteWork' => [ - 'workId' => 'd81bab71-d9fe-456b-9951-2308b91db2b4' - ] - ] - ]))); - - $result = $this->client->deleteWork('d81bab71-d9fe-456b-9951-2308b91db2b4'); - $this->assertSame('d81bab71-d9fe-456b-9951-2308b91db2b4', $result); - } - - public function testCreateWorkRelation(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'createWorkRelation' => [ - 'workRelationId' => '64019725-3e50-41de-a785-e4e5ddc4620a' - ] - ] - ]))); - - $workRelation = new WorkRelation(); - $result = $this->client->createWorkRelation($workRelation); - $this->assertSame('64019725-3e50-41de-a785-e4e5ddc4620a', $result); - } - - public function testUpdateWorkRelation(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'updateWorkRelation' => [ - 'workRelationId' => '64019725-3e50-41de-a785-e4e5ddc4620a' - ] - ] - ]))); - - $workRelation = new WorkRelation(); - $result = $this->client->updateWorkRelation($workRelation); - $this->assertSame('64019725-3e50-41de-a785-e4e5ddc4620a', $result); - } - - public function testDeleteWorkRelation(): void - { - $this->mockHandler->append(new Response(200, [], json_encode([ - 'data' => [ - 'deleteWorkRelation' => [ - 'workRelationId' => '64019725-3e50-41de-a785-e4e5ddc4620a' - ] - ] - ]))); - - $result = $this->client->deleteWorkRelation('64019725-3e50-41de-a785-e4e5ddc4620a'); - $this->assertSame('64019725-3e50-41de-a785-e4e5ddc4620a', $result); - } - public function testRunRawQuery(): void { $this->mockHandler->append(new Response(200, [], json_encode([ diff --git a/tests/GraphQL/Concerns/HasClientMutationTests.php b/tests/GraphQL/Concerns/HasClientMutationTests.php new file mode 100644 index 0000000..5347bff --- /dev/null +++ b/tests/GraphQL/Concerns/HasClientMutationTests.php @@ -0,0 +1,773 @@ +mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'createAffiliation' => [ + 'affiliationId' => 'e435b256-681c-4118-a3b5-bba22cb6fe7f' + ] + ] + ]))); + + $affiliation = new Affiliation(); + $result = $this->client->createAffiliation($affiliation); + $this->assertSame('e435b256-681c-4118-a3b5-bba22cb6fe7f', $result); + } + + public function testUpdateAffiliation(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'updateAffiliation' => [ + 'affiliationId' => 'e435b256-681c-4118-a3b5-bba22cb6fe7f' + ] + ] + ]))); + + $affiliation = new Affiliation(); + $result = $this->client->updateAffiliation($affiliation); + $this->assertSame('e435b256-681c-4118-a3b5-bba22cb6fe7f', $result); + } + + public function testDeleteAffiliation(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'deleteAffiliation' => [ + 'affiliationId' => 'e435b256-681c-4118-a3b5-bba22cb6fe7f' + ] + ] + ]))); + + $result = $this->client->deleteAffiliation('e435b256-681c-4118-a3b5-bba22cb6fe7f'); + $this->assertSame('e435b256-681c-4118-a3b5-bba22cb6fe7f', $result); + } + + public function testCreateContribution(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'createContribution' => [ + 'contributionId' => '5448ca99-ae7d-4347-9170-b8ffa067ebbf' + ] + ] + ]))); + + $contribution = new Contribution(); + $result = $this->client->createContribution($contribution); + $this->assertSame('5448ca99-ae7d-4347-9170-b8ffa067ebbf', $result); + } + + public function testUpdateContribution(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'updateContribution' => [ + 'contributionId' => '5448ca99-ae7d-4347-9170-b8ffa067ebbf' + ] + ] + ]))); + + $contribution = new Contribution(); + $result = $this->client->updateContribution($contribution); + $this->assertSame('5448ca99-ae7d-4347-9170-b8ffa067ebbf', $result); + } + + public function testDeleteContribution(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'deleteContribution' => [ + 'contributionId' => '5448ca99-ae7d-4347-9170-b8ffa067ebbf' + ] + ] + ]))); + + $result = $this->client->deleteContribution('5448ca99-ae7d-4347-9170-b8ffa067ebbf'); + $this->assertSame('5448ca99-ae7d-4347-9170-b8ffa067ebbf', $result); + } + + public function testCreateContributor(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'createContributor' => [ + 'contributorId' => '2724eca4-0d31-44ba-bbf4-19061a9637ce' + ] + ] + ]))); + + $contributor = new Contributor(); + $result = $this->client->createContributor($contributor); + $this->assertSame('2724eca4-0d31-44ba-bbf4-19061a9637ce', $result); + } + + public function testUpdateContributor(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'updateContributor' => [ + 'contributorId' => '2724eca4-0d31-44ba-bbf4-19061a9637ce' + ] + ] + ]))); + + $contributor = new Contributor(); + $result = $this->client->updateContributor($contributor); + $this->assertSame('2724eca4-0d31-44ba-bbf4-19061a9637ce', $result); + } + + public function testDeleteContributor(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'deleteContributor' => [ + 'contributorId' => '2724eca4-0d31-44ba-bbf4-19061a9637ce' + ] + ] + ]))); + + $result = $this->client->deleteContributor('2724eca4-0d31-44ba-bbf4-19061a9637ce'); + $this->assertSame('2724eca4-0d31-44ba-bbf4-19061a9637ce', $result); + } + + public function testCreateFunding(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'createFunding' => [ + 'fundingId' => 'bba5f263-3442-4a4e-8b2b-752a238b9c03' + ] + ] + ]))); + + $funding = new Funding(); + $result = $this->client->createFunding($funding); + $this->assertSame('bba5f263-3442-4a4e-8b2b-752a238b9c03', $result); + } + + public function testUpdateFunding(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'updateFunding' => [ + 'fundingId' => 'bba5f263-3442-4a4e-8b2b-752a238b9c03' + ] + ] + ]))); + + $funding = new Funding(); + $result = $this->client->updateFunding($funding); + $this->assertSame('bba5f263-3442-4a4e-8b2b-752a238b9c03', $result); + } + + public function testDeleteFunding(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'deleteFunding' => [ + 'fundingId' => 'bba5f263-3442-4a4e-8b2b-752a238b9c03' + ] + ] + ]))); + + $result = $this->client->deleteFunding('bba5f263-3442-4a4e-8b2b-752a238b9c03'); + $this->assertSame('bba5f263-3442-4a4e-8b2b-752a238b9c03', $result); + } + + public function testCreateImprint(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'createImprint' => [ + 'imprintId' => '7485750d-c8cf-4a7e-9a6c-c080b932dbd9' + ] + ] + ]))); + + $imprint = new Imprint(); + $result = $this->client->createImprint($imprint); + $this->assertSame('7485750d-c8cf-4a7e-9a6c-c080b932dbd9', $result); + } + + public function testUpdateImprint(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'updateImprint' => [ + 'imprintId' => '7485750d-c8cf-4a7e-9a6c-c080b932dbd9' + ] + ] + ]))); + + $imprint = new Imprint(); + $result = $this->client->updateImprint($imprint); + $this->assertSame('7485750d-c8cf-4a7e-9a6c-c080b932dbd9', $result); + } + + public function testDeleteImprint(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'deleteImprint' => [ + 'imprintId' => '7485750d-c8cf-4a7e-9a6c-c080b932dbd9' + ] + ] + ]))); + + $result = $this->client->deleteImprint('7485750d-c8cf-4a7e-9a6c-c080b932dbd9'); + $this->assertSame('7485750d-c8cf-4a7e-9a6c-c080b932dbd9', $result); + } + + public function testCreateInstitution(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'createInstitution' => [ + 'institutionId' => 'a71debc6-0172-4cf5-b4c4-f932915ffce3' + ] + ] + ]))); + + $institution = new Institution(); + $result = $this->client->createInstitution($institution); + $this->assertSame('a71debc6-0172-4cf5-b4c4-f932915ffce3', $result); + } + + public function testUpdateInstitution(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'updateInstitution' => [ + 'institutionId' => 'a71debc6-0172-4cf5-b4c4-f932915ffce3' + ] + ] + ]))); + + $institution = new Institution(); + $result = $this->client->updateInstitution($institution); + $this->assertSame('a71debc6-0172-4cf5-b4c4-f932915ffce3', $result); + } + + public function testDeleteInstitution(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'deleteInstitution' => [ + 'institutionId' => 'a71debc6-0172-4cf5-b4c4-f932915ffce3' + ] + ] + ]))); + + $result = $this->client->deleteInstitution('a71debc6-0172-4cf5-b4c4-f932915ffce3'); + $this->assertSame('a71debc6-0172-4cf5-b4c4-f932915ffce3', $result); + } + + public function testCreateIssue(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'createIssue' => [ + 'issueId' => 'df439ff0-a8ed-4972-aada-956fb0bb27ce' + ] + ] + ]))); + + $issue = new Issue(); + $result = $this->client->createIssue($issue); + $this->assertSame('df439ff0-a8ed-4972-aada-956fb0bb27ce', $result); + } + + public function testUpdateIssue(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'updateIssue' => [ + 'issueId' => 'df439ff0-a8ed-4972-aada-956fb0bb27ce' + ] + ] + ]))); + + $issue = new Issue(); + $result = $this->client->updateIssue($issue); + $this->assertSame('df439ff0-a8ed-4972-aada-956fb0bb27ce', $result); + } + + public function testDeleteIssue(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'deleteIssue' => [ + 'issueId' => 'df439ff0-a8ed-4972-aada-956fb0bb27ce' + ] + ] + ]))); + + $result = $this->client->deleteIssue('df439ff0-a8ed-4972-aada-956fb0bb27ce'); + $this->assertSame('df439ff0-a8ed-4972-aada-956fb0bb27ce', $result); + } + + public function testCreateLanguage(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'createLanguage' => [ + 'languageId' => '1584d8e2-b856-4519-a507-c2399af11af5' + ] + ] + ]))); + + $language = new Language(); + $result = $this->client->createLanguage($language); + $this->assertSame('1584d8e2-b856-4519-a507-c2399af11af5', $result); + } + + public function testUpdateLanguage(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'updateLanguage' => [ + 'languageId' => '1584d8e2-b856-4519-a507-c2399af11af5' + ] + ] + ]))); + + $language = new Language(); + $result = $this->client->updateLanguage($language); + $this->assertSame('1584d8e2-b856-4519-a507-c2399af11af5', $result); + } + + public function testDeleteLanguage(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'deleteLanguage' => [ + 'languageId' => '1584d8e2-b856-4519-a507-c2399af11af5' + ] + ] + ]))); + + $result = $this->client->deleteLanguage('1584d8e2-b856-4519-a507-c2399af11af5'); + $this->assertSame('1584d8e2-b856-4519-a507-c2399af11af5', $result); + } + + public function testCreateLocation(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'createLocation' => [ + 'locationId' => 'c45e9a4a-80e1-46c2-8845-61bf4263255e' + ] + ] + ]))); + + $location = new Location(); + $result = $this->client->createLocation($location); + $this->assertSame('c45e9a4a-80e1-46c2-8845-61bf4263255e', $result); + } + + public function testUpdateLocation(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'updateLocation' => [ + 'locationId' => 'c45e9a4a-80e1-46c2-8845-61bf4263255e' + ] + ] + ]))); + + $location = new Location(); + $result = $this->client->updateLocation($location); + $this->assertSame('c45e9a4a-80e1-46c2-8845-61bf4263255e', $result); + } + + public function testDeleteLocation(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'deleteLocation' => [ + 'locationId' => 'c45e9a4a-80e1-46c2-8845-61bf4263255e' + ] + ] + ]))); + + $result = $this->client->deleteLocation('c45e9a4a-80e1-46c2-8845-61bf4263255e'); + $this->assertSame('c45e9a4a-80e1-46c2-8845-61bf4263255e', $result); + } + + public function testCreatePrice(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'createPrice' => [ + 'priceId' => '38e96434-88a3-4f1c-9c39-b9160000c61a' + ] + ] + ]))); + + $price = new Price(); + $result = $this->client->createPrice($price); + $this->assertSame('38e96434-88a3-4f1c-9c39-b9160000c61a', $result); + } + + public function testUpdatePrice(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'updatePrice' => [ + 'priceId' => '38e96434-88a3-4f1c-9c39-b9160000c61a' + ] + ] + ]))); + + $price = new Price(); + $result = $this->client->updatePrice($price); + $this->assertSame('38e96434-88a3-4f1c-9c39-b9160000c61a', $result); + } + + public function testDeletePrice(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'deletePrice' => [ + 'priceId' => '38e96434-88a3-4f1c-9c39-b9160000c61a' + ] + ] + ]))); + + $result = $this->client->deletePrice('38e96434-88a3-4f1c-9c39-b9160000c61a'); + $this->assertSame('38e96434-88a3-4f1c-9c39-b9160000c61a', $result); + } + + public function testCreatePublication(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'createPublication' => [ + 'publicationId' => '01fec4e9-fbff-4c2e-9752-a0562a506e4d' + ] + ] + ]))); + + $publication = new Publication(); + $result = $this->client->createPublication($publication); + $this->assertSame('01fec4e9-fbff-4c2e-9752-a0562a506e4d', $result); + } + + public function testUpdatePublication(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'updatePublication' => [ + 'publicationId' => '01fec4e9-fbff-4c2e-9752-a0562a506e4d' + ] + ] + ]))); + + $publication = new Publication(); + $result = $this->client->updatePublication($publication); + $this->assertSame('01fec4e9-fbff-4c2e-9752-a0562a506e4d', $result); + } + + public function testDeletePublication(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'deletePublication' => [ + 'publicationId' => '01fec4e9-fbff-4c2e-9752-a0562a506e4d' + ] + ] + ]))); + + $result = $this->client->deletePublication('01fec4e9-fbff-4c2e-9752-a0562a506e4d'); + $this->assertSame('01fec4e9-fbff-4c2e-9752-a0562a506e4d', $result); + } + + public function testCreatePublisher(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'createPublisher' => [ + 'publisherId' => 'a77ef552-856c-4585-9d35-fd58d2190b1b' + ] + ] + ]))); + + $publisher = new Publisher(); + $result = $this->client->createPublisher($publisher); + $this->assertSame('a77ef552-856c-4585-9d35-fd58d2190b1b', $result); + } + + public function testUpdatePublisher(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'updatePublisher' => [ + 'publisherId' => 'a77ef552-856c-4585-9d35-fd58d2190b1b' + ] + ] + ]))); + + $publisher = new Publisher(); + $result = $this->client->updatePublisher($publisher); + $this->assertSame('a77ef552-856c-4585-9d35-fd58d2190b1b', $result); + } + + public function testDeletePublisher(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'deletePublisher' => [ + 'publisherId' => 'a77ef552-856c-4585-9d35-fd58d2190b1b' + ] + ] + ]))); + + $result = $this->client->deletePublisher('a77ef552-856c-4585-9d35-fd58d2190b1b'); + $this->assertSame('a77ef552-856c-4585-9d35-fd58d2190b1b', $result); + } + + public function testCreateReference(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'createReference' => [ + 'referenceId' => '6b4060ff-a89b-4bdc-b722-2b87ef9d057a' + ] + ] + ]))); + + $reference = new Reference(); + $result = $this->client->createReference($reference); + $this->assertSame('6b4060ff-a89b-4bdc-b722-2b87ef9d057a', $result); + } + + public function testUpdateReference(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'updateReference' => [ + 'referenceId' => '6b4060ff-a89b-4bdc-b722-2b87ef9d057a' + ] + ] + ]))); + + $reference = new Reference(); + $result = $this->client->updateReference($reference); + $this->assertSame('6b4060ff-a89b-4bdc-b722-2b87ef9d057a', $result); + } + + public function testDeleteReference(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'deleteReference' => [ + 'referenceId' => '6b4060ff-a89b-4bdc-b722-2b87ef9d057a' + ] + ] + ]))); + + $result = $this->client->deleteReference('6b4060ff-a89b-4bdc-b722-2b87ef9d057a'); + $this->assertSame('6b4060ff-a89b-4bdc-b722-2b87ef9d057a', $result); + } + + public function testCreateSeries(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'createSeries' => [ + 'seriesId' => 'dc4ed0f7-89a4-4760-aad3-adec7294706d' + ] + ] + ]))); + + $series = new Series(); + $result = $this->client->createSeries($series); + $this->assertSame('dc4ed0f7-89a4-4760-aad3-adec7294706d', $result); + } + + public function testUpdateSeries(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'updateSeries' => [ + 'seriesId' => 'dc4ed0f7-89a4-4760-aad3-adec7294706d' + ] + ] + ]))); + + $series = new Series(); + $result = $this->client->updateSeries($series); + $this->assertSame('dc4ed0f7-89a4-4760-aad3-adec7294706d', $result); + } + + public function testDeleteSeries(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'deleteSeries' => [ + 'seriesId' => 'dc4ed0f7-89a4-4760-aad3-adec7294706d' + ] + ] + ]))); + + $result = $this->client->deleteSeries('dc4ed0f7-89a4-4760-aad3-adec7294706d'); + $this->assertSame('dc4ed0f7-89a4-4760-aad3-adec7294706d', $result); + } + + public function testCreateSubject(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'createSubject' => [ + 'subjectId' => 'e7ab386e-186a-4b1c-aa6f-e974b8a1e3cd' + ] + ] + ]))); + + $subject = new Subject(); + $result = $this->client->createSubject($subject); + $this->assertSame('e7ab386e-186a-4b1c-aa6f-e974b8a1e3cd', $result); + } + + public function testUpdateSubject(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'updateSubject' => [ + 'subjectId' => 'e7ab386e-186a-4b1c-aa6f-e974b8a1e3cd' + ] + ] + ]))); + + $subject = new Subject(); + $result = $this->client->updateSubject($subject); + $this->assertSame('e7ab386e-186a-4b1c-aa6f-e974b8a1e3cd', $result); + } + + public function testDeleteSubject(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'deleteSubject' => [ + 'subjectId' => 'e7ab386e-186a-4b1c-aa6f-e974b8a1e3cd' + ] + ] + ]))); + + $result = $this->client->deleteSubject('e7ab386e-186a-4b1c-aa6f-e974b8a1e3cd'); + $this->assertSame('e7ab386e-186a-4b1c-aa6f-e974b8a1e3cd', $result); + } + + public function testCreateWork(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'createWork' => [ + 'workId' => 'd81bab71-d9fe-456b-9951-2308b91db2b4' + ] + ] + ]))); + + $work = new Work(); + $result = $this->client->createWork($work); + $this->assertSame('d81bab71-d9fe-456b-9951-2308b91db2b4', $result); + } + + public function testUpdateWork(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'updateWork' => [ + 'workId' => 'd81bab71-d9fe-456b-9951-2308b91db2b4' + ] + ] + ]))); + + $work = new Work(); + $result = $this->client->updateWork($work); + $this->assertSame('d81bab71-d9fe-456b-9951-2308b91db2b4', $result); + } + + public function testDeleteWork(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'deleteWork' => [ + 'workId' => 'd81bab71-d9fe-456b-9951-2308b91db2b4' + ] + ] + ]))); + + $result = $this->client->deleteWork('d81bab71-d9fe-456b-9951-2308b91db2b4'); + $this->assertSame('d81bab71-d9fe-456b-9951-2308b91db2b4', $result); + } + + public function testCreateWorkRelation(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'createWorkRelation' => [ + 'workRelationId' => '64019725-3e50-41de-a785-e4e5ddc4620a' + ] + ] + ]))); + + $workRelation = new WorkRelation(); + $result = $this->client->createWorkRelation($workRelation); + $this->assertSame('64019725-3e50-41de-a785-e4e5ddc4620a', $result); + } + + public function testUpdateWorkRelation(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'updateWorkRelation' => [ + 'workRelationId' => '64019725-3e50-41de-a785-e4e5ddc4620a' + ] + ] + ]))); + + $workRelation = new WorkRelation(); + $result = $this->client->updateWorkRelation($workRelation); + $this->assertSame('64019725-3e50-41de-a785-e4e5ddc4620a', $result); + } + + public function testDeleteWorkRelation(): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'deleteWorkRelation' => [ + 'workRelationId' => '64019725-3e50-41de-a785-e4e5ddc4620a' + ] + ] + ]))); + + $result = $this->client->deleteWorkRelation('64019725-3e50-41de-a785-e4e5ddc4620a'); + $this->assertSame('64019725-3e50-41de-a785-e4e5ddc4620a', $result); + } +} diff --git a/tests/GraphQL/Concerns/HasClientQueryTests.php b/tests/GraphQL/Concerns/HasClientQueryTests.php new file mode 100644 index 0000000..a46b674 --- /dev/null +++ b/tests/GraphQL/Concerns/HasClientQueryTests.php @@ -0,0 +1,1024 @@ + '9afc6760-f556-46a1-a912-39ea5ebc921b']); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'affiliation' => [ + 'affiliationId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' + ] + ] + ]))); + + $result = $this->client->affiliation('9afc6760-f556-46a1-a912-39ea5ebc921b'); + $this->assertEquals($affiliation, $result); + } + + public function testAffiliations(): void + { + $affiliations = [ + new Affiliation(['affiliationId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new Affiliation(['affiliationId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'affiliations' => [ + [ + 'affiliationId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' + ], + [ + 'affiliationId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' + ] + ] + ] + ]))); + + $result = $this->client->affiliations(); + $this->assertEquals($affiliations, $result); + } + + public function testAffiliationCount(): void + { + $expectedCount = 710; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'affiliationCount' => 710 + ] + ]))); + + $result = $this->client->affiliationCount(); + $this->assertSame($expectedCount, $result); + } + + public function testContribution(): void + { + $contribution = new Contribution(['contributionId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'contribution' => [ + 'contributionId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' + ] + ] + ]))); + + $result = $this->client->contribution('9afc6760-f556-46a1-a912-39ea5ebc921b'); + $this->assertEquals($contribution, $result); + } + + public function testBooks(): void + { + $books = [ + new Work(['workId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new Work(['workId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'books' => [ + [ + 'workId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' + ], + [ + 'workId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' + ] + ] + ] + ]))); + + $result = $this->client->books(); + $this->assertEquals($books, $result); + } + + public function testBookByDoi(): void + { + $book = new Work([ + 'workId' => '9afc6760-f556-46a1-a912-39ea5ebc921b', + 'doi' => 'https://doi.org/10.00000/00000000' + ]); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'bookByDoi' => [ + 'workId' => '9afc6760-f556-46a1-a912-39ea5ebc921b', + 'doi' => 'https://doi.org/10.00000/00000000' + ] + ] + ]))); + + $result = $this->client->bookByDoi('https://doi.org/10.00000/00000000'); + $this->assertEquals($book, $result); + } + + public function testBookCount(): void + { + $expectedCount = 710; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'bookCount' => 710 + ] + ]))); + + $result = $this->client->bookCount(); + $this->assertSame($expectedCount, $result); + } + + public function testChapters(): void + { + $chapters = [ + new Work(['workId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new Work(['workId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'chapters' => [ + [ + 'workId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' + ], + [ + 'workId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' + ] + ] + ] + ]))); + + $result = $this->client->chapters(); + $this->assertEquals($chapters, $result); + } + + public function testChapterByDoi(): void + { + $chapter = new Work([ + 'workId' => '9afc6760-f556-46a1-a912-39ea5ebc921b', + 'doi' => 'https://doi.org/10.00000/00000000' + ]); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'chapterByDoi' => [ + 'workId' => '9afc6760-f556-46a1-a912-39ea5ebc921b', + 'doi' => 'https://doi.org/10.00000/00000000' + ] + ] + ]))); + + $result = $this->client->chapterByDoi('https://doi.org/10.00000/00000000'); + $this->assertEquals($chapter, $result); + } + + public function testChapterCount(): void + { + $expectedCount = 710; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'chapterCount' => 710 + ] + ]))); + + $result = $this->client->chapterCount(); + $this->assertSame($expectedCount, $result); + } + + public function testContributions(): void + { + $contributions = [ + new Contribution(['contributionId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new Contribution(['contributionId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'contributions' => [ + [ + 'contributionId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' + ], + [ + 'contributionId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' + ] + ] + ] + ]))); + + $result = $this->client->contributions(); + $this->assertEquals($contributions, $result); + } + + public function testContributionCount(): void + { + $expectedCount = 710; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'contributionCount' => 710 + ] + ]))); + + $result = $this->client->contributionCount(); + $this->assertSame($expectedCount, $result); + } + + public function testContributor(): void + { + $contributor = new Contributor(['contributorId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'contributor' => [ + 'contributorId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' + ] + ] + ]))); + + $result = $this->client->contributor('9afc6760-f556-46a1-a912-39ea5ebc921b'); + $this->assertEquals($contributor, $result); + } + + public function testContributors(): void + { + $contributors = [ + new Contributor(['contributorId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new Contributor(['contributorId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'contributors' => [ + [ + 'contributorId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' + ], + [ + 'contributorId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' + ] + ] + ] + ]))); + + $result = $this->client->contributors(); + $this->assertEquals($contributors, $result); + } + + public function testContributorCount(): void + { + $expectedCount = 710; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'contributorCount' => 710 + ] + ]))); + + $result = $this->client->contributorCount(); + $this->assertSame($expectedCount, $result); + } + + public function testFunding(): void + { + $funding = new Funding(['fundingId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'funding' => [ + 'fundingId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' + ] + ] + ]))); + + $result = $this->client->funding('9afc6760-f556-46a1-a912-39ea5ebc921b'); + $this->assertEquals($funding, $result); + } + + public function testFundings(): void + { + $fundings = [ + new Funding(['fundingId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new Funding(['fundingId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'fundings' => [ + [ + 'fundingId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' + ], + [ + 'fundingId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' + ] + ] + ] + ]))); + + $result = $this->client->fundings(); + $this->assertEquals($fundings, $result); + } + + public function testFundingCount(): void + { + $expectedCount = 710; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'fundingCount' => 710 + ] + ]))); + + $result = $this->client->fundingCount(); + $this->assertSame($expectedCount, $result); + } + + public function testImprint(): void + { + $imprint = new Imprint(['imprintId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'imprint' => [ + 'imprintId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' + ] + ] + ]))); + + $result = $this->client->imprint('9afc6760-f556-46a1-a912-39ea5ebc921b'); + $this->assertEquals($imprint, $result); + } + + public function testImprints(): void + { + $imprints = [ + new Imprint(['imprintId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new Imprint(['imprintId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'imprints' => [ + [ + 'imprintId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' + ], + [ + 'imprintId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' + ] + ] + ] + ]))); + + $result = $this->client->imprints(); + $this->assertEquals($imprints, $result); + } + + public function testImprintCount(): void + { + $expectedCount = 710; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'imprintCount' => 710 + ] + ]))); + + $result = $this->client->imprintCount(); + $this->assertSame($expectedCount, $result); + } + + public function testInstitution(): void + { + $institution = new Institution(['institutionId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'institution' => [ + 'institutionId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' + ] + ] + ]))); + + $result = $this->client->institution('9afc6760-f556-46a1-a912-39ea5ebc921b'); + $this->assertEquals($institution, $result); + } + + public function testInstitutions(): void + { + $institutions = [ + new Institution(['institutionId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new Institution(['institutionId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'institutions' => [ + [ + 'institutionId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' + ], + [ + 'institutionId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' + ] + ] + ] + ]))); + + $result = $this->client->institutions(); + $this->assertEquals($institutions, $result); + } + + public function testInstitutionCount(): void + { + $expectedCount = 710; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'institutionCount' => 710 + ] + ]))); + + $result = $this->client->institutionCount(); + $this->assertSame($expectedCount, $result); + } + + public function testIssue(): void + { + $issue = new Issue(['issueId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'issue' => [ + 'issueId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' + ] + ] + ]))); + + $result = $this->client->issue('9afc6760-f556-46a1-a912-39ea5ebc921b'); + $this->assertEquals($issue, $result); + } + + public function testIssues(): void + { + $issues = [ + new Issue(['issueId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new Issue(['issueId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'issues' => [ + [ + 'issueId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' + ], + [ + 'issueId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' + ] + ] + ] + ]))); + + $result = $this->client->issues(); + $this->assertEquals($issues, $result); + } + + public function testIssueCount(): void + { + $expectedCount = 710; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'issueCount' => 710 + ] + ]))); + + $result = $this->client->issueCount(); + $this->assertSame($expectedCount, $result); + } + + public function testLanguage(): void + { + $language = new Language(['languageId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'language' => [ + 'languageId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' + ] + ] + ]))); + + $result = $this->client->language('9afc6760-f556-46a1-a912-39ea5ebc921b'); + $this->assertEquals($language, $result); + } + + public function testLanguages(): void + { + $languages = [ + new Language(['languageId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new Language(['languageId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'languages' => [ + [ + 'languageId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' + ], + [ + 'languageId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' + ] + ] + ] + ]))); + + $result = $this->client->languages(); + $this->assertEquals($languages, $result); + } + + public function testLanguageCount(): void + { + $expectedCount = 710; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'languageCount' => 710 + ] + ]))); + + $result = $this->client->languageCount(); + $this->assertSame($expectedCount, $result); + } + + public function testLocation(): void + { + $location = new Location(['locationId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'location' => [ + 'locationId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' + ] + ] + ]))); + + $result = $this->client->location('9afc6760-f556-46a1-a912-39ea5ebc921b'); + $this->assertEquals($location, $result); + } + + public function testLocations(): void + { + $locations = [ + new Location(['locationId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new Location(['locationId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'locations' => [ + [ + 'locationId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' + ], + [ + 'locationId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' + ] + ] + ] + ]))); + + $result = $this->client->locations(); + $this->assertEquals($locations, $result); + } + + public function testLocationCount(): void + { + $expectedCount = 710; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'locationCount' => 710 + ] + ]))); + + $result = $this->client->locationCount(); + $this->assertSame($expectedCount, $result); + } + + public function testPrice(): void + { + $price = new Price(['priceId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'price' => [ + 'priceId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' + ] + ] + ]))); + + $result = $this->client->price('9afc6760-f556-46a1-a912-39ea5ebc921b'); + $this->assertEquals($price, $result); + } + + public function testPrices(): void + { + $prices = [ + new Price(['priceId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new Price(['priceId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'prices' => [ + [ + 'priceId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' + ], + [ + 'priceId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' + ] + ] + ] + ]))); + + $result = $this->client->prices(); + $this->assertEquals($prices, $result); + } + + public function testPriceCount(): void + { + $expectedCount = 710; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'priceCount' => 710 + ] + ]))); + + $result = $this->client->priceCount(); + $this->assertSame($expectedCount, $result); + } + + public function testPublication(): void + { + $publication = new Publication(['publicationId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'publication' => [ + 'publicationId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' + ] + ] + ]))); + + $result = $this->client->publication('9afc6760-f556-46a1-a912-39ea5ebc921b'); + $this->assertEquals($publication, $result); + } + + public function testPublications(): void + { + $publications = [ + new Publication(['publicationId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new Publication(['publicationId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'publications' => [ + [ + 'publicationId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' + ], + [ + 'publicationId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' + ] + ] + ] + ]))); + + $result = $this->client->publications(); + $this->assertEquals($publications, $result); + } + + public function testPublicationCount(): void + { + $expectedCount = 710; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'publicationCount' => 710 + ] + ]))); + + $result = $this->client->publicationCount(); + $this->assertSame($expectedCount, $result); + } + + public function testPublisher(): void + { + $publisher = new Publisher(['publisherId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'publisher' => [ + 'publisherId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' + ] + ] + ]))); + + $result = $this->client->publisher('9afc6760-f556-46a1-a912-39ea5ebc921b'); + $this->assertEquals($publisher, $result); + } + + public function testPublishers(): void + { + $publishers = [ + new Publisher(['publisherId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new Publisher(['publisherId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'publishers' => [ + [ + 'publisherId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' + ], + [ + 'publisherId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' + ] + ] + ] + ]))); + + $result = $this->client->publishers(); + $this->assertEquals($publishers, $result); + } + + public function testPublisherCount(): void + { + $expectedCount = 710; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'publisherCount' => 710 + ] + ]))); + + $result = $this->client->publisherCount(); + $this->assertSame($expectedCount, $result); + } + + public function testReference(): void + { + $reference = new Reference(['referenceId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'reference' => [ + 'referenceId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' + ] + ] + ]))); + + $result = $this->client->reference('9afc6760-f556-46a1-a912-39ea5ebc921b'); + $this->assertEquals($reference, $result); + } + + public function testReferences(): void + { + $references = [ + new Reference(['referenceId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new Reference(['referenceId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'references' => [ + [ + 'referenceId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' + ], + [ + 'referenceId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' + ] + ] + ] + ]))); + + $result = $this->client->references(); + $this->assertEquals($references, $result); + } + + public function testReferenceCount(): void + { + $expectedCount = 710; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'referenceCount' => 710 + ] + ]))); + + $result = $this->client->referenceCount(); + $this->assertSame($expectedCount, $result); + } + + public function testSeries(): void + { + $series = new Series(['seriesId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'series' => [ + 'seriesId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' + ] + ] + ]))); + + $result = $this->client->series('9afc6760-f556-46a1-a912-39ea5ebc921b'); + $this->assertEquals($series, $result); + } + + public function testSerieses(): void + { + $serieses = [ + new Series(['seriesId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new Series(['seriesId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'serieses' => [ + [ + 'seriesId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' + ], + [ + 'seriesId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' + ] + ] + ] + ]))); + + $result = $this->client->serieses(); + $this->assertEquals($serieses, $result); + } + + public function testSeriesCount(): void + { + $expectedCount = 710; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'seriesCount' => 710 + ] + ]))); + + $result = $this->client->seriesCount(); + $this->assertSame($expectedCount, $result); + } + + public function testSubject(): void + { + $subject = new Subject(['subjectId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'subject' => [ + 'subjectId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' + ] + ] + ]))); + + $result = $this->client->subject('9afc6760-f556-46a1-a912-39ea5ebc921b'); + $this->assertEquals($subject, $result); + } + + public function testSubjects(): void + { + $subjects = [ + new Subject(['subjectId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new Subject(['subjectId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'subjects' => [ + [ + 'subjectId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' + ], + [ + 'subjectId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' + ] + ] + ] + ]))); + + $result = $this->client->subjects(); + $this->assertEquals($subjects, $result); + } + + public function testSubjectCount(): void + { + $expectedCount = 710; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'subjectCount' => 710 + ] + ]))); + + $result = $this->client->subjectCount(); + $this->assertSame($expectedCount, $result); + } + + public function testWork(): void + { + $work = new Work(['workId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'work' => [ + 'workId' => '9afc6760-f556-46a1-a912-39ea5ebc921b' + ] + ] + ]))); + + $result = $this->client->work('9afc6760-f556-46a1-a912-39ea5ebc921b'); + $this->assertEquals($work, $result); + } + + public function testWorks(): void + { + $works = [ + new Work(['workId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new Work(['workId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'works' => [ + [ + 'workId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2' + ], + [ + 'workId' => '0472b0af-acf6-4f27-bee3-d3414466ccec' + ] + ] + ] + ]))); + + $result = $this->client->works(); + $this->assertEquals($works, $result); + } + + public function testWorkByDoi(): void + { + $work = new Work([ + 'workId' => '9afc6760-f556-46a1-a912-39ea5ebc921b', + 'doi' => 'https://doi.org/10.00000/00000000' + ]); + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'workByDoi' => [ + 'workId' => '9afc6760-f556-46a1-a912-39ea5ebc921b', + 'doi' => 'https://doi.org/10.00000/00000000' + ] + ] + ]))); + + $result = $this->client->workByDoi('https://doi.org/10.00000/00000000'); + $this->assertEquals($work, $result); + } + + public function testWorkCount(): void + { + $expectedCount = 710; + + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + 'workCount' => 710 + ] + ]))); + + $result = $this->client->workCount(); + $this->assertSame($expectedCount, $result); + } +} From 1226b3bf59496fa035a735fddad83c6c9a127562 Mon Sep 17 00:00:00 2001 From: Thiago Matos Date: Fri, 10 Apr 2026 18:23:06 -0400 Subject: [PATCH 4/8] fix(php): restore php 7.4 compatibility --- src/GraphQL/Client.php | 16 ++++++++++------ src/GraphQL/MutationBuilder.php | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/GraphQL/Client.php b/src/GraphQL/Client.php index fde35cd..fbfe523 100644 --- a/src/GraphQL/Client.php +++ b/src/GraphQL/Client.php @@ -106,12 +106,16 @@ private function getModelClass(string $entityName): string private function getIdentifierField(string $entityName): string { - return match ($entityName) { - 'additionalResource' => 'additionalResourceId', - 'bookReview' => 'bookReviewId', - 'workFeaturedVideo' => 'workFeaturedVideoId', - default => $entityName . 'Id', - }; + switch ($entityName) { + case 'additionalResource': + return 'additionalResourceId'; + case 'bookReview': + return 'bookReviewId'; + case 'workFeaturedVideo': + return 'workFeaturedVideoId'; + default: + return $entityName . 'Id'; + } } private function query(string $queryName, array $args = [], ?string $token = null): array diff --git a/src/GraphQL/MutationBuilder.php b/src/GraphQL/MutationBuilder.php index e225e8b..4b9de38 100644 --- a/src/GraphQL/MutationBuilder.php +++ b/src/GraphQL/MutationBuilder.php @@ -4,7 +4,7 @@ class MutationBuilder { - public static function build(string $mutationName, array $mutationData, array|bool $extraArgs = []): string + public static function build(string $mutationName, array $mutationData, $extraArgs = []): string { $nestedOverride = null; if (is_bool($extraArgs)) { From 89001eeb78747a429619a940062bcc28f7c4366d Mon Sep 17 00:00:00 2001 From: Thiago Matos Date: Fri, 10 Apr 2026 18:24:51 -0400 Subject: [PATCH 5/8] style(graphql): order query provider imports --- src/GraphQL/QueryProvider.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GraphQL/QueryProvider.php b/src/GraphQL/QueryProvider.php index ccca404..d216078 100644 --- a/src/GraphQL/QueryProvider.php +++ b/src/GraphQL/QueryProvider.php @@ -4,14 +4,14 @@ use ThothApi\GraphQL\Queries\AbstractQuery; use ThothApi\GraphQL\Queries\AbstractTextQuery; -use ThothApi\GraphQL\Queries\AffiliationQuery; use ThothApi\GraphQL\Queries\AdditionalResourceQuery; +use ThothApi\GraphQL\Queries\AffiliationQuery; use ThothApi\GraphQL\Queries\AwardQuery; use ThothApi\GraphQL\Queries\BiographyQuery; use ThothApi\GraphQL\Queries\BookReviewQuery; +use ThothApi\GraphQL\Queries\ContactQuery; use ThothApi\GraphQL\Queries\ContributionQuery; use ThothApi\GraphQL\Queries\ContributorQuery; -use ThothApi\GraphQL\Queries\ContactQuery; use ThothApi\GraphQL\Queries\EndorsementQuery; use ThothApi\GraphQL\Queries\FileQuery; use ThothApi\GraphQL\Queries\FundingQuery; @@ -28,8 +28,8 @@ use ThothApi\GraphQL\Queries\SeriesQuery; use ThothApi\GraphQL\Queries\SubjectQuery; use ThothApi\GraphQL\Queries\TitleQuery; -use ThothApi\GraphQL\Queries\WorkQuery; use ThothApi\GraphQL\Queries\WorkFeaturedVideoQuery; +use ThothApi\GraphQL\Queries\WorkQuery; class QueryProvider { From 753eae2ae5bc99940651b30dcb028826dfecb0a3 Mon Sep 17 00:00:00 2001 From: Thiago Matos Date: Fri, 10 Apr 2026 18:39:12 -0400 Subject: [PATCH 6/8] docs(license): update copyright years --- LICENSE | 3 ++- README.md | 4 ++-- docs/README-es.md | 4 ++-- docs/README-pt_BR.md | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/LICENSE b/LICENSE index 6d02bda..4f360d6 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,8 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2024 Thiago Matos + Copyright 2026 Thoth Open Metadata + Copyright 2026 Lepidus Tecnologia Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 0631a4d..f9bd832 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,6 @@ Developed by [Lepidus Tecnologia](https://github.com/lepidus). Licensed under the Apache License, Version 2.0 - [See the License file.](/LICENSE) -Copyright (c) 2024 Lepidus Tecnologia +Copyright (c) 2024-2026 Lepidus Tecnologia -Copyright (c) 2024 Thoth +Copyright (c) 2024-2026 Thoth Open Metadata diff --git a/docs/README-es.md b/docs/README-es.md index b69dcea..427addf 100644 --- a/docs/README-es.md +++ b/docs/README-es.md @@ -211,6 +211,6 @@ Desarrollado por [Lepidus Tecnologia](https://github.com/lepidus). Licenciado bajo la Licencia Apache, Versión 2.0 - [Consulta el archivo de licencia.](/LICENSE) -Copyright (c) 2024 Lepidus Tecnologia +Copyright (c) 2024-2026 Lepidus Tecnologia -Copyright (c) 2024 Thoth +Copyright (c) 2024-2026 Thoth Open Metadata diff --git a/docs/README-pt_BR.md b/docs/README-pt_BR.md index 36a1490..248edb2 100644 --- a/docs/README-pt_BR.md +++ b/docs/README-pt_BR.md @@ -211,6 +211,6 @@ Desenvolvido por [Lepidus Tecnologia](https://github.com/lepidus). Licenciado sob a Licença Apache, Versão 2.0 - [Veja o arquivo de licença.](/LICENSE) -Copyright (c) 2024 Lepidus Tecnologia +Copyright (c) 2024-2026 Lepidus Tecnologia -Copyright (c) 2024 Thoth +Copyright (c) 2024-2026 Thoth Open Metadata From 451202c6e7f6a5bf87a3c3419d473ccf00cd150b Mon Sep 17 00:00:00 2001 From: Thiago Matos Date: Fri, 10 Apr 2026 18:46:54 -0400 Subject: [PATCH 7/8] docs(readme): rename bearer token to personal access token --- README.md | 2 +- docs/README-es.md | 2 +- docs/README-pt_BR.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f9bd832..780f0cd 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ $works = $client->works([ #### Mutations -To execute mutations, provide a valid Thoth API bearer token to the client. +To execute mutations, provide a valid personal access token to the client. ```php $client->setToken($token); diff --git a/docs/README-es.md b/docs/README-es.md index 427addf..41bdd3f 100644 --- a/docs/README-es.md +++ b/docs/README-es.md @@ -67,7 +67,7 @@ $works = $client->works([ #### Mutaciones -Para ejecutar mutaciones, proporcione al cliente un token bearer valido de la API de Thoth. +Para ejecutar mutaciones, proporcione al cliente un personal access token valido. ```php $client->setToken($token); diff --git a/docs/README-pt_BR.md b/docs/README-pt_BR.md index 248edb2..b339d1b 100644 --- a/docs/README-pt_BR.md +++ b/docs/README-pt_BR.md @@ -67,7 +67,7 @@ $works = $client->works([ #### Mutações -Para executar mutações, forneça ao cliente um token bearer válido da API Thoth. +Para executar mutações, forneça ao cliente um personal access token válido. ```php $client->setToken($token); From 1a48ab034153277720730dc4725544b884d4df38 Mon Sep 17 00:00:00 2001 From: Thiago Matos Date: Fri, 10 Apr 2026 19:59:53 -0400 Subject: [PATCH 8/8] test(graphql): cover schema sync operations --- src/GraphQL/Client.php | 14 +- src/GraphQL/QueryProvider.php | 16 +- tests/GraphQL/ClientTest.php | 2 + .../Concerns/HasClientSchemaSyncTests.php | 402 ++++++++++++++++++ .../GraphQL/MutationBuilderSchemaSyncTest.php | 333 +++++++++++++++ tests/GraphQL/Queries/SchemaSyncQueryTest.php | 112 +++++ tests/GraphQL/QueryProviderSchemaSyncTest.php | 53 +++ 7 files changed, 929 insertions(+), 3 deletions(-) create mode 100644 tests/GraphQL/Concerns/HasClientSchemaSyncTests.php create mode 100644 tests/GraphQL/MutationBuilderSchemaSyncTest.php create mode 100644 tests/GraphQL/Queries/SchemaSyncQueryTest.php create mode 100644 tests/GraphQL/QueryProviderSchemaSyncTest.php diff --git a/src/GraphQL/Client.php b/src/GraphQL/Client.php index fbfe523..4599052 100644 --- a/src/GraphQL/Client.php +++ b/src/GraphQL/Client.php @@ -56,7 +56,7 @@ private function get(string $entityName, string $entityId, array $args = []): Ab private function getMany(string $entityName, array $args = []): array { $entityClass = $this->getModelClass($entityName); - $queryName = $entityName . ($entityName !== 'series' ? 's' : 'es'); + $queryName = $this->getPluralQueryName($entityName); $result = $this->query($queryName, $args); return array_map(fn ($data) => new $entityClass($data), $result[$queryName]); @@ -118,6 +118,18 @@ private function getIdentifierField(string $entityName): string } } + private function getPluralQueryName(string $entityName): string + { + switch ($entityName) { + case 'biography': + return 'biographies'; + case 'series': + return 'serieses'; + default: + return $entityName . 's'; + } + } + private function query(string $queryName, array $args = [], ?string $token = null): array { $query = QueryProvider::get($queryName); diff --git a/src/GraphQL/QueryProvider.php b/src/GraphQL/QueryProvider.php index d216078..8094f4a 100644 --- a/src/GraphQL/QueryProvider.php +++ b/src/GraphQL/QueryProvider.php @@ -87,7 +87,7 @@ private static function mapQuery(AbstractQuery $queryObject, string $name): arra { return [ $name => $queryObject->getQuery(), - $name . ($name !== 'series' ? 's' : 'es') => $queryObject->getManyQuery(), + self::getPluralQueryName($name) => $queryObject->getManyQuery(), $name . 'Count' => $queryObject->getCountQuery(), ]; } @@ -112,7 +112,19 @@ private static function mapMarkupQuery(AbstractQuery $queryObject, string $name) { return [ $name => $queryObject->getQuery(), - $name . 's' => $queryObject->getManyQuery(), + self::getPluralQueryName($name) => $queryObject->getManyQuery(), ]; } + + private static function getPluralQueryName(string $name): string + { + switch ($name) { + case 'biography': + return 'biographies'; + case 'series': + return 'serieses'; + default: + return $name . 's'; + } + } } diff --git a/tests/GraphQL/ClientTest.php b/tests/GraphQL/ClientTest.php index bff9975..0dd1951 100644 --- a/tests/GraphQL/ClientTest.php +++ b/tests/GraphQL/ClientTest.php @@ -9,11 +9,13 @@ use ThothApi\GraphQL\Client; use ThothApi\Tests\GraphQL\Concerns\HasClientMutationTests; use ThothApi\Tests\GraphQL\Concerns\HasClientQueryTests; +use ThothApi\Tests\GraphQL\Concerns\HasClientSchemaSyncTests; final class ClientTest extends TestCase { use HasClientMutationTests; use HasClientQueryTests; + use HasClientSchemaSyncTests; private MockHandler $mockHandler; diff --git a/tests/GraphQL/Concerns/HasClientSchemaSyncTests.php b/tests/GraphQL/Concerns/HasClientSchemaSyncTests.php new file mode 100644 index 0000000..7b22941 --- /dev/null +++ b/tests/GraphQL/Concerns/HasClientSchemaSyncTests.php @@ -0,0 +1,402 @@ + '9afc6760-f556-46a1-a912-39ea5ebc921b']); + $this->appendGraphQlResponse('additionalResource', ['workResourceId' => '9afc6760-f556-46a1-a912-39ea5ebc921b']); + + $result = $this->client->additionalResource('9afc6760-f556-46a1-a912-39ea5ebc921b'); + $this->assertEquals($expected, $result); + } + + public function testAdditionalResources(): void + { + $expected = [ + new AdditionalResource(['workResourceId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2']), + new AdditionalResource(['workResourceId' => '0472b0af-acf6-4f27-bee3-d3414466ccec']), + ]; + $this->appendGraphQlResponse('additionalResources', [ + ['workResourceId' => '7608e91a-7e51-467a-9bab-67d1eee68ab2'], + ['workResourceId' => '0472b0af-acf6-4f27-bee3-d3414466ccec'], + ]); + + $result = $this->client->additionalResources(); + $this->assertEquals($expected, $result); + } + + public function testAdditionalResourceCount(): void + { + $this->appendGraphQlResponse('additionalResourceCount', 12); + $this->assertSame(12, $this->client->additionalResourceCount()); + } + + public function testAbstract(): void + { + $expected = new AbstractText(['abstractId' => '7b256755-3546-49ad-8199-6e98d1a66792']); + $this->appendGraphQlResponse('abstract', ['abstractId' => '7b256755-3546-49ad-8199-6e98d1a66792']); + + $result = $this->client->abstract('7b256755-3546-49ad-8199-6e98d1a66792', 'HTML'); + $this->assertEquals($expected, $result); + } + + public function testAbstracts(): void + { + $expected = [ + new AbstractText(['abstractId' => 'c8cba422-728e-4e94-8f4d-b4c1ba8f7416']), + new AbstractText(['abstractId' => '0cf7d5c4-c8e0-4787-8130-f6b7133ec2f1']), + ]; + $this->appendGraphQlResponse('abstracts', [ + ['abstractId' => 'c8cba422-728e-4e94-8f4d-b4c1ba8f7416'], + ['abstractId' => '0cf7d5c4-c8e0-4787-8130-f6b7133ec2f1'], + ]); + + $result = $this->client->abstracts(); + $this->assertEquals($expected, $result); + } + + public function testAward(): void + { + $expected = new Award(['awardId' => '348f8f66-9bd5-43f5-beb7-f08a6656d1a2']); + $this->appendGraphQlResponse('award', ['awardId' => '348f8f66-9bd5-43f5-beb7-f08a6656d1a2']); + + $result = $this->client->award('348f8f66-9bd5-43f5-beb7-f08a6656d1a2'); + $this->assertEquals($expected, $result); + } + + public function testAwards(): void + { + $expected = [ + new Award(['awardId' => 'e9572168-7795-4a72-a139-ad1c0f1143af']), + new Award(['awardId' => '6b8b30aa-0ad8-4dab-b9f1-725cfaf2f804']), + ]; + $this->appendGraphQlResponse('awards', [ + ['awardId' => 'e9572168-7795-4a72-a139-ad1c0f1143af'], + ['awardId' => '6b8b30aa-0ad8-4dab-b9f1-725cfaf2f804'], + ]); + + $result = $this->client->awards(); + $this->assertEquals($expected, $result); + } + + public function testAwardCount(): void + { + $this->appendGraphQlResponse('awardCount', 5); + $this->assertSame(5, $this->client->awardCount()); + } + + public function testBiography(): void + { + $expected = new Biography(['biographyId' => '6d8ddf35-e112-48b2-87c6-3ef5888c03e7']); + $this->appendGraphQlResponse('biography', ['biographyId' => '6d8ddf35-e112-48b2-87c6-3ef5888c03e7']); + + $result = $this->client->biography('6d8ddf35-e112-48b2-87c6-3ef5888c03e7', 'HTML'); + $this->assertEquals($expected, $result); + } + + public function testBiographies(): void + { + $expected = [ + new Biography(['biographyId' => 'ed51ceb4-d77e-4f6e-bf1a-8277c1f5f0df']), + new Biography(['biographyId' => '2d8a97c3-6b6e-440f-9c6e-b8c5ee5bf1cb']), + ]; + $this->appendGraphQlResponse('biographies', [ + ['biographyId' => 'ed51ceb4-d77e-4f6e-bf1a-8277c1f5f0df'], + ['biographyId' => '2d8a97c3-6b6e-440f-9c6e-b8c5ee5bf1cb'], + ]); + + $result = $this->client->biographies(); + $this->assertEquals($expected, $result); + } + + public function testBookReview(): void + { + $expected = new BookReview(['bookReviewId' => 'a465c5d1-5ef0-493c-b2b3-a8084144f35c']); + $this->appendGraphQlResponse('bookReview', ['bookReviewId' => 'a465c5d1-5ef0-493c-b2b3-a8084144f35c']); + + $result = $this->client->bookReview('a465c5d1-5ef0-493c-b2b3-a8084144f35c'); + $this->assertEquals($expected, $result); + } + + public function testBookReviews(): void + { + $expected = [ + new BookReview(['bookReviewId' => '728d3048-b0db-444e-bd46-26ab6b66e7cf']), + new BookReview(['bookReviewId' => '83b8dfe7-8394-49f1-b5f0-c833e86d9d5b']), + ]; + $this->appendGraphQlResponse('bookReviews', [ + ['bookReviewId' => '728d3048-b0db-444e-bd46-26ab6b66e7cf'], + ['bookReviewId' => '83b8dfe7-8394-49f1-b5f0-c833e86d9d5b'], + ]); + + $result = $this->client->bookReviews(); + $this->assertEquals($expected, $result); + } + + public function testBookReviewCount(): void + { + $this->appendGraphQlResponse('bookReviewCount', 8); + $this->assertSame(8, $this->client->bookReviewCount()); + } + + public function testContact(): void + { + $expected = new Contact(['contactId' => 'd4122dc0-f3fc-45ce-81a4-fe45e8da837b']); + $this->appendGraphQlResponse('contact', ['contactId' => 'd4122dc0-f3fc-45ce-81a4-fe45e8da837b']); + + $result = $this->client->contact('d4122dc0-f3fc-45ce-81a4-fe45e8da837b'); + $this->assertEquals($expected, $result); + } + + public function testContacts(): void + { + $expected = [ + new Contact(['contactId' => 'f74cc2d0-4888-4629-a31b-ac8527d4f374']), + new Contact(['contactId' => '67c2ab2c-e1c5-452a-8bb4-7fd3bf7f2394']), + ]; + $this->appendGraphQlResponse('contacts', [ + ['contactId' => 'f74cc2d0-4888-4629-a31b-ac8527d4f374'], + ['contactId' => '67c2ab2c-e1c5-452a-8bb4-7fd3bf7f2394'], + ]); + + $result = $this->client->contacts(); + $this->assertEquals($expected, $result); + } + + public function testContactCount(): void + { + $this->appendGraphQlResponse('contactCount', 4); + $this->assertSame(4, $this->client->contactCount()); + } + + public function testEndorsement(): void + { + $expected = new Endorsement(['endorsementId' => '0b13c4ca-6db2-4f4a-ad98-784ec0f5f8f6']); + $this->appendGraphQlResponse('endorsement', ['endorsementId' => '0b13c4ca-6db2-4f4a-ad98-784ec0f5f8f6']); + + $result = $this->client->endorsement('0b13c4ca-6db2-4f4a-ad98-784ec0f5f8f6'); + $this->assertEquals($expected, $result); + } + + public function testEndorsements(): void + { + $expected = [ + new Endorsement(['endorsementId' => '1bb5729c-2fb1-4e0b-b9eb-d78c646c2048']), + new Endorsement(['endorsementId' => 'f2248af2-4650-4f4b-b5e7-b702a05629a7']), + ]; + $this->appendGraphQlResponse('endorsements', [ + ['endorsementId' => '1bb5729c-2fb1-4e0b-b9eb-d78c646c2048'], + ['endorsementId' => 'f2248af2-4650-4f4b-b5e7-b702a05629a7'], + ]); + + $result = $this->client->endorsements(); + $this->assertEquals($expected, $result); + } + + public function testEndorsementCount(): void + { + $this->appendGraphQlResponse('endorsementCount', 7); + $this->assertSame(7, $this->client->endorsementCount()); + } + + public function testFile(): void + { + $expected = new File(['fileId' => '0a2cde56-a535-4f7a-ac6b-3fc12942d1c9']); + $this->appendGraphQlResponse('file', ['fileId' => '0a2cde56-a535-4f7a-ac6b-3fc12942d1c9']); + + $result = $this->client->file('0a2cde56-a535-4f7a-ac6b-3fc12942d1c9'); + $this->assertEquals($expected, $result); + } + + public function testMe(): void + { + $expected = new Me(['userId' => '3a3d425f-35ed-49fd-a0f9-4b13d68ab71b']); + $this->appendGraphQlResponse('me', ['userId' => '3a3d425f-35ed-49fd-a0f9-4b13d68ab71b']); + + $result = $this->client->setToken('token')->me(); + $this->assertEquals($expected, $result); + } + + public function testTitle(): void + { + $expected = new Title(['titleId' => '11595f9d-536e-422a-8184-4b01df1158f5']); + $this->appendGraphQlResponse('title', ['titleId' => '11595f9d-536e-422a-8184-4b01df1158f5']); + + $result = $this->client->title('11595f9d-536e-422a-8184-4b01df1158f5', 'HTML'); + $this->assertEquals($expected, $result); + } + + public function testTitles(): void + { + $expected = [ + new Title(['titleId' => '194fb8a9-ec22-414d-a4ce-a2216755b5b0']), + new Title(['titleId' => '204291c6-6ecb-4b9b-b61d-c789336f281d']), + ]; + $this->appendGraphQlResponse('titles', [ + ['titleId' => '194fb8a9-ec22-414d-a4ce-a2216755b5b0'], + ['titleId' => '204291c6-6ecb-4b9b-b61d-c789336f281d'], + ]); + + $result = $this->client->titles(); + $this->assertEquals($expected, $result); + } + + public function testWorkFeaturedVideo(): void + { + $expected = new WorkFeaturedVideo(['workFeaturedVideoId' => 'ce185b34-0678-4332-b805-271db0feec4c']); + $this->appendGraphQlResponse('workFeaturedVideo', ['workFeaturedVideoId' => 'ce185b34-0678-4332-b805-271db0feec4c']); + + $result = $this->client->workFeaturedVideo('ce185b34-0678-4332-b805-271db0feec4c'); + $this->assertEquals($expected, $result); + } + + public function testWorkFeaturedVideos(): void + { + $expected = [ + new WorkFeaturedVideo(['workFeaturedVideoId' => 'b44e6137-bd54-46d3-a5de-d377ef205022']), + new WorkFeaturedVideo(['workFeaturedVideoId' => 'd865ba29-1f2c-42b8-b6c0-35f96a86091a']), + ]; + $this->appendGraphQlResponse('workFeaturedVideos', [ + ['workFeaturedVideoId' => 'b44e6137-bd54-46d3-a5de-d377ef205022'], + ['workFeaturedVideoId' => 'd865ba29-1f2c-42b8-b6c0-35f96a86091a'], + ]); + + $result = $this->client->workFeaturedVideos(); + $this->assertEquals($expected, $result); + } + + public function testWorkFeaturedVideoCount(): void + { + $this->appendGraphQlResponse('workFeaturedVideoCount', 2); + $this->assertSame(2, $this->client->workFeaturedVideoCount()); + } + + public function testAdditionalSchemaMutations(): void + { + $cases = [ + ['createAdditionalResource', new AdditionalResource(), 'createAdditionalResource', 'workResourceId'], + ['updateAdditionalResource', new AdditionalResource(), 'updateAdditionalResource', 'workResourceId'], + ['deleteAdditionalResource', '6df7310c-8d9e-4b25-afb9-3ef670051c5a', 'deleteAdditionalResource', 'workResourceId'], + ['createAbstract', new AbstractText(), 'createAbstract', 'abstractId'], + ['updateAbstract', new AbstractText(), 'updateAbstract', 'abstractId'], + ['deleteAbstract', 'c17f97cd-6c31-4e25-a870-9df7559c61ad', 'deleteAbstract', 'abstractId'], + ['createAward', new Award(), 'createAward', 'awardId'], + ['updateAward', new Award(), 'updateAward', 'awardId'], + ['deleteAward', '1da2c824-1cdd-4a20-8d18-979743f2576d', 'deleteAward', 'awardId'], + ['createBiography', new Biography(), 'createBiography', 'biographyId'], + ['updateBiography', new Biography(), 'updateBiography', 'biographyId'], + ['deleteBiography', '403d31d1-8e7a-4b36-a3d2-72cdc4f9d2a4', 'deleteBiography', 'biographyId'], + ['createBookReview', new BookReview(), 'createBookReview', 'bookReviewId'], + ['updateBookReview', new BookReview(), 'updateBookReview', 'bookReviewId'], + ['deleteBookReview', '5db50f30-9783-4ff6-9c85-521662fdd1d2', 'deleteBookReview', 'bookReviewId'], + ['createContact', new Contact(), 'createContact', 'contactId'], + ['updateContact', new Contact(), 'updateContact', 'contactId'], + ['deleteContact', '52e6f1dd-2811-497a-a0fd-7fdc439c0ab4', 'deleteContact', 'contactId'], + ['createEndorsement', new Endorsement(), 'createEndorsement', 'endorsementId'], + ['updateEndorsement', new Endorsement(), 'updateEndorsement', 'endorsementId'], + ['deleteEndorsement', 'a2d18be6-b877-4b68-b6e9-bf1c0b74d89c', 'deleteEndorsement', 'endorsementId'], + ['createTitle', new Title(), 'createTitle', 'titleId'], + ['updateTitle', new Title(), 'updateTitle', 'titleId'], + ['deleteTitle', '2581af59-2c28-4576-a823-cd90cacf9f7f', 'deleteTitle', 'titleId'], + ['createWorkFeaturedVideo', new WorkFeaturedVideo(), 'createWorkFeaturedVideo', 'workFeaturedVideoId'], + ['updateWorkFeaturedVideo', new WorkFeaturedVideo(), 'updateWorkFeaturedVideo', 'workFeaturedVideoId'], + ['deleteWorkFeaturedVideo', 'e3733ec2-2bc2-456b-af8c-43a83df87f5d', 'deleteWorkFeaturedVideo', 'workFeaturedVideoId'], + ]; + + foreach ($cases as $case) { + $this->appendGraphQlResponse($case[2], [$case[3] => '5d065ca7-e93d-4830-a94c-0b18cac0d738']); + $result = is_string($case[1]) + ? $this->client->{$case[0]}($case[1]) + : $this->client->{$case[0]}($case[1]); + + $this->assertSame('5d065ca7-e93d-4830-a94c-0b18cac0d738', $result); + } + } + + public function testMoveMutations(): void + { + $cases = [ + ['moveAffiliation', 'moveAffiliation', 'affiliationId'], + ['moveContribution', 'moveContribution', 'contributionId'], + ['moveIssue', 'moveIssue', 'issueId'], + ['moveReference', 'moveReference', 'referenceId'], + ['moveAdditionalResource', 'moveAdditionalResource', 'workResourceId'], + ['moveAward', 'moveAward', 'awardId'], + ['moveEndorsement', 'moveEndorsement', 'endorsementId'], + ['moveBookReview', 'moveBookReview', 'bookReviewId'], + ['moveSubject', 'moveSubject', 'subjectId'], + ['moveWorkRelation', 'moveWorkRelation', 'workRelationId'], + ]; + + foreach ($cases as $case) { + $this->appendGraphQlResponse($case[1], [$case[2] => 'a6ef3310-3f0a-4814-b66f-75c0a0850ed1']); + $result = $this->client->{$case[0]}('8ad22885-ea80-4bfc-b562-a4e3f8c9fe25', 2); + $this->assertSame('a6ef3310-3f0a-4814-b66f-75c0a0850ed1', $result); + } + } + + public function testFileUploadMutations(): void + { + $payload = [ + 'declaredMimeType' => 'application/pdf', + 'declaredExtension' => 'pdf', + 'declaredSha256' => 'abc123', + ]; + + $this->appendGraphQlResponse('initPublicationFileUpload', ['fileUploadId' => '805f6199-48e8-4c30-aeec-7c4bcc6cf515']); + $this->assertEquals( + new FileUploadResponse(['fileUploadId' => '805f6199-48e8-4c30-aeec-7c4bcc6cf515']), + $this->client->initPublicationFileUpload(['publicationId' => '22851a6f-b1b8-4631-90b4-fcf70dce8472'] + $payload) + ); + + $this->appendGraphQlResponse('initFrontcoverFileUpload', ['fileUploadId' => '33ea7c51-54e4-4e77-a9e2-666aeb277cfa']); + $this->assertEquals( + new FileUploadResponse(['fileUploadId' => '33ea7c51-54e4-4e77-a9e2-666aeb277cfa']), + $this->client->initFrontcoverFileUpload(['workId' => 'f3505088-fb35-4c64-9b64-0cdd4964d3db'] + $payload) + ); + + $this->appendGraphQlResponse('initAdditionalResourceFileUpload', ['fileUploadId' => '63f8edbf-3e4d-44fe-b83d-725fdb7152f4']); + $this->assertEquals( + new FileUploadResponse(['fileUploadId' => '63f8edbf-3e4d-44fe-b83d-725fdb7152f4']), + $this->client->initAdditionalResourceFileUpload(['additionalResourceId' => '4fadb13b-fda1-4ce1-aa17-cf1902652f66'] + $payload) + ); + + $this->appendGraphQlResponse('initWorkFeaturedVideoFileUpload', ['fileUploadId' => '2897df20-c90f-4a0e-a81d-7b0557d7fd07']); + $this->assertEquals( + new FileUploadResponse(['fileUploadId' => '2897df20-c90f-4a0e-a81d-7b0557d7fd07']), + $this->client->initWorkFeaturedVideoFileUpload(['workFeaturedVideoId' => '2b554c7f-0c1d-49c6-8a4f-d9638a115bea'] + $payload) + ); + + $this->appendGraphQlResponse('completeFileUpload', ['fileId' => 'c0b70667-9a9a-4829-9b29-f4792c53c702']); + $this->assertEquals( + new File(['fileId' => 'c0b70667-9a9a-4829-9b29-f4792c53c702']), + $this->client->completeFileUpload(['fileUploadId' => '2897df20-c90f-4a0e-a81d-7b0557d7fd07']) + ); + } + + private function appendGraphQlResponse(string $field, $data): void + { + $this->mockHandler->append(new Response(200, [], json_encode([ + 'data' => [ + $field => $data, + ], + ]))); + } +} diff --git a/tests/GraphQL/MutationBuilderSchemaSyncTest.php b/tests/GraphQL/MutationBuilderSchemaSyncTest.php new file mode 100644 index 0000000..a3078ce --- /dev/null +++ b/tests/GraphQL/MutationBuilderSchemaSyncTest.php @@ -0,0 +1,333 @@ +assertMutation( + 'createAdditionalResource', + 'workId: "c53fa7ab-0ae0-44fd-ad28-1d5b8a5e3859", title: "Resource title", description: "Resource description", attribution: "John Doe", resourceType: OTHER, doi: "https:\/\/doi.org\/10.00000\/00000000", handle: "https:\/\/hdl.handle.net\/123", url: "https:\/\/example.com", date: "2026-04-10", resourceOrdinal: 2', + 'workResourceId', + [ + 'workId' => 'c53fa7ab-0ae0-44fd-ad28-1d5b8a5e3859', + 'title' => 'Resource title', + 'description' => 'Resource description', + 'attribution' => 'John Doe', + 'resourceType' => 'OTHER', + 'doi' => 'https://doi.org/10.00000/00000000', + 'handle' => 'https://hdl.handle.net/123', + 'url' => 'https://example.com', + 'date' => '2026-04-10', + 'resourceOrdinal' => 2, + ], + 'markupFormat: HTML', + true, + ['markupFormat' => 'HTML'] + ); + + $this->assertMutation( + 'updateAdditionalResource', + 'additionalResourceId: "6f02b20c-e94e-46ff-a3f7-87f9e20bf9fd", workId: "c53fa7ab-0ae0-44fd-ad28-1d5b8a5e3859", title: "Resource title", description: "Resource description", attribution: "John Doe", resourceType: OTHER, doi: "https:\/\/doi.org\/10.00000\/00000000", handle: "https:\/\/hdl.handle.net\/123", url: "https:\/\/example.com", date: "2026-04-10", resourceOrdinal: 2', + 'workResourceId', + [ + 'additionalResourceId' => '6f02b20c-e94e-46ff-a3f7-87f9e20bf9fd', + 'workId' => 'c53fa7ab-0ae0-44fd-ad28-1d5b8a5e3859', + 'title' => 'Resource title', + 'description' => 'Resource description', + 'attribution' => 'John Doe', + 'resourceType' => 'OTHER', + 'doi' => 'https://doi.org/10.00000/00000000', + 'handle' => 'https://hdl.handle.net/123', + 'url' => 'https://example.com', + 'date' => '2026-04-10', + 'resourceOrdinal' => 2, + ], + 'markupFormat: HTML', + true, + ['markupFormat' => 'HTML'] + ); + + $this->assertMutation( + 'deleteAdditionalResource', + 'additionalResourceId: "6f02b20c-e94e-46ff-a3f7-87f9e20bf9fd"', + 'workResourceId', + ['additionalResourceId' => '6f02b20c-e94e-46ff-a3f7-87f9e20bf9fd'], + '', + false + ); + } + + public function testBuildMarkupMutations(): void + { + $this->assertMutation( + 'createAbstract', + 'workId: "b0a17dad-4ef0-4429-89e4-a3ddd9c4f72a", content: "Abstract text", localeCode: EN_GB, abstractType: LONG, canonical: true', + 'abstractId', + [ + 'workId' => 'b0a17dad-4ef0-4429-89e4-a3ddd9c4f72a', + 'content' => 'Abstract text', + 'localeCode' => 'EN_GB', + 'abstractType' => 'LONG', + 'canonical' => true, + ], + 'markupFormat: HTML', + true, + ['markupFormat' => 'HTML'] + ); + + $this->assertMutation( + 'createAward', + 'workId: "b0a17dad-4ef0-4429-89e4-a3ddd9c4f72a", title: "Award title", url: "https:\/\/example.com\/award", category: "Prize", year: 2026, jury: "Jury", country: GB, prizeStatement: "Winner", role: AUTHOR, awardOrdinal: 1', + 'awardId', + [ + 'workId' => 'b0a17dad-4ef0-4429-89e4-a3ddd9c4f72a', + 'title' => 'Award title', + 'url' => 'https://example.com/award', + 'category' => 'Prize', + 'year' => 2026, + 'jury' => 'Jury', + 'country' => 'GB', + 'prizeStatement' => 'Winner', + 'role' => 'AUTHOR', + 'awardOrdinal' => 1, + ], + 'markupFormat: HTML', + true, + ['markupFormat' => 'HTML'] + ); + + $this->assertMutation( + 'createBiography', + 'contributionId: "7b865707-f8ec-4c14-a580-f4a9767f2dd5", content: "Biography text", canonical: true, localeCode: EN_GB', + 'biographyId', + [ + 'contributionId' => '7b865707-f8ec-4c14-a580-f4a9767f2dd5', + 'content' => 'Biography text', + 'canonical' => true, + 'localeCode' => 'EN_GB', + ], + 'markupFormat: HTML', + true, + ['markupFormat' => 'HTML'] + ); + + $this->assertMutation( + 'createBookReview', + 'workId: "b0a17dad-4ef0-4429-89e4-a3ddd9c4f72a", title: "Review title", authorName: "John Doe", reviewerOrcid: "https:\/\/orcid.org\/0000-0000-0000-0000", reviewerInstitutionId: "77af8f4c-0ea0-44de-bbfa-c68cc2fc60fb", url: "https:\/\/example.com\/review", doi: "https:\/\/doi.org\/10.00000\/11111111", reviewDate: "2026-04-10", journalName: "Journal", journalVolume: "4", journalNumber: "2", journalIssn: "1234-5678", pageRange: "10-12", text: "Review text", reviewOrdinal: 3', + 'bookReviewId', + [ + 'workId' => 'b0a17dad-4ef0-4429-89e4-a3ddd9c4f72a', + 'title' => 'Review title', + 'authorName' => 'John Doe', + 'reviewerOrcid' => 'https://orcid.org/0000-0000-0000-0000', + 'reviewerInstitutionId' => '77af8f4c-0ea0-44de-bbfa-c68cc2fc60fb', + 'url' => 'https://example.com/review', + 'doi' => 'https://doi.org/10.00000/11111111', + 'reviewDate' => '2026-04-10', + 'journalName' => 'Journal', + 'journalVolume' => '4', + 'journalNumber' => '2', + 'journalIssn' => '1234-5678', + 'pageRange' => '10-12', + 'text' => 'Review text', + 'reviewOrdinal' => 3, + ], + 'markupFormat: HTML', + true, + ['markupFormat' => 'HTML'] + ); + + $this->assertMutation( + 'createEndorsement', + 'workId: "b0a17dad-4ef0-4429-89e4-a3ddd9c4f72a", authorName: "Jane Doe", authorRole: "Editor", authorOrcid: "https:\/\/orcid.org\/0000-0000-0000-0001", authorInstitutionId: "77af8f4c-0ea0-44de-bbfa-c68cc2fc60fb", url: "https:\/\/example.com\/endorsement", text: "Endorsement text", endorsementOrdinal: 1', + 'endorsementId', + [ + 'workId' => 'b0a17dad-4ef0-4429-89e4-a3ddd9c4f72a', + 'authorName' => 'Jane Doe', + 'authorRole' => 'Editor', + 'authorOrcid' => 'https://orcid.org/0000-0000-0000-0001', + 'authorInstitutionId' => '77af8f4c-0ea0-44de-bbfa-c68cc2fc60fb', + 'url' => 'https://example.com/endorsement', + 'text' => 'Endorsement text', + 'endorsementOrdinal' => 1, + ], + 'markupFormat: HTML', + true, + ['markupFormat' => 'HTML'] + ); + + $this->assertMutation( + 'createTitle', + 'workId: "b0a17dad-4ef0-4429-89e4-a3ddd9c4f72a", localeCode: EN_GB, fullTitle: "Full title", title: "Title", subtitle: "Subtitle", canonical: true', + 'titleId', + [ + 'workId' => 'b0a17dad-4ef0-4429-89e4-a3ddd9c4f72a', + 'localeCode' => 'EN_GB', + 'fullTitle' => 'Full title', + 'title' => 'Title', + 'subtitle' => 'Subtitle', + 'canonical' => true, + ], + 'markupFormat: HTML', + true, + ['markupFormat' => 'HTML'] + ); + } + + public function testBuildContactAndFeaturedVideoMutations(): void + { + $this->assertMutation( + 'createContact', + 'publisherId: "f70cac7c-b6c2-4af6-833b-910bb8bb1741", contactType: SUPPORT, email: "support@example.com"', + 'contactId', + [ + 'publisherId' => 'f70cac7c-b6c2-4af6-833b-910bb8bb1741', + 'contactType' => 'SUPPORT', + 'email' => 'support@example.com', + ] + ); + + $this->assertMutation( + 'updateContact', + 'contactId: "d83d440f-190f-4695-b752-3080c5d4ea40", publisherId: "f70cac7c-b6c2-4af6-833b-910bb8bb1741", contactType: SUPPORT, email: "support@example.com"', + 'contactId', + [ + 'contactId' => 'd83d440f-190f-4695-b752-3080c5d4ea40', + 'publisherId' => 'f70cac7c-b6c2-4af6-833b-910bb8bb1741', + 'contactType' => 'SUPPORT', + 'email' => 'support@example.com', + ] + ); + + $this->assertMutation( + 'deleteContact', + 'contactId: "d83d440f-190f-4695-b752-3080c5d4ea40"', + 'contactId', + ['contactId' => 'd83d440f-190f-4695-b752-3080c5d4ea40'], + '', + false + ); + + $this->assertMutation( + 'createWorkFeaturedVideo', + 'workId: "b0a17dad-4ef0-4429-89e4-a3ddd9c4f72a", title: "Featured video", url: "https:\/\/example.com\/video", width: 1920, height: 1080', + 'workFeaturedVideoId', + [ + 'workId' => 'b0a17dad-4ef0-4429-89e4-a3ddd9c4f72a', + 'title' => 'Featured video', + 'url' => 'https://example.com/video', + 'width' => 1920, + 'height' => 1080, + ] + ); + } + + public function testBuildMoveMutations(): void + { + $cases = [ + ['moveAffiliation', 'affiliationId', 'affiliationId'], + ['moveContribution', 'contributionId', 'contributionId'], + ['moveIssue', 'issueId', 'issueId'], + ['moveReference', 'referenceId', 'referenceId'], + ['moveAdditionalResource', 'additionalResourceId', 'workResourceId'], + ['moveAward', 'awardId', 'awardId'], + ['moveEndorsement', 'endorsementId', 'endorsementId'], + ['moveBookReview', 'bookReviewId', 'bookReviewId'], + ['moveSubject', 'subjectId', 'subjectId'], + ['moveWorkRelation', 'workRelationId', 'workRelationId'], + ]; + + foreach ($cases as $case) { + $this->assertMutation( + $case[0], + $case[1] . ': "6b4060ff-a89b-4bdc-b722-2b87ef9d057a", newOrdinal: 4', + $case[2], + [ + $case[1] => '6b4060ff-a89b-4bdc-b722-2b87ef9d057a', + 'newOrdinal' => 4, + ], + '', + false + ); + } + } + + public function testBuildUploadMutations(): void + { + $common = [ + 'declaredMimeType' => 'application/pdf', + 'declaredExtension' => 'pdf', + 'declaredSha256' => 'abc123', + ]; + + $this->assertMutation( + 'initPublicationFileUpload', + 'publicationId: "f70cac7c-b6c2-4af6-833b-910bb8bb1741", declaredMimeType: "application\/pdf", declaredExtension: "pdf", declaredSha256: "abc123"', + 'fileUploadId', + ['publicationId' => 'f70cac7c-b6c2-4af6-833b-910bb8bb1741'] + $common + ); + + $this->assertMutation( + 'initFrontcoverFileUpload', + 'workId: "f70cac7c-b6c2-4af6-833b-910bb8bb1741", declaredMimeType: "application\/pdf", declaredExtension: "pdf", declaredSha256: "abc123"', + 'fileUploadId', + ['workId' => 'f70cac7c-b6c2-4af6-833b-910bb8bb1741'] + $common + ); + + $this->assertMutation( + 'initAdditionalResourceFileUpload', + 'additionalResourceId: "f70cac7c-b6c2-4af6-833b-910bb8bb1741", declaredMimeType: "application\/pdf", declaredExtension: "pdf", declaredSha256: "abc123"', + 'fileUploadId', + ['additionalResourceId' => 'f70cac7c-b6c2-4af6-833b-910bb8bb1741'] + $common + ); + + $this->assertMutation( + 'initWorkFeaturedVideoFileUpload', + 'workFeaturedVideoId: "f70cac7c-b6c2-4af6-833b-910bb8bb1741", declaredMimeType: "application\/pdf", declaredExtension: "pdf", declaredSha256: "abc123"', + 'fileUploadId', + ['workFeaturedVideoId' => 'f70cac7c-b6c2-4af6-833b-910bb8bb1741'] + $common + ); + + $this->assertMutation( + 'completeFileUpload', + 'fileUploadId: "f70cac7c-b6c2-4af6-833b-910bb8bb1741"', + 'fileId', + ['fileUploadId' => 'f70cac7c-b6c2-4af6-833b-910bb8bb1741'] + ); + } + + private function assertMutation( + string $mutationName, + string $data, + string $returnValue, + array $input, + string $extraArgs = '', + bool $nested = true, + array $extraInput = [] + ): void { + $args = [$nested ? 'data: {' . $data . '}' : $data]; + if ($extraArgs !== '') { + $args[] = $extraArgs; + } + + $expectedMutation = <<assertSame($expectedMutation, $mutation); + } +} diff --git a/tests/GraphQL/Queries/SchemaSyncQueryTest.php b/tests/GraphQL/Queries/SchemaSyncQueryTest.php new file mode 100644 index 0000000..7293e95 --- /dev/null +++ b/tests/GraphQL/Queries/SchemaSyncQueryTest.php @@ -0,0 +1,112 @@ +assertStringContainsString('additionalResource(additionalResourceId:', $query->getQuery()); + $this->assertStringContainsString('additionalResources(', $query->getManyQuery()); + $this->assertStringContainsString('additionalResourceCount', $query->getCountQuery()); + $this->assertStringContainsString('fragment additionalResourceFields on WorkResource', $query->getQuery()); + } + + public function testAbstractQueries(): void + { + $query = new AbstractTextQuery(); + $this->assertStringContainsString('abstract(abstractId:', $query->getQuery()); + $this->assertStringContainsString('markupFormat: $markupFormat', $query->getQuery()); + $this->assertStringContainsString('abstracts(', $query->getManyQuery()); + $this->assertStringContainsString('fragment abstractFields on Abstract', $query->getManyQuery()); + } + + public function testAwardQueries(): void + { + $query = new AwardQuery(); + $this->assertStringContainsString('award(awardId:', $query->getQuery()); + $this->assertStringContainsString('awards(', $query->getManyQuery()); + $this->assertStringContainsString('awardCount', $query->getCountQuery()); + $this->assertStringContainsString('fragment awardFields on Award', $query->getQuery()); + } + + public function testBiographyQueries(): void + { + $query = new BiographyQuery(); + $this->assertStringContainsString('biography(biographyId:', $query->getQuery()); + $this->assertStringContainsString('biographies(', $query->getManyQuery()); + $this->assertStringContainsString('fragment biographyFields on Biography', $query->getQuery()); + } + + public function testBookReviewQueries(): void + { + $query = new BookReviewQuery(); + $this->assertStringContainsString('bookReview(bookReviewId:', $query->getQuery()); + $this->assertStringContainsString('bookReviews(', $query->getManyQuery()); + $this->assertStringContainsString('bookReviewCount', $query->getCountQuery()); + $this->assertStringContainsString('fragment bookReviewFields on BookReview', $query->getQuery()); + } + + public function testContactQueries(): void + { + $query = new ContactQuery(); + $this->assertStringContainsString('contact(contactId:', $query->getQuery()); + $this->assertStringContainsString('contacts(', $query->getManyQuery()); + $this->assertStringContainsString('contactCount(contactTypes:', $query->getCountQuery()); + $this->assertStringContainsString('fragment contactFields on Contact', $query->getQuery()); + } + + public function testEndorsementQueries(): void + { + $query = new EndorsementQuery(); + $this->assertStringContainsString('endorsement(endorsementId:', $query->getQuery()); + $this->assertStringContainsString('endorsements(', $query->getManyQuery()); + $this->assertStringContainsString('endorsementCount', $query->getCountQuery()); + $this->assertStringContainsString('fragment endorsementFields on Endorsement', $query->getQuery()); + } + + public function testFileQuery(): void + { + $query = new FileQuery(); + $this->assertStringContainsString('file(fileId:', $query->getQuery()); + $this->assertStringContainsString('fragment fileFields on File', $query->getQuery()); + } + + public function testMeQuery(): void + { + $query = new MeQuery(); + $this->assertStringContainsString('me {', $query->getQuery()); + $this->assertStringContainsString('fragment meFields on Me', $query->getQuery()); + } + + public function testTitleQueries(): void + { + $query = new TitleQuery(); + $this->assertStringContainsString('title(titleId:', $query->getQuery()); + $this->assertStringContainsString('titles(', $query->getManyQuery()); + $this->assertStringContainsString('fragment titleFields on Title', $query->getQuery()); + } + + public function testWorkFeaturedVideoQueries(): void + { + $query = new WorkFeaturedVideoQuery(); + $this->assertStringContainsString('workFeaturedVideo(workFeaturedVideoId:', $query->getQuery()); + $this->assertStringContainsString('workFeaturedVideos(', $query->getManyQuery()); + $this->assertStringContainsString('workFeaturedVideoCount', $query->getCountQuery()); + $this->assertStringContainsString('fragment workFeaturedVideoFields on WorkFeaturedVideo', $query->getQuery()); + } +} diff --git a/tests/GraphQL/QueryProviderSchemaSyncTest.php b/tests/GraphQL/QueryProviderSchemaSyncTest.php new file mode 100644 index 0000000..7a3be31 --- /dev/null +++ b/tests/GraphQL/QueryProviderSchemaSyncTest.php @@ -0,0 +1,53 @@ +assertStringContainsString($queryName, $query); + } + } + + public function testGetAdditionalSchemaQueries(): void + { + foreach ([ + 'additionalResource', + 'additionalResources', + 'additionalResourceCount', + 'award', + 'awards', + 'awardCount', + 'bookReview', + 'bookReviews', + 'bookReviewCount', + 'contact', + 'contacts', + 'contactCount', + 'endorsement', + 'endorsements', + 'endorsementCount', + 'workFeaturedVideo', + 'workFeaturedVideos', + 'workFeaturedVideoCount', + ] as $queryName) { + $query = QueryProvider::get($queryName); + $this->assertStringContainsString($queryName, $query); + } + } + + public function testGetStandaloneQueries(): void + { + $query = QueryProvider::get('file'); + $this->assertStringContainsString('file(fileId:', $query); + + $query = QueryProvider::get('me'); + $this->assertStringContainsString('me {', $query); + } +}