Create and delete media items via GraphQL, see #28

This commit is contained in:
Timothy Warren 2020-08-05 13:30:24 -04:00
parent c132766486
commit c7beb76404
6 changed files with 74 additions and 25 deletions

View File

@ -43,6 +43,16 @@ final class ListItem extends AbstractListItem {
* @throws Throwable * @throws Throwable
*/ */
public function create(array $data): Request public function create(array $data): Request
{
return $this->requestBuilder->mutateRequest('CreateLibraryItem', [
'id' => $data['id'],
'status' => strtoupper($data['status']),
'type' => strtoupper($data['type']),
'userId' => $data['user_id'],
]);
}
public function createFull(array $data): Request
{ {
$body = [ $body = [
'data' => [ 'data' => [
@ -93,15 +103,9 @@ final class ListItem extends AbstractListItem {
*/ */
public function delete(string $id): Request public function delete(string $id): Request
{ {
$authHeader = $this->getAuthHeader(); return $this->requestBuilder->mutateRequest('DeleteLibraryItem', [
$request = $this->requestBuilder->newRequest('DELETE', "library-entries/{$id}"); 'id' => $id
]);
if ($authHeader !== NULL)
{
$request = $request->setHeader('Authorization', $authHeader);
}
return $request->getFullRequest();
} }
/** /**

View File

@ -0,0 +1,19 @@
# Create full library item
# Flesh out a library item with data - most commonly used for syncing lists
# between APIs
mutation (
$userId: ID!
$id: ID!,
$mediaType: media_type!,
$status: MediaListStatus,
) {
createLibraryEntry (input: {
userId: $userId
mediaId: $id
mediaType: $mediaType
status: $status
}) {
mediaId
status
}
}

View File

@ -0,0 +1,27 @@
# Create minimal library item
# This is the more common use case, when adding an anime or manga to
# the user's library.
mutation (
$userId: ID!
$id: ID!,
$type: media_type!,
$status: LibraryEntryStatus!,
) {
createLibraryEntry (input: {
userId: $userId
mediaId: $id
mediaType: $type
status: $status
}) {
libraryEntry {
id
media {
type
}
user {
id
}
status
}
}
}

View File

@ -0,0 +1,7 @@
mutation ($id: ID!) {
deleteLibraryEntry(input: {id: $id}) {
libraryEntry {
id
}
}
}

View File

@ -27,8 +27,9 @@ query ($slug: String!) {
character { character {
id id
names { names {
canonical
alternatives alternatives
canonical
localized
} }
image { image {
original { original {
@ -96,7 +97,9 @@ query ($slug: String!) {
subtype subtype
synopsis synopsis
titles { titles {
alternatives
canonical canonical
canonicalLocale
localized localized
} }
totalLength totalLength

View File

@ -27,8 +27,9 @@ query ($id: ID!) {
character { character {
id id
names { names {
canonical
alternatives alternatives
canonical
localized
} }
image { image {
original { original {
@ -54,20 +55,6 @@ query ($id: ID!) {
episodeCount episodeCount
episodeLength episodeLength
totalLength totalLength
posterImage {
original {
height
name
url
width
}
views {
height
name
url
width
}
}
season season
sfw sfw
slug slug
@ -110,7 +97,9 @@ query ($id: ID!) {
subtype subtype
synopsis synopsis
titles { titles {
alternatives
canonical canonical
canonicalLocale
localized localized
} }
totalLength totalLength