Skip to content

Commit

Permalink
fixing some graphql caching issues
Browse files Browse the repository at this point in the history
  • Loading branch information
patsissons committed Mar 25, 2023
1 parent 2a31447 commit df57b82
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/lib/client/graphql/Movie.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ query Movie($id: Int!) {
id
response
numericalRatings {
id
metascore
imdbRating
imdbVotes
Expand Down
1 change: 1 addition & 0 deletions src/lib/client/graphql/OMDBMovie.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ query OMDBMovie($imdbId: String!) {
id
response
numericalRatings {
id
metascore
imdbRating
imdbVotes
Expand Down
5 changes: 5 additions & 0 deletions src/lib/server/graphql/resolvers/query/movie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const movie = (async (_source, { id }, { fetch }) => {
try {
const {
credits: { cast },
externalIds,
...payload
} = await fetchTMDBJson<MoviePayload>(
fetch,
Expand All @@ -30,6 +31,10 @@ export const movie = (async (_source, { id }, { fetch }) => {

return {
...payload,
externalIds: {
id,
...externalIds,
},
cast,
}
} catch (error) {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/server/graphql/resolvers/types/OMDBMovie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import type { Maybe, OmdbMovie } from '$lib/types/graphql.generated'
import type { IObjectTypeResolver } from '@graphql-tools/utils'

export const OMDBMovie: IObjectTypeResolver<OmdbMovie, Context, unknown> = {
numericalRatings: ({ metascore, imdbRating, imdbVotes, ratings }) => {
numericalRatings: ({ id, metascore, imdbRating, imdbVotes, ratings }) => {
return {
id,
metascore: toNumber(metascore),
imdbRating: toNumber(imdbRating),
imdbVotes: toNumber(imdbVotes, (value) => value.replaceAll(',', '')),
Expand Down
3 changes: 2 additions & 1 deletion src/lib/server/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type MovieCastCredit {
}

type ExternalMovieIds {
id: Int
id: Int!
imdbId: String
facebookId: String
instagramId: String
Expand All @@ -77,6 +77,7 @@ type ExternalMovieIds {
}

type OMDBNumericalRatings {
id: ID!
metascore: Int
imdbRating: Float
imdbVotes: Int
Expand Down

0 comments on commit df57b82

Please sign in to comment.