🐘 Massive refactor for graphql changes
This commit is contained in:
76
src/client/graphql/adapters/comicAdapter.ts
Normal file
76
src/client/graphql/adapters/comicAdapter.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { GetComicByIdQuery } from '../generated';
|
||||
|
||||
/**
|
||||
* Adapter to transform GraphQL Comic response to legacy REST API format
|
||||
* This allows gradual migration while maintaining compatibility with existing components
|
||||
*/
|
||||
export function adaptGraphQLComicToLegacy(graphqlComic: GetComicByIdQuery['comic']) {
|
||||
if (!graphqlComic) return null;
|
||||
|
||||
// Parse sourced metadata (GraphQL returns as strings)
|
||||
const comicvine = graphqlComic.sourcedMetadata?.comicvine
|
||||
? (typeof graphqlComic.sourcedMetadata.comicvine === 'string'
|
||||
? JSON.parse(graphqlComic.sourcedMetadata.comicvine)
|
||||
: graphqlComic.sourcedMetadata.comicvine)
|
||||
: undefined;
|
||||
|
||||
const comicInfo = graphqlComic.sourcedMetadata?.comicInfo
|
||||
? (typeof graphqlComic.sourcedMetadata.comicInfo === 'string'
|
||||
? JSON.parse(graphqlComic.sourcedMetadata.comicInfo)
|
||||
: graphqlComic.sourcedMetadata.comicInfo)
|
||||
: undefined;
|
||||
|
||||
const locg = graphqlComic.sourcedMetadata?.locg || undefined;
|
||||
|
||||
// Use inferredMetadata from GraphQL response, or build from canonical metadata as fallback
|
||||
const inferredMetadata = graphqlComic.inferredMetadata || {
|
||||
issue: {
|
||||
name: graphqlComic.canonicalMetadata?.title?.value ||
|
||||
graphqlComic.canonicalMetadata?.series?.value ||
|
||||
graphqlComic.rawFileDetails?.name || '',
|
||||
number: graphqlComic.canonicalMetadata?.issueNumber?.value
|
||||
? parseInt(graphqlComic.canonicalMetadata.issueNumber.value, 10)
|
||||
: undefined,
|
||||
year: graphqlComic.canonicalMetadata?.publicationDate?.value?.substring(0, 4) ||
|
||||
graphqlComic.canonicalMetadata?.coverDate?.value?.substring(0, 4),
|
||||
subtitle: graphqlComic.canonicalMetadata?.series?.value,
|
||||
},
|
||||
};
|
||||
|
||||
// Build acquisition data (if available from importStatus or other fields)
|
||||
const acquisition = {
|
||||
directconnect: {
|
||||
downloads: [],
|
||||
},
|
||||
torrent: [],
|
||||
};
|
||||
|
||||
// Transform rawFileDetails to match expected format
|
||||
const rawFileDetails = graphqlComic.rawFileDetails ? {
|
||||
name: graphqlComic.rawFileDetails.name || '',
|
||||
filePath: graphqlComic.rawFileDetails.filePath,
|
||||
fileSize: graphqlComic.rawFileDetails.fileSize,
|
||||
extension: graphqlComic.rawFileDetails.extension,
|
||||
mimeType: graphqlComic.rawFileDetails.mimeType,
|
||||
containedIn: graphqlComic.rawFileDetails.containedIn,
|
||||
pageCount: graphqlComic.rawFileDetails.pageCount,
|
||||
archive: graphqlComic.rawFileDetails.archive,
|
||||
cover: graphqlComic.rawFileDetails.cover,
|
||||
} : undefined;
|
||||
|
||||
return {
|
||||
_id: graphqlComic.id,
|
||||
rawFileDetails,
|
||||
inferredMetadata,
|
||||
sourcedMetadata: {
|
||||
comicvine,
|
||||
locg,
|
||||
comicInfo,
|
||||
},
|
||||
acquisition,
|
||||
createdAt: graphqlComic.createdAt || new Date().toISOString(),
|
||||
updatedAt: graphqlComic.updatedAt || new Date().toISOString(),
|
||||
// Include the full GraphQL data for components that can use it
|
||||
__graphql: graphqlComic,
|
||||
} as any; // Use 'as any' to bypass strict type checking during migration
|
||||
}
|
||||
19
src/client/graphql/client.ts
Normal file
19
src/client/graphql/client.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client';
|
||||
import { LIBRARY_SERVICE_HOST } from '../constants/endpoints';
|
||||
|
||||
const httpLink = new HttpLink({
|
||||
uri: `${LIBRARY_SERVICE_HOST}/graphql`,
|
||||
});
|
||||
|
||||
export const apolloClient = new ApolloClient({
|
||||
link: httpLink,
|
||||
cache: new InMemoryCache(),
|
||||
defaultOptions: {
|
||||
watchQuery: {
|
||||
fetchPolicy: 'cache-and-network',
|
||||
},
|
||||
query: {
|
||||
fetchPolicy: 'network-only',
|
||||
},
|
||||
},
|
||||
});
|
||||
43
src/client/graphql/fetcher.ts
Normal file
43
src/client/graphql/fetcher.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { LIBRARY_SERVICE_HOST } from '../constants/endpoints';
|
||||
|
||||
export function fetcher<TData, TVariables>(
|
||||
query: string,
|
||||
variables?: TVariables,
|
||||
options?: RequestInit['headers']
|
||||
) {
|
||||
return async (): Promise<TData> => {
|
||||
try {
|
||||
const res = await fetch(`${LIBRARY_SERVICE_HOST}/graphql`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...options,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
query,
|
||||
variables,
|
||||
}),
|
||||
});
|
||||
|
||||
// Check if the response is OK (status 200-299)
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP error! status: ${res.status}`);
|
||||
}
|
||||
|
||||
const json = await res.json();
|
||||
|
||||
if (json.errors) {
|
||||
const { message } = json.errors[0] || {};
|
||||
throw new Error(message || 'Error fetching data');
|
||||
}
|
||||
|
||||
return json.data;
|
||||
} catch (error) {
|
||||
// Handle network errors or other fetch failures
|
||||
if (error instanceof Error) {
|
||||
throw new Error(`Failed to fetch: ${error.message}`);
|
||||
}
|
||||
throw new Error('Failed to fetch data from server');
|
||||
}
|
||||
};
|
||||
}
|
||||
1848
src/client/graphql/generated.ts
Normal file
1848
src/client/graphql/generated.ts
Normal file
File diff suppressed because it is too large
Load Diff
191
src/client/graphql/queries/comicDetail.graphql
Normal file
191
src/client/graphql/queries/comicDetail.graphql
Normal file
@@ -0,0 +1,191 @@
|
||||
query GetComicById($id: ID!) {
|
||||
comic(id: $id) {
|
||||
id
|
||||
|
||||
# Inferred metadata
|
||||
inferredMetadata {
|
||||
issue {
|
||||
name
|
||||
number
|
||||
year
|
||||
subtitle
|
||||
}
|
||||
}
|
||||
|
||||
# Canonical metadata
|
||||
canonicalMetadata {
|
||||
title {
|
||||
value
|
||||
provenance {
|
||||
source
|
||||
sourceId
|
||||
confidence
|
||||
fetchedAt
|
||||
url
|
||||
}
|
||||
userOverride
|
||||
}
|
||||
series {
|
||||
value
|
||||
provenance {
|
||||
source
|
||||
sourceId
|
||||
confidence
|
||||
fetchedAt
|
||||
url
|
||||
}
|
||||
userOverride
|
||||
}
|
||||
volume {
|
||||
value
|
||||
provenance {
|
||||
source
|
||||
sourceId
|
||||
confidence
|
||||
fetchedAt
|
||||
url
|
||||
}
|
||||
userOverride
|
||||
}
|
||||
issueNumber {
|
||||
value
|
||||
provenance {
|
||||
source
|
||||
sourceId
|
||||
confidence
|
||||
fetchedAt
|
||||
url
|
||||
}
|
||||
userOverride
|
||||
}
|
||||
publisher {
|
||||
value
|
||||
provenance {
|
||||
source
|
||||
sourceId
|
||||
confidence
|
||||
fetchedAt
|
||||
url
|
||||
}
|
||||
userOverride
|
||||
}
|
||||
publicationDate {
|
||||
value
|
||||
provenance {
|
||||
source
|
||||
sourceId
|
||||
confidence
|
||||
fetchedAt
|
||||
url
|
||||
}
|
||||
userOverride
|
||||
}
|
||||
coverDate {
|
||||
value
|
||||
provenance {
|
||||
source
|
||||
sourceId
|
||||
confidence
|
||||
fetchedAt
|
||||
url
|
||||
}
|
||||
userOverride
|
||||
}
|
||||
description {
|
||||
value
|
||||
provenance {
|
||||
source
|
||||
sourceId
|
||||
confidence
|
||||
fetchedAt
|
||||
url
|
||||
}
|
||||
userOverride
|
||||
}
|
||||
creators {
|
||||
name
|
||||
role
|
||||
provenance {
|
||||
source
|
||||
sourceId
|
||||
confidence
|
||||
fetchedAt
|
||||
url
|
||||
}
|
||||
}
|
||||
pageCount {
|
||||
value
|
||||
provenance {
|
||||
source
|
||||
sourceId
|
||||
confidence
|
||||
fetchedAt
|
||||
url
|
||||
}
|
||||
userOverride
|
||||
}
|
||||
coverImage {
|
||||
value
|
||||
provenance {
|
||||
source
|
||||
sourceId
|
||||
confidence
|
||||
fetchedAt
|
||||
url
|
||||
}
|
||||
userOverride
|
||||
}
|
||||
}
|
||||
|
||||
# Sourced metadata
|
||||
sourcedMetadata {
|
||||
comicInfo
|
||||
comicvine
|
||||
metron
|
||||
gcd
|
||||
locg {
|
||||
name
|
||||
publisher
|
||||
url
|
||||
cover
|
||||
description
|
||||
price
|
||||
rating
|
||||
pulls
|
||||
potw
|
||||
}
|
||||
}
|
||||
|
||||
# Raw file details
|
||||
rawFileDetails {
|
||||
name
|
||||
filePath
|
||||
fileSize
|
||||
extension
|
||||
mimeType
|
||||
containedIn
|
||||
pageCount
|
||||
archive {
|
||||
uncompressed
|
||||
expandedPath
|
||||
}
|
||||
cover {
|
||||
filePath
|
||||
stats
|
||||
}
|
||||
}
|
||||
|
||||
# Import status
|
||||
importStatus {
|
||||
isImported
|
||||
tagged
|
||||
matchedResult {
|
||||
score
|
||||
}
|
||||
}
|
||||
|
||||
# Timestamps
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
216
src/client/graphql/queries/dashboard.graphql
Normal file
216
src/client/graphql/queries/dashboard.graphql
Normal file
@@ -0,0 +1,216 @@
|
||||
query GetComics($page: Int, $limit: Int, $search: String, $publisher: String, $series: String) {
|
||||
comics(page: $page, limit: $limit, search: $search, publisher: $publisher, series: $series) {
|
||||
comics {
|
||||
id
|
||||
inferredMetadata {
|
||||
issue {
|
||||
name
|
||||
number
|
||||
year
|
||||
subtitle
|
||||
}
|
||||
}
|
||||
rawFileDetails {
|
||||
name
|
||||
extension
|
||||
archive {
|
||||
uncompressed
|
||||
}
|
||||
}
|
||||
sourcedMetadata {
|
||||
comicvine
|
||||
comicInfo
|
||||
locg {
|
||||
name
|
||||
publisher
|
||||
cover
|
||||
}
|
||||
}
|
||||
canonicalMetadata {
|
||||
title {
|
||||
value
|
||||
}
|
||||
series {
|
||||
value
|
||||
}
|
||||
issueNumber {
|
||||
value
|
||||
}
|
||||
}
|
||||
}
|
||||
totalCount
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
currentPage
|
||||
totalPages
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query GetRecentComics($limit: Int) {
|
||||
comics(page: 1, limit: $limit) {
|
||||
comics {
|
||||
id
|
||||
inferredMetadata {
|
||||
issue {
|
||||
name
|
||||
number
|
||||
year
|
||||
subtitle
|
||||
}
|
||||
}
|
||||
rawFileDetails {
|
||||
name
|
||||
extension
|
||||
cover {
|
||||
filePath
|
||||
}
|
||||
archive {
|
||||
uncompressed
|
||||
}
|
||||
}
|
||||
sourcedMetadata {
|
||||
comicvine
|
||||
comicInfo
|
||||
locg {
|
||||
name
|
||||
publisher
|
||||
cover
|
||||
}
|
||||
}
|
||||
canonicalMetadata {
|
||||
title {
|
||||
value
|
||||
}
|
||||
series {
|
||||
value
|
||||
}
|
||||
issueNumber {
|
||||
value
|
||||
}
|
||||
publisher {
|
||||
value
|
||||
}
|
||||
}
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
|
||||
query GetWantedComics($paginationOptions: PaginationOptionsInput!, $predicate: PredicateInput) {
|
||||
getComicBooks(paginationOptions: $paginationOptions, predicate: $predicate) {
|
||||
docs {
|
||||
id
|
||||
inferredMetadata {
|
||||
issue {
|
||||
name
|
||||
number
|
||||
year
|
||||
subtitle
|
||||
}
|
||||
}
|
||||
rawFileDetails {
|
||||
name
|
||||
extension
|
||||
cover {
|
||||
filePath
|
||||
}
|
||||
archive {
|
||||
uncompressed
|
||||
}
|
||||
}
|
||||
sourcedMetadata {
|
||||
comicvine
|
||||
comicInfo
|
||||
locg {
|
||||
name
|
||||
publisher
|
||||
cover
|
||||
}
|
||||
}
|
||||
canonicalMetadata {
|
||||
title {
|
||||
value
|
||||
}
|
||||
series {
|
||||
value
|
||||
}
|
||||
issueNumber {
|
||||
value
|
||||
}
|
||||
}
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
totalDocs
|
||||
limit
|
||||
page
|
||||
totalPages
|
||||
hasNextPage
|
||||
hasPrevPage
|
||||
}
|
||||
}
|
||||
|
||||
query GetVolumeGroups {
|
||||
getComicBookGroups {
|
||||
id
|
||||
volumes {
|
||||
id
|
||||
name
|
||||
count_of_issues
|
||||
publisher {
|
||||
id
|
||||
name
|
||||
}
|
||||
start_year
|
||||
image {
|
||||
small_url
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query GetLibraryStatistics {
|
||||
getLibraryStatistics {
|
||||
totalDocuments
|
||||
comicDirectorySize {
|
||||
fileCount
|
||||
}
|
||||
statistics {
|
||||
fileTypes {
|
||||
id
|
||||
data
|
||||
}
|
||||
issues {
|
||||
id {
|
||||
id
|
||||
name
|
||||
}
|
||||
data
|
||||
}
|
||||
fileLessComics {
|
||||
id
|
||||
}
|
||||
issuesWithComicInfoXML {
|
||||
id
|
||||
}
|
||||
publisherWithMostComicsInLibrary {
|
||||
id
|
||||
count
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query GetWeeklyPullList($input: WeeklyPullListInput!) {
|
||||
getWeeklyPullList(input: $input) {
|
||||
result {
|
||||
name
|
||||
publisher
|
||||
cover
|
||||
}
|
||||
}
|
||||
}
|
||||
72
src/client/graphql/queries/library.graphql
Normal file
72
src/client/graphql/queries/library.graphql
Normal file
@@ -0,0 +1,72 @@
|
||||
# Library queries
|
||||
# Note: The Library component currently uses Elasticsearch for search functionality
|
||||
# These queries are prepared for when the backend supports GraphQL-based library queries
|
||||
|
||||
query GetLibraryComics($page: Int, $limit: Int, $search: String, $series: String) {
|
||||
comics(page: $page, limit: $limit, search: $search, series: $series) {
|
||||
comics {
|
||||
id
|
||||
inferredMetadata {
|
||||
issue {
|
||||
name
|
||||
number
|
||||
year
|
||||
subtitle
|
||||
}
|
||||
}
|
||||
rawFileDetails {
|
||||
name
|
||||
filePath
|
||||
fileSize
|
||||
extension
|
||||
mimeType
|
||||
pageCount
|
||||
archive {
|
||||
uncompressed
|
||||
}
|
||||
cover {
|
||||
filePath
|
||||
}
|
||||
}
|
||||
sourcedMetadata {
|
||||
comicvine
|
||||
comicInfo
|
||||
locg {
|
||||
name
|
||||
publisher
|
||||
cover
|
||||
}
|
||||
}
|
||||
canonicalMetadata {
|
||||
title {
|
||||
value
|
||||
}
|
||||
series {
|
||||
value
|
||||
}
|
||||
issueNumber {
|
||||
value
|
||||
}
|
||||
publisher {
|
||||
value
|
||||
}
|
||||
pageCount {
|
||||
value
|
||||
}
|
||||
}
|
||||
importStatus {
|
||||
isImported
|
||||
tagged
|
||||
}
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
totalCount
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
currentPage
|
||||
totalPages
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user