@tmdb-graphql-api/resolvers 0.0.33 → 0.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/production.analysis.txt +37 -37
- package/dist/types/cjs/helpers/getTvIdSeasonAndEpisode.d.cts +2 -3
- package/dist/types/cjs/helpers/getTvIdSeasonAndEpisode.d.cts.map +1 -1
- package/dist/types/cjs/queries/collection.d.cts +387 -387
- package/dist/types/cjs/queries/company.d.cts +1 -1
- package/dist/types/cjs/queries/credit.d.cts +472 -468
- package/dist/types/cjs/queries/credit.d.cts.map +1 -1
- package/dist/types/cjs/queries/episode.d.cts +13 -12
- package/dist/types/cjs/queries/episode.d.cts.map +1 -1
- package/dist/types/cjs/queries/episodeCredits.d.cts +5 -5
- package/dist/types/cjs/queries/episodeVideos.d.cts +1 -1
- package/dist/types/cjs/queries/find.d.cts +197 -197
- package/dist/types/cjs/queries/genres.d.cts +1 -1
- package/dist/types/cjs/queries/keyword.d.cts +1 -1
- package/dist/types/cjs/queries/movie.d.cts +398 -398
- package/dist/types/cjs/queries/movieCredits.d.cts +5 -5
- package/dist/types/cjs/queries/movieRecommendations.d.cts +203 -203
- package/dist/types/cjs/queries/movieReviews.d.cts +203 -203
- package/dist/types/cjs/queries/movieSimilarMovies.d.cts +203 -203
- package/dist/types/cjs/queries/movieVideos.d.cts +1 -1
- package/dist/types/cjs/queries/movieWatchProviders.d.cts +180 -180
- package/dist/types/cjs/queries/network.d.cts +1 -1
- package/dist/types/cjs/queries/person.d.cts +2 -2
- package/dist/types/cjs/queries/review.d.cts +2 -2
- package/dist/types/cjs/queries/season.d.cts +34 -31
- package/dist/types/cjs/queries/season.d.cts.map +1 -1
- package/dist/types/cjs/queries/seasonCredits.d.cts +5 -5
- package/dist/types/cjs/queries/seasonVideos.d.cts +1 -1
- package/dist/types/cjs/queries/tv.d.cts +1167 -1144
- package/dist/types/cjs/queries/tv.d.cts.map +1 -1
- package/dist/types/cjs/queries/tvCredits.d.cts +5 -5
- package/dist/types/cjs/queries/tvEpisodeGroups.d.cts +2 -2
- package/dist/types/cjs/queries/tvKeywords.d.cts +1 -1
- package/dist/types/cjs/queries/tvRecommendations.d.cts +594 -582
- package/dist/types/cjs/queries/tvRecommendations.d.cts.map +1 -1
- package/dist/types/cjs/queries/tvReviews.d.cts +594 -582
- package/dist/types/cjs/queries/tvReviews.d.cts.map +1 -1
- package/dist/types/cjs/queries/tvSimilarTvShows.d.cts +594 -582
- package/dist/types/cjs/queries/tvSimilarTvShows.d.cts.map +1 -1
- package/dist/types/cjs/queries/tvVideos.d.cts +1 -1
- package/dist/types/cjs/queries/tvWatchProviders.d.cts +180 -180
- package/dist/types/cjs/types.d.cts +2 -0
- package/dist/types/cjs/types.d.cts.map +1 -1
- package/dist/types/esm/helpers/getTvIdSeasonAndEpisode.d.ts +2 -3
- package/dist/types/esm/helpers/getTvIdSeasonAndEpisode.d.ts.map +1 -1
- package/dist/types/esm/queries/collection.d.ts +387 -387
- package/dist/types/esm/queries/company.d.ts +1 -1
- package/dist/types/esm/queries/credit.d.ts +472 -468
- package/dist/types/esm/queries/credit.d.ts.map +1 -1
- package/dist/types/esm/queries/episode.d.ts +13 -12
- package/dist/types/esm/queries/episode.d.ts.map +1 -1
- package/dist/types/esm/queries/episodeCredits.d.ts +5 -5
- package/dist/types/esm/queries/episodeVideos.d.ts +1 -1
- package/dist/types/esm/queries/find.d.ts +197 -197
- package/dist/types/esm/queries/genres.d.ts +1 -1
- package/dist/types/esm/queries/keyword.d.ts +1 -1
- package/dist/types/esm/queries/movie.d.ts +398 -398
- package/dist/types/esm/queries/movieCredits.d.ts +5 -5
- package/dist/types/esm/queries/movieRecommendations.d.ts +203 -203
- package/dist/types/esm/queries/movieReviews.d.ts +203 -203
- package/dist/types/esm/queries/movieSimilarMovies.d.ts +203 -203
- package/dist/types/esm/queries/movieVideos.d.ts +1 -1
- package/dist/types/esm/queries/movieWatchProviders.d.ts +180 -180
- package/dist/types/esm/queries/network.d.ts +1 -1
- package/dist/types/esm/queries/person.d.ts +2 -2
- package/dist/types/esm/queries/review.d.ts +2 -2
- package/dist/types/esm/queries/season.d.ts +34 -31
- package/dist/types/esm/queries/season.d.ts.map +1 -1
- package/dist/types/esm/queries/seasonCredits.d.ts +5 -5
- package/dist/types/esm/queries/seasonVideos.d.ts +1 -1
- package/dist/types/esm/queries/tv.d.ts +1167 -1144
- package/dist/types/esm/queries/tv.d.ts.map +1 -1
- package/dist/types/esm/queries/tvCredits.d.ts +5 -5
- package/dist/types/esm/queries/tvEpisodeGroups.d.ts +2 -2
- package/dist/types/esm/queries/tvKeywords.d.ts +1 -1
- package/dist/types/esm/queries/tvRecommendations.d.ts +594 -582
- package/dist/types/esm/queries/tvRecommendations.d.ts.map +1 -1
- package/dist/types/esm/queries/tvReviews.d.ts +594 -582
- package/dist/types/esm/queries/tvReviews.d.ts.map +1 -1
- package/dist/types/esm/queries/tvSimilarTvShows.d.ts +594 -582
- package/dist/types/esm/queries/tvSimilarTvShows.d.ts.map +1 -1
- package/dist/types/esm/queries/tvVideos.d.ts +1 -1
- package/dist/types/esm/queries/tvWatchProviders.d.ts +180 -180
- package/dist/types/esm/types.d.ts +2 -0
- package/dist/types/esm/types.d.ts.map +1 -1
- package/dist/types/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/helpers/__snapshots__/typePropNames.test.ts.snap +2 -0
- package/src/helpers/getTvIdSeasonAndEpisode.ts +6 -10
- package/src/queries/__snapshots__/episode.test.ts.snap +2 -1
- package/src/queries/__snapshots__/season.test.ts.snap +2 -1
- package/src/queries/episode.test.ts +2 -2
- package/src/queries/episode.ts +7 -7
- package/src/queries/episodeCredits.test.ts +15 -5
- package/src/queries/episodeExternalIds.test.ts +13 -3
- package/src/queries/episodeStills.test.ts +13 -3
- package/src/queries/episodeTranslations.test.ts +13 -3
- package/src/queries/episodeVideos.test.ts +13 -3
- package/src/queries/season.test.ts +2 -2
- package/src/queries/season.ts +6 -6
- package/src/types.ts +9 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmdb-graphql-api/resolvers",
|
|
3
3
|
"description": "The TMDB GraphQL resolvers module.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.34",
|
|
5
5
|
"author": "Dylan Aubrey",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/badbatch/themoviedb-graphql-api",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"query-string": "^8.1.0",
|
|
41
41
|
"type-fest": "^4.5.0",
|
|
42
42
|
"@tmdb-graphql-api/rest-client": "0.0.9",
|
|
43
|
-
"@tmdb-graphql-api/schema": "0.0.
|
|
43
|
+
"@tmdb-graphql-api/schema": "0.0.26"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@babel/runtime": "<8",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"fetch-mocked": "^0.0.21",
|
|
60
60
|
"graphql": "^16.8.1",
|
|
61
61
|
"lodash-es": "^4.17.21",
|
|
62
|
-
"@tmdb-graphql-api/test-utils": "0.0.
|
|
62
|
+
"@tmdb-graphql-api/test-utils": "0.0.4"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "pnpm run clean:dist && pnpm run compile",
|
|
@@ -266,6 +266,7 @@ exports[`typePropNames the correct prop names are returned 1`] = `
|
|
|
266
266
|
"airDate",
|
|
267
267
|
"cast",
|
|
268
268
|
"crew",
|
|
269
|
+
"episodeLookupId",
|
|
269
270
|
"episodeNumber",
|
|
270
271
|
"externalIds",
|
|
271
272
|
"guestStars",
|
|
@@ -562,6 +563,7 @@ exports[`typePropNames the correct prop names are returned 1`] = `
|
|
|
562
563
|
"overview",
|
|
563
564
|
"posterPath",
|
|
564
565
|
"posters",
|
|
566
|
+
"seasonLookupId",
|
|
565
567
|
"seasonNumber",
|
|
566
568
|
"translations",
|
|
567
569
|
"tvShowId",
|
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
import { type QueryEpisodeArgs, type QuerySeasonArgs } from '@tmdb-graphql-api/schema/types';
|
|
2
1
|
import { type RawEpisode, type RawSeason } from '../types.ts';
|
|
3
2
|
import { decodeId } from './decodeId.ts';
|
|
4
3
|
|
|
5
|
-
export const getTvIdSeasonAndEpisode = (
|
|
6
|
-
|
|
7
|
-
args: QuerySeasonArgs | QueryEpisodeArgs
|
|
8
|
-
) => {
|
|
9
|
-
let id: string | number;
|
|
4
|
+
export const getTvIdSeasonAndEpisode = (obj: RawSeason | RawEpisode | undefined, lookupId: string) => {
|
|
5
|
+
let tvId: number;
|
|
10
6
|
let seasonNumber: number;
|
|
11
7
|
let episodeNumber: number | undefined;
|
|
12
8
|
|
|
13
9
|
if (obj) {
|
|
14
|
-
|
|
10
|
+
tvId = obj.tv_show_id;
|
|
15
11
|
seasonNumber = obj.season_number;
|
|
16
12
|
episodeNumber = 'episode_number' in obj ? obj.episode_number : undefined;
|
|
17
13
|
} else {
|
|
18
|
-
const parsed = decodeId<{ episodeNumber?: number; id: string; seasonNumber: number }>(
|
|
19
|
-
|
|
14
|
+
const parsed = decodeId<{ episodeNumber?: number; id: string; seasonNumber: number }>(lookupId);
|
|
15
|
+
tvId = Number(parsed.id);
|
|
20
16
|
seasonNumber = parsed.seasonNumber;
|
|
21
17
|
episodeNumber = parsed.episodeNumber;
|
|
22
18
|
}
|
|
23
19
|
|
|
24
|
-
return { episodeNumber,
|
|
20
|
+
return { episodeNumber, seasonNumber, tvId };
|
|
25
21
|
};
|
|
@@ -70,6 +70,7 @@ exports[`resolveEpisode > should return the correct episode details 1`] = `
|
|
|
70
70
|
"profile_path": "/xvNN5huL0X8yJ7h3IZfGG4O2zBD.jpg",
|
|
71
71
|
},
|
|
72
72
|
],
|
|
73
|
+
"episode_lookup_id": "eyJzZWFzb25OdW1iZXIiOjEsInR2SWQiOjEzOTksImVwaXNvZGVOdW1iZXIiOjF9",
|
|
73
74
|
"episode_number": 1,
|
|
74
75
|
"guest_stars": [
|
|
75
76
|
{
|
|
@@ -346,7 +347,7 @@ exports[`resolveEpisode > should return the correct episode details 1`] = `
|
|
|
346
347
|
"profile_path": "/tNW2DukUhi0ljCxOcYqs6x30LIH.jpg",
|
|
347
348
|
},
|
|
348
349
|
],
|
|
349
|
-
"id":
|
|
350
|
+
"id": 63056,
|
|
350
351
|
"name": "Winter Is Coming",
|
|
351
352
|
"overview": "Jon Arryn, the Hand of the King, is dead. King Robert Baratheon plans to ask his oldest friend, Eddard Stark, to take Jon's place. Across the sea, Viserys Targaryen plans to wed his sister to a nomadic warlord in exchange for an army.",
|
|
352
353
|
"production_code": "101",
|
|
@@ -4684,10 +4684,11 @@ exports[`resolveSeason > should return the correct season details 1`] = `
|
|
|
4684
4684
|
"vote_count": 115,
|
|
4685
4685
|
},
|
|
4686
4686
|
],
|
|
4687
|
-
"id":
|
|
4687
|
+
"id": 3624,
|
|
4688
4688
|
"name": "Season 1",
|
|
4689
4689
|
"overview": "Trouble is brewing in the Seven Kingdoms of Westeros. For the driven inhabitants of this visionary world, control of Westeros' Iron Throne holds the lure of great power. But in a land where the seasons can last a lifetime, winter is coming...and beyond the Great Wall that protects them, an ancient evil has returned. In Season One, the story centers on three primary areas: the Stark and the Lannister families, whose designs on controlling the throne threaten a tenuous peace; the dragon princess Daenerys, heir to the former dynasty, who waits just over the Narrow Sea with her malevolent brother Viserys; and the Great Wall--a massive barrier of ice where a forgotten danger is stirring.",
|
|
4690
4690
|
"poster_path": "/zwaj4egrhnXOBIit1tyb4Sbt3KP.jpg",
|
|
4691
|
+
"season_lookup_id": "eyJzZWFzb25OdW1iZXIiOjEsInR2SWQiOjEzOTl9",
|
|
4691
4692
|
"season_number": 1,
|
|
4692
4693
|
"tv_show_id": 1399,
|
|
4693
4694
|
}
|
|
@@ -44,7 +44,7 @@ describe('resolveEpisode >', () => {
|
|
|
44
44
|
await expect(
|
|
45
45
|
resolveEpisode(
|
|
46
46
|
undefined,
|
|
47
|
-
{
|
|
47
|
+
{ episodeLookupId: encodeId({ episodeNumber: 1, id, seasonNumber: 1 }) },
|
|
48
48
|
{ restClient, setCacheMetadata, tmdbGuestSessionId: 'mock-tmdbGuestSessionId' } as unknown as Context,
|
|
49
49
|
{ fieldNodes: [fieldNode] } as unknown as GraphQLResolveInfo
|
|
50
50
|
)
|
|
@@ -61,7 +61,7 @@ describe('resolveEpisode >', () => {
|
|
|
61
61
|
|
|
62
62
|
await resolveEpisode(
|
|
63
63
|
undefined,
|
|
64
|
-
{
|
|
64
|
+
{ episodeLookupId: encodeId({ episodeNumber: 1, id, seasonNumber: 1 }) },
|
|
65
65
|
{
|
|
66
66
|
restClient: { episode: episodeFetchMock } as unknown as Getta & ShortcutProperties<ShortcutMethodNames>,
|
|
67
67
|
setCacheMetadata,
|
package/src/queries/episode.ts
CHANGED
|
@@ -24,11 +24,11 @@ export const resolveEpisode = async (
|
|
|
24
24
|
{ fieldName, fieldNodes }: GraphQLResolveInfo
|
|
25
25
|
) => {
|
|
26
26
|
const typedFieldName = snakeCase(fieldName) as keyof RawEpisode;
|
|
27
|
-
const { episodeNumber,
|
|
27
|
+
const { episodeNumber, seasonNumber, tvId } = getTvIdSeasonAndEpisode(obj, args.episodeLookupId);
|
|
28
28
|
|
|
29
29
|
if (obj && !isUndefined(obj[typedFieldName])) {
|
|
30
|
-
return typedFieldName === '
|
|
31
|
-
? encodeId({
|
|
30
|
+
return typedFieldName === 'episode_lookup_id'
|
|
31
|
+
? encodeId({ seasonNumber, tvId, ...(episodeNumber ? { episodeNumber } : {}) })
|
|
32
32
|
: obj[typedFieldName];
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -36,7 +36,7 @@ export const resolveEpisode = async (
|
|
|
36
36
|
|
|
37
37
|
const { data, errors, headers } = await restClient.episode<RawEpisodeWithAppendToResponse>(
|
|
38
38
|
{
|
|
39
|
-
pathTemplateData: { episodeNumber, id, seasonNumber },
|
|
39
|
+
pathTemplateData: { episodeNumber, id: tvId, seasonNumber },
|
|
40
40
|
...(appendToResponseKeys.length > 0
|
|
41
41
|
? {
|
|
42
42
|
queryParams: {
|
|
@@ -50,16 +50,16 @@ export const resolveEpisode = async (
|
|
|
50
50
|
|
|
51
51
|
if (errors?.length) {
|
|
52
52
|
throw new GraphQLError(
|
|
53
|
-
`Failed to resolve ${TV} show ${
|
|
53
|
+
`Failed to resolve ${TV} show ${tvId} ${SEASON} ${seasonNumber} ${EPISODE} ${episodeNumber!}.`,
|
|
54
54
|
{ nodes: fieldNodes, originalError: errors[0] }
|
|
55
55
|
);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const rawEpisode = data!;
|
|
59
|
-
rawEpisode.
|
|
59
|
+
rawEpisode.episode_lookup_id = encodeId({ seasonNumber, tvId, ...(episodeNumber ? { episodeNumber } : {}) });
|
|
60
60
|
|
|
61
61
|
if (!rawEpisode.tv_show_id) {
|
|
62
|
-
rawEpisode.tv_show_id =
|
|
62
|
+
rawEpisode.tv_show_id = tvId;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
if (obj) {
|
|
@@ -8,11 +8,21 @@ import { type FetchResponse, type Getta, type ShortcutProperties } from 'getta';
|
|
|
8
8
|
import { type GraphQLResolveInfo } from 'graphql';
|
|
9
9
|
import { buildEndpoint } from '../__testUtils__/helpers/buildEndpoint.ts';
|
|
10
10
|
import { createRestClient } from '../__testUtils__/helpers/createRestClient.ts';
|
|
11
|
+
import { encodeId } from '../helpers/encodeId.ts';
|
|
11
12
|
import { type Context, type RawEpisode } from '../types.ts';
|
|
12
13
|
import { resolveEpisodeCredits } from './episodeCredits.ts';
|
|
13
14
|
|
|
14
15
|
const mockedFetch = mockFetch(jest.fn);
|
|
15
16
|
|
|
17
|
+
const episodeDetailsWithLookupId: RawEpisode = {
|
|
18
|
+
...episodeDetails,
|
|
19
|
+
episode_lookup_id: encodeId({
|
|
20
|
+
episodeNumber: episodeDetails.episode_number,
|
|
21
|
+
seasonNumber: episodeDetails.season_number,
|
|
22
|
+
tvId: episodeDetails.tv_show_id,
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
|
|
16
26
|
describe('resolveEpisodeCredits >', () => {
|
|
17
27
|
let restClient: Getta & ShortcutProperties<ShortcutMethodNames>;
|
|
18
28
|
const setCacheMetadata = jest.fn();
|
|
@@ -42,7 +52,7 @@ describe('resolveEpisodeCredits >', () => {
|
|
|
42
52
|
it('should return the correct response', async () => {
|
|
43
53
|
await expect(
|
|
44
54
|
resolveEpisodeCredits(
|
|
45
|
-
|
|
55
|
+
episodeDetailsWithLookupId,
|
|
46
56
|
undefined,
|
|
47
57
|
{ restClient, setCacheMetadata, tmdbGuestSessionId: 'mock-tmdbGuestSessionId' } as unknown as Context,
|
|
48
58
|
{
|
|
@@ -57,7 +67,7 @@ describe('resolveEpisodeCredits >', () => {
|
|
|
57
67
|
it('should return the correct response', async () => {
|
|
58
68
|
await expect(
|
|
59
69
|
resolveEpisodeCredits(
|
|
60
|
-
|
|
70
|
+
episodeDetailsWithLookupId,
|
|
61
71
|
undefined,
|
|
62
72
|
{ restClient, setCacheMetadata, tmdbGuestSessionId: 'mock-tmdbGuestSessionId' } as unknown as Context,
|
|
63
73
|
{
|
|
@@ -72,7 +82,7 @@ describe('resolveEpisodeCredits >', () => {
|
|
|
72
82
|
it('should return the correct response', async () => {
|
|
73
83
|
await expect(
|
|
74
84
|
resolveEpisodeCredits(
|
|
75
|
-
|
|
85
|
+
episodeDetailsWithLookupId,
|
|
76
86
|
undefined,
|
|
77
87
|
{ restClient, setCacheMetadata, tmdbGuestSessionId: 'mock-tmdbGuestSessionId' } as unknown as Context,
|
|
78
88
|
{
|
|
@@ -93,7 +103,7 @@ describe('resolveEpisodeCredits >', () => {
|
|
|
93
103
|
|
|
94
104
|
await expect(
|
|
95
105
|
resolveEpisodeCredits(
|
|
96
|
-
{ ...
|
|
106
|
+
{ ...episodeDetailsWithLookupId, __headers: new Headers(), credits: rest },
|
|
97
107
|
undefined,
|
|
98
108
|
{
|
|
99
109
|
restClient: { episode: episodeFetchMock } as unknown as Getta & ShortcutProperties<ShortcutMethodNames>,
|
|
@@ -115,7 +125,7 @@ describe('resolveEpisodeCredits >', () => {
|
|
|
115
125
|
const { id, ...rest } = episodeCredits;
|
|
116
126
|
|
|
117
127
|
await resolveEpisodeCredits(
|
|
118
|
-
{ ...
|
|
128
|
+
{ ...episodeDetailsWithLookupId, __headers: new Headers(), credits: rest },
|
|
119
129
|
undefined,
|
|
120
130
|
{
|
|
121
131
|
restClient: { episode: episodeFetchMock } as unknown as Getta & ShortcutProperties<ShortcutMethodNames>,
|
|
@@ -8,11 +8,21 @@ import { type FetchResponse, type Getta, type ShortcutProperties } from 'getta';
|
|
|
8
8
|
import { type GraphQLResolveInfo } from 'graphql';
|
|
9
9
|
import { buildEndpoint } from '../__testUtils__/helpers/buildEndpoint.ts';
|
|
10
10
|
import { createRestClient } from '../__testUtils__/helpers/createRestClient.ts';
|
|
11
|
+
import { encodeId } from '../helpers/encodeId.ts';
|
|
11
12
|
import { type Context, type RawEpisode, type RawEpisodeWithAppendToResponse } from '../types.ts';
|
|
12
13
|
import { resolveEpisodeExternalIds } from './episodeExternalIds.ts';
|
|
13
14
|
|
|
14
15
|
const mockedFetch = mockFetch(jest.fn);
|
|
15
16
|
|
|
17
|
+
const episodeDetailsWithLookupId: RawEpisode = {
|
|
18
|
+
...episodeDetails,
|
|
19
|
+
episode_lookup_id: encodeId({
|
|
20
|
+
episodeNumber: episodeDetails.episode_number,
|
|
21
|
+
seasonNumber: episodeDetails.season_number,
|
|
22
|
+
tvId: episodeDetails.tv_show_id,
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
|
|
16
26
|
describe('resolveEpisodeExternalIds >', () => {
|
|
17
27
|
let restClient: Getta & ShortcutProperties<ShortcutMethodNames>;
|
|
18
28
|
const setCacheMetadata = jest.fn();
|
|
@@ -41,7 +51,7 @@ describe('resolveEpisodeExternalIds >', () => {
|
|
|
41
51
|
it('should return the episode external IDs', async () => {
|
|
42
52
|
await expect(
|
|
43
53
|
resolveEpisodeExternalIds(
|
|
44
|
-
|
|
54
|
+
episodeDetailsWithLookupId,
|
|
45
55
|
undefined,
|
|
46
56
|
{ restClient, setCacheMetadata, tmdbGuestSessionId: 'mock-tmdbGuestSessionId' } as unknown as Context,
|
|
47
57
|
{} as GraphQLResolveInfo
|
|
@@ -60,7 +70,7 @@ describe('resolveEpisodeExternalIds >', () => {
|
|
|
60
70
|
await expect(
|
|
61
71
|
resolveEpisodeExternalIds(
|
|
62
72
|
{
|
|
63
|
-
...
|
|
73
|
+
...episodeDetailsWithLookupId,
|
|
64
74
|
__headers: new Headers(),
|
|
65
75
|
external_ids: rest,
|
|
66
76
|
} as unknown as RawEpisodeWithAppendToResponse,
|
|
@@ -84,7 +94,7 @@ describe('resolveEpisodeExternalIds >', () => {
|
|
|
84
94
|
|
|
85
95
|
await resolveEpisodeExternalIds(
|
|
86
96
|
{
|
|
87
|
-
...
|
|
97
|
+
...episodeDetailsWithLookupId,
|
|
88
98
|
__headers: new Headers(),
|
|
89
99
|
external_ids: rest,
|
|
90
100
|
} as unknown as RawEpisodeWithAppendToResponse,
|
|
@@ -8,11 +8,21 @@ import { type FetchResponse, type Getta, type ShortcutProperties } from 'getta';
|
|
|
8
8
|
import { type GraphQLResolveInfo } from 'graphql';
|
|
9
9
|
import { buildEndpoint } from '../__testUtils__/helpers/buildEndpoint.ts';
|
|
10
10
|
import { createRestClient } from '../__testUtils__/helpers/createRestClient.ts';
|
|
11
|
+
import { encodeId } from '../helpers/encodeId.ts';
|
|
11
12
|
import { type Context, type RawEpisode } from '../types.ts';
|
|
12
13
|
import { resolveEpisodeStills } from './episodeStills.ts';
|
|
13
14
|
|
|
14
15
|
const mockedFetch = mockFetch(jest.fn);
|
|
15
16
|
|
|
17
|
+
const episodeDetailsWithLookupId: RawEpisode = {
|
|
18
|
+
...episodeDetails,
|
|
19
|
+
episode_lookup_id: encodeId({
|
|
20
|
+
episodeNumber: episodeDetails.episode_number,
|
|
21
|
+
seasonNumber: episodeDetails.season_number,
|
|
22
|
+
tvId: episodeDetails.tv_show_id,
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
|
|
16
26
|
describe('resolveEpisodeStills >', () => {
|
|
17
27
|
let restClient: Getta & ShortcutProperties<ShortcutMethodNames>;
|
|
18
28
|
const setCacheMetadata = jest.fn();
|
|
@@ -41,7 +51,7 @@ describe('resolveEpisodeStills >', () => {
|
|
|
41
51
|
it('should return the episode stills', async () => {
|
|
42
52
|
await expect(
|
|
43
53
|
resolveEpisodeStills(
|
|
44
|
-
|
|
54
|
+
episodeDetailsWithLookupId,
|
|
45
55
|
undefined,
|
|
46
56
|
{ restClient, setCacheMetadata, tmdbGuestSessionId: 'mock-tmdbGuestSessionId' } as unknown as Context,
|
|
47
57
|
{} as GraphQLResolveInfo
|
|
@@ -59,7 +69,7 @@ describe('resolveEpisodeStills >', () => {
|
|
|
59
69
|
|
|
60
70
|
await expect(
|
|
61
71
|
resolveEpisodeStills(
|
|
62
|
-
{ ...
|
|
72
|
+
{ ...episodeDetailsWithLookupId, __headers: new Headers(), images: rest },
|
|
63
73
|
undefined,
|
|
64
74
|
{
|
|
65
75
|
restClient: { episode: episodeFetchMock } as unknown as Getta & ShortcutProperties<ShortcutMethodNames>,
|
|
@@ -79,7 +89,7 @@ describe('resolveEpisodeStills >', () => {
|
|
|
79
89
|
const { id, ...rest } = episodeStills;
|
|
80
90
|
|
|
81
91
|
await resolveEpisodeStills(
|
|
82
|
-
{ ...
|
|
92
|
+
{ ...episodeDetailsWithLookupId, __headers: new Headers(), images: rest },
|
|
83
93
|
undefined,
|
|
84
94
|
{
|
|
85
95
|
restClient: { episode: episodeFetchMock } as unknown as Getta & ShortcutProperties<ShortcutMethodNames>,
|
|
@@ -8,11 +8,21 @@ import { type FetchResponse, type Getta, type ShortcutProperties } from 'getta';
|
|
|
8
8
|
import { type GraphQLResolveInfo } from 'graphql';
|
|
9
9
|
import { buildEndpoint } from '../__testUtils__/helpers/buildEndpoint.ts';
|
|
10
10
|
import { createRestClient } from '../__testUtils__/helpers/createRestClient.ts';
|
|
11
|
+
import { encodeId } from '../helpers/encodeId.ts';
|
|
11
12
|
import { type Context, type RawEpisode } from '../types.ts';
|
|
12
13
|
import { resolveEpisodeTranslations } from './episodeTranslations.ts';
|
|
13
14
|
|
|
14
15
|
const mockedFetch = mockFetch(jest.fn);
|
|
15
16
|
|
|
17
|
+
const episodeDetailsWithLookupId: RawEpisode = {
|
|
18
|
+
...episodeDetails,
|
|
19
|
+
episode_lookup_id: encodeId({
|
|
20
|
+
episodeNumber: episodeDetails.episode_number,
|
|
21
|
+
seasonNumber: episodeDetails.season_number,
|
|
22
|
+
tvId: episodeDetails.tv_show_id,
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
|
|
16
26
|
describe('resolveEpisodeTranslations >', () => {
|
|
17
27
|
let restClient: Getta & ShortcutProperties<ShortcutMethodNames>;
|
|
18
28
|
const setCacheMetadata = jest.fn();
|
|
@@ -41,7 +51,7 @@ describe('resolveEpisodeTranslations >', () => {
|
|
|
41
51
|
it('should return the episode translations', async () => {
|
|
42
52
|
await expect(
|
|
43
53
|
resolveEpisodeTranslations(
|
|
44
|
-
|
|
54
|
+
episodeDetailsWithLookupId,
|
|
45
55
|
undefined,
|
|
46
56
|
{ restClient, setCacheMetadata, tmdbGuestSessionId: 'mock-tmdbGuestSessionId' } as unknown as Context,
|
|
47
57
|
{} as GraphQLResolveInfo
|
|
@@ -59,7 +69,7 @@ describe('resolveEpisodeTranslations >', () => {
|
|
|
59
69
|
|
|
60
70
|
await expect(
|
|
61
71
|
resolveEpisodeTranslations(
|
|
62
|
-
{ ...
|
|
72
|
+
{ ...episodeDetailsWithLookupId, __headers: new Headers(), translations: rest },
|
|
63
73
|
undefined,
|
|
64
74
|
{
|
|
65
75
|
restClient: { episode: episodeFetchMock } as unknown as Getta & ShortcutProperties<ShortcutMethodNames>,
|
|
@@ -79,7 +89,7 @@ describe('resolveEpisodeTranslations >', () => {
|
|
|
79
89
|
const { id, ...rest } = episodeTranslations;
|
|
80
90
|
|
|
81
91
|
await resolveEpisodeTranslations(
|
|
82
|
-
{ ...
|
|
92
|
+
{ ...episodeDetailsWithLookupId, __headers: new Headers(), translations: rest },
|
|
83
93
|
undefined,
|
|
84
94
|
{
|
|
85
95
|
restClient: { episode: episodeFetchMock } as unknown as Getta & ShortcutProperties<ShortcutMethodNames>,
|
|
@@ -8,11 +8,21 @@ import { type FetchResponse, type Getta, type ShortcutProperties } from 'getta';
|
|
|
8
8
|
import { type GraphQLResolveInfo } from 'graphql';
|
|
9
9
|
import { buildEndpoint } from '../__testUtils__/helpers/buildEndpoint.ts';
|
|
10
10
|
import { createRestClient } from '../__testUtils__/helpers/createRestClient.ts';
|
|
11
|
+
import { encodeId } from '../helpers/encodeId.ts';
|
|
11
12
|
import { type Context, type RawEpisode } from '../types.ts';
|
|
12
13
|
import { resolveEpisodeVideos } from './episodeVideos.ts';
|
|
13
14
|
|
|
14
15
|
const mockedFetch = mockFetch(jest.fn);
|
|
15
16
|
|
|
17
|
+
const episodeDetailsWithLookupId: RawEpisode = {
|
|
18
|
+
...episodeDetails,
|
|
19
|
+
episode_lookup_id: encodeId({
|
|
20
|
+
episodeNumber: episodeDetails.episode_number,
|
|
21
|
+
seasonNumber: episodeDetails.season_number,
|
|
22
|
+
tvId: episodeDetails.tv_show_id,
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
|
|
16
26
|
describe('resolveEpisodeVideos >', () => {
|
|
17
27
|
let restClient: Getta & ShortcutProperties<ShortcutMethodNames>;
|
|
18
28
|
const setCacheMetadata = jest.fn();
|
|
@@ -41,7 +51,7 @@ describe('resolveEpisodeVideos >', () => {
|
|
|
41
51
|
it('should return the episode videos', async () => {
|
|
42
52
|
await expect(
|
|
43
53
|
resolveEpisodeVideos(
|
|
44
|
-
|
|
54
|
+
episodeDetailsWithLookupId,
|
|
45
55
|
undefined,
|
|
46
56
|
{ restClient, setCacheMetadata, tmdbGuestSessionId: 'mock-tmdbGuestSessionId' } as unknown as Context,
|
|
47
57
|
{} as GraphQLResolveInfo
|
|
@@ -59,7 +69,7 @@ describe('resolveEpisodeVideos >', () => {
|
|
|
59
69
|
|
|
60
70
|
await expect(
|
|
61
71
|
resolveEpisodeVideos(
|
|
62
|
-
{ ...
|
|
72
|
+
{ ...episodeDetailsWithLookupId, __headers: new Headers(), videos: rest },
|
|
63
73
|
undefined,
|
|
64
74
|
{
|
|
65
75
|
restClient: { episode: episodeFetchMock } as unknown as Getta & ShortcutProperties<ShortcutMethodNames>,
|
|
@@ -79,7 +89,7 @@ describe('resolveEpisodeVideos >', () => {
|
|
|
79
89
|
const { id, ...rest } = episodeVideos;
|
|
80
90
|
|
|
81
91
|
await resolveEpisodeVideos(
|
|
82
|
-
{ ...
|
|
92
|
+
{ ...episodeDetailsWithLookupId, __headers: new Headers(), videos: rest },
|
|
83
93
|
undefined,
|
|
84
94
|
{
|
|
85
95
|
restClient: { episode: episodeFetchMock } as unknown as Getta & ShortcutProperties<ShortcutMethodNames>,
|
|
@@ -44,7 +44,7 @@ describe('resolveSeason >', () => {
|
|
|
44
44
|
await expect(
|
|
45
45
|
resolveSeason(
|
|
46
46
|
undefined,
|
|
47
|
-
{
|
|
47
|
+
{ seasonLookupId: encodeId({ id, seasonNumber: 1 }) },
|
|
48
48
|
{ restClient, setCacheMetadata, tmdbGuestSessionId: 'mock-tmdbGuestSessionId' } as unknown as Context,
|
|
49
49
|
{ fieldNodes: [fieldNode] } as unknown as GraphQLResolveInfo
|
|
50
50
|
)
|
|
@@ -61,7 +61,7 @@ describe('resolveSeason >', () => {
|
|
|
61
61
|
|
|
62
62
|
await resolveSeason(
|
|
63
63
|
undefined,
|
|
64
|
-
{
|
|
64
|
+
{ seasonLookupId: encodeId({ id, seasonNumber: 1 }) },
|
|
65
65
|
{
|
|
66
66
|
restClient: { season: seasonFetchMock } as unknown as Getta & ShortcutProperties<ShortcutMethodNames>,
|
|
67
67
|
setCacheMetadata,
|
package/src/queries/season.ts
CHANGED
|
@@ -31,17 +31,17 @@ export const resolveSeason = async (
|
|
|
31
31
|
{ fieldName, fieldNodes }: GraphQLResolveInfo
|
|
32
32
|
) => {
|
|
33
33
|
const typedFieldName = snakeCase(fieldName) as keyof RawSeason;
|
|
34
|
-
const {
|
|
34
|
+
const { seasonNumber, tvId } = getTvIdSeasonAndEpisode(obj, args.seasonLookupId);
|
|
35
35
|
|
|
36
36
|
if (obj && !isUndefined(obj[typedFieldName])) {
|
|
37
|
-
return typedFieldName === '
|
|
37
|
+
return typedFieldName === 'season_lookup_id' ? encodeId({ seasonNumber, tvId }) : obj[typedFieldName];
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const appendToResponseKeys = getAppendToResponseKeys(fieldNodes[0]!, appendToResponse, fragmentDefinitions);
|
|
41
41
|
|
|
42
42
|
const { data, errors, headers } = await restClient.season<RawSeasonWithAppendToResponse>(
|
|
43
43
|
{
|
|
44
|
-
pathTemplateData: { id, number: seasonNumber },
|
|
44
|
+
pathTemplateData: { id: tvId, number: seasonNumber },
|
|
45
45
|
...(appendToResponseKeys.length > 0
|
|
46
46
|
? {
|
|
47
47
|
queryParams: {
|
|
@@ -54,17 +54,17 @@ export const resolveSeason = async (
|
|
|
54
54
|
);
|
|
55
55
|
|
|
56
56
|
if (errors?.length) {
|
|
57
|
-
throw new GraphQLError(`Failed to resolve ${TV} show ${
|
|
57
|
+
throw new GraphQLError(`Failed to resolve ${TV} show ${tvId} ${SEASON} ${seasonNumber}.`, {
|
|
58
58
|
nodes: fieldNodes,
|
|
59
59
|
originalError: errors[0],
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
const rawSeason = data!;
|
|
64
|
-
rawSeason.
|
|
64
|
+
rawSeason.season_lookup_id = encodeId({ seasonNumber, tvId });
|
|
65
65
|
|
|
66
66
|
if (!rawSeason.tv_show_id) {
|
|
67
|
-
rawSeason.tv_show_id =
|
|
67
|
+
rawSeason.tv_show_id = tvId;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
enrichEpisodeData(rawSeason);
|
package/src/types.ts
CHANGED
|
@@ -107,7 +107,10 @@ export interface RawDiscoverTv extends PlainObject {
|
|
|
107
107
|
|
|
108
108
|
export type RawEpisode = SnakeCasedPropertiesDeep<
|
|
109
109
|
Omit<Episode, 'cast' | 'crew' | 'externalIds' | 'guestStars' | 'stills' | 'translations' | 'videos'>
|
|
110
|
-
> & {
|
|
110
|
+
> & {
|
|
111
|
+
episode_lookup_id: Scalars['String'];
|
|
112
|
+
tv_show_id?: Scalars['ID'];
|
|
113
|
+
};
|
|
111
114
|
|
|
112
115
|
export type RawEpisodeCredits = SnakeCasedPropertiesDeep<Pick<Episode, 'id' | 'cast' | 'crew' | 'guestStars'>>;
|
|
113
116
|
|
|
@@ -305,7 +308,11 @@ export type RawMedia = RawMovie | RawTv | RawPerson;
|
|
|
305
308
|
|
|
306
309
|
export type RawSeason = SnakeCasedPropertiesDeep<
|
|
307
310
|
Omit<Season, 'cast' | 'crew' | 'externalIds' | 'posters' | 'translations' | 'videos'>
|
|
308
|
-
> & {
|
|
311
|
+
> & {
|
|
312
|
+
episodes?: RawEpisode[];
|
|
313
|
+
season_lookup_id: Scalars['String'];
|
|
314
|
+
tv_show_id: Scalars['ID'];
|
|
315
|
+
};
|
|
309
316
|
|
|
310
317
|
export type RawSeasonCredits = SnakeCasedPropertiesDeep<Pick<Season, 'id' | 'cast' | 'crew'>>;
|
|
311
318
|
|