@tmdb-graphql-api/resolvers 0.1.12 → 0.1.14

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.
Files changed (103) hide show
  1. package/dist/cjs/index.cjs +1 -1
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/esm/index.mjs +1 -1
  4. package/dist/esm/index.mjs.map +1 -1
  5. package/dist/production.analysis.txt +292 -292
  6. package/dist/types/cjs/helpers/buildArgsResolver.d.cts.map +1 -1
  7. package/dist/types/cjs/helpers/buildNoObjArgsResolver.d.cts.map +1 -1
  8. package/dist/types/cjs/helpers/buildObjArgsResolver.d.cts.map +1 -1
  9. package/dist/types/cjs/helpers/formatQueryParams.d.cts +1 -2
  10. package/dist/types/cjs/helpers/formatQueryParams.d.cts.map +1 -1
  11. package/dist/types/cjs/helpers/getAppendToResponseKeys.d.cts +2 -3
  12. package/dist/types/cjs/helpers/getAppendToResponseKeys.d.cts.map +1 -1
  13. package/dist/types/cjs/helpers/removeNullValues.d.cts +1 -1
  14. package/dist/types/cjs/helpers/removeNullValues.d.cts.map +1 -1
  15. package/dist/types/cjs/helpers/snakeCasePropNames.d.cts +1 -1
  16. package/dist/types/cjs/helpers/snakeCasePropNames.d.cts.map +1 -1
  17. package/dist/types/cjs/queries/certifications.d.cts +10 -10
  18. package/dist/types/cjs/queries/collection.d.cts +10 -6
  19. package/dist/types/cjs/queries/collection.d.cts.map +1 -1
  20. package/dist/types/cjs/queries/collectionImages.d.cts +4 -2
  21. package/dist/types/cjs/queries/collectionImages.d.cts.map +1 -1
  22. package/dist/types/cjs/queries/collectionTranslations.d.cts +4 -2
  23. package/dist/types/cjs/queries/collectionTranslations.d.cts.map +1 -1
  24. package/dist/types/cjs/queries/companyAlternativeNames.d.cts +4 -2
  25. package/dist/types/cjs/queries/companyAlternativeNames.d.cts.map +1 -1
  26. package/dist/types/cjs/queries/personCombinedCredits.d.cts +1 -1
  27. package/dist/types/cjs/queries/personExternalIds.d.cts +1 -1
  28. package/dist/types/cjs/queries/personMovieCredits.d.cts +1 -1
  29. package/dist/types/cjs/queries/personProfiles.d.cts +1 -1
  30. package/dist/types/cjs/queries/personTranslations.d.cts +1 -1
  31. package/dist/types/cjs/queries/personTvCredits.d.cts +2 -2
  32. package/dist/types/cjs/queries/season.d.cts +17 -4
  33. package/dist/types/cjs/queries/season.d.cts.map +1 -1
  34. package/dist/types/cjs/queries/seasonCredits.d.cts +9 -2
  35. package/dist/types/cjs/queries/seasonCredits.d.cts.map +1 -1
  36. package/dist/types/cjs/queries/seasonExternalIds.d.cts +9 -2
  37. package/dist/types/cjs/queries/seasonExternalIds.d.cts.map +1 -1
  38. package/dist/types/cjs/queries/seasonPosters.d.cts +9 -2
  39. package/dist/types/cjs/queries/seasonPosters.d.cts.map +1 -1
  40. package/dist/types/cjs/queries/seasonTranslations.d.cts +9 -2
  41. package/dist/types/cjs/queries/seasonTranslations.d.cts.map +1 -1
  42. package/dist/types/cjs/queries/seasonVideos.d.cts +9 -2
  43. package/dist/types/cjs/queries/seasonVideos.d.cts.map +1 -1
  44. package/dist/types/esm/helpers/buildArgsResolver.d.ts.map +1 -1
  45. package/dist/types/esm/helpers/buildNoObjArgsResolver.d.ts.map +1 -1
  46. package/dist/types/esm/helpers/buildObjArgsResolver.d.ts.map +1 -1
  47. package/dist/types/esm/helpers/formatQueryParams.d.ts +1 -2
  48. package/dist/types/esm/helpers/formatQueryParams.d.ts.map +1 -1
  49. package/dist/types/esm/helpers/getAppendToResponseKeys.d.ts +2 -3
  50. package/dist/types/esm/helpers/getAppendToResponseKeys.d.ts.map +1 -1
  51. package/dist/types/esm/helpers/removeNullValues.d.ts +1 -1
  52. package/dist/types/esm/helpers/removeNullValues.d.ts.map +1 -1
  53. package/dist/types/esm/helpers/snakeCasePropNames.d.ts +1 -1
  54. package/dist/types/esm/helpers/snakeCasePropNames.d.ts.map +1 -1
  55. package/dist/types/esm/queries/certifications.d.ts +10 -10
  56. package/dist/types/esm/queries/collection.d.ts +10 -6
  57. package/dist/types/esm/queries/collection.d.ts.map +1 -1
  58. package/dist/types/esm/queries/collectionImages.d.ts +4 -2
  59. package/dist/types/esm/queries/collectionImages.d.ts.map +1 -1
  60. package/dist/types/esm/queries/collectionTranslations.d.ts +4 -2
  61. package/dist/types/esm/queries/collectionTranslations.d.ts.map +1 -1
  62. package/dist/types/esm/queries/companyAlternativeNames.d.ts +4 -2
  63. package/dist/types/esm/queries/companyAlternativeNames.d.ts.map +1 -1
  64. package/dist/types/esm/queries/personCombinedCredits.d.ts +1 -1
  65. package/dist/types/esm/queries/personExternalIds.d.ts +1 -1
  66. package/dist/types/esm/queries/personMovieCredits.d.ts +1 -1
  67. package/dist/types/esm/queries/personProfiles.d.ts +1 -1
  68. package/dist/types/esm/queries/personTranslations.d.ts +1 -1
  69. package/dist/types/esm/queries/personTvCredits.d.ts +2 -2
  70. package/dist/types/esm/queries/season.d.ts +17 -4
  71. package/dist/types/esm/queries/season.d.ts.map +1 -1
  72. package/dist/types/esm/queries/seasonCredits.d.ts +9 -2
  73. package/dist/types/esm/queries/seasonCredits.d.ts.map +1 -1
  74. package/dist/types/esm/queries/seasonExternalIds.d.ts +9 -2
  75. package/dist/types/esm/queries/seasonExternalIds.d.ts.map +1 -1
  76. package/dist/types/esm/queries/seasonPosters.d.ts +9 -2
  77. package/dist/types/esm/queries/seasonPosters.d.ts.map +1 -1
  78. package/dist/types/esm/queries/seasonTranslations.d.ts +9 -2
  79. package/dist/types/esm/queries/seasonTranslations.d.ts.map +1 -1
  80. package/dist/types/esm/queries/seasonVideos.d.ts +9 -2
  81. package/dist/types/esm/queries/seasonVideos.d.ts.map +1 -1
  82. package/dist/types/tsconfig.build.tsbuildinfo +1 -1
  83. package/package.json +9 -9
  84. package/src/__testUtils__/helpers/buildResolveInfoArg.ts +8 -17
  85. package/src/__testUtils__/helpers/getChildField.ts +35 -0
  86. package/src/helpers/buildArgsResolver.ts +4 -1
  87. package/src/helpers/buildNoObjArgsResolver.ts +5 -1
  88. package/src/helpers/buildObjArgsResolver.ts +4 -5
  89. package/src/helpers/buildObjResolver.ts +3 -3
  90. package/src/helpers/createDefaultFieldResolver.ts +1 -1
  91. package/src/helpers/getAppendToResponseKeys.ts +31 -20
  92. package/src/helpers/removeNullValues.ts +2 -2
  93. package/src/helpers/snakeCasePropNames.ts +2 -2
  94. package/src/queries/episode.test.ts +4 -3
  95. package/src/queries/episode.ts +2 -2
  96. package/src/queries/movie.test.ts +4 -3
  97. package/src/queries/movie.ts +2 -2
  98. package/src/queries/person.test.ts +4 -3
  99. package/src/queries/person.ts +2 -2
  100. package/src/queries/season.test.ts +4 -3
  101. package/src/queries/season.ts +2 -2
  102. package/src/queries/tv.test.ts +4 -3
  103. package/src/queries/tv.ts +2 -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.1.12",
4
+ "version": "0.1.14",
5
5
  "author": "miami-man",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/badbatch/themoviedb-graphql-api",
@@ -29,19 +29,19 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@cachemap/core": "^5.2.7",
33
- "@cachemap/map": "^5.0.9",
34
- "@cachemap/reaper": "^5.1.3",
35
- "@graphql-box/connection-resolver": "^5.4.20",
36
- "@graphql-box/core": "^5.4.11",
32
+ "@cachemap/core": "^5.3.0",
33
+ "@cachemap/map": "^5.1.0",
34
+ "@cachemap/reaper": "^5.2.0",
35
+ "@graphql-box/connection-resolver": "5.4.23-unstable-12345.5",
36
+ "@graphql-box/core": "5.4.14-unstable-12345.5",
37
37
  "cacheability": "^4.0.27",
38
38
  "getta": "^1.0.21",
39
39
  "js-base64": "^3.6.0",
40
40
  "query-string": "^8.1.0",
41
41
  "type-fest": "^4.37.0",
42
42
  "winston": "^3.17.0",
43
- "@tmdb-graphql-api/rest-client": "0.0.19",
44
- "@tmdb-graphql-api/schema": "0.1.2"
43
+ "@tmdb-graphql-api/rest-client": "0.0.20",
44
+ "@tmdb-graphql-api/schema": "0.1.3"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@babel/runtime": "<8",
@@ -51,7 +51,7 @@
51
51
  },
52
52
  "devDependencies": {
53
53
  "@babel/runtime": "^7.23.2",
54
- "@graphql-box/helpers": "^5.4.11",
54
+ "@graphql-box/helpers": "5.4.14-unstable-12345.5",
55
55
  "@jest/globals": "^29.7.0",
56
56
  "@types/lodash-es": "^4.14.191",
57
57
  "core-js": "^3.33.1",
@@ -1,29 +1,20 @@
1
- import { type ParentNode, getChildFields, getName, getOperationDefinitions } from '@graphql-box/helpers';
1
+ import { getOperationDefinitions } from '@graphql-box/helpers';
2
2
  import { schema } from '@tmdb-graphql-api/schema';
3
- import { type FieldNode, type GraphQLObjectType, type GraphQLResolveInfo, parse } from 'graphql';
3
+ import { type GraphQLObjectType, type GraphQLResolveInfo, parse } from 'graphql';
4
+ import { getChildField } from './getChildField.ts';
4
5
 
5
6
  export const buildResolveInfoArgument = (request: string, path: string[]): GraphQLResolveInfo => {
6
7
  const ast = parse(request);
7
- const operationDefinitions = getOperationDefinitions(ast);
8
-
9
- const fieldNodes = path.reduce((nodes: ParentNode[], pathEntry) => {
10
- const node = nodes[0];
11
-
12
- if (!node) {
13
- return nodes;
14
- }
15
-
16
- return getChildFields(node, { name: pathEntry })?.map(({ fieldNode }) => fieldNode) ?? nodes;
17
- }, operationDefinitions) as FieldNode[];
18
-
19
- const fieldName = (fieldNodes[0] ? getName(fieldNodes[0]) : undefined) ?? '';
8
+ const operationDefinition = getOperationDefinitions(ast)[0]!;
9
+ const childField = getChildField(operationDefinition, path)!;
10
+ const fieldName = childField.name.value;
20
11
  const mockType = {};
21
12
 
22
13
  return {
23
14
  fieldName,
24
- fieldNodes,
15
+ fieldNodes: [childField],
25
16
  fragments: {},
26
- operation: operationDefinitions[0],
17
+ operation: operationDefinition,
27
18
  parentType: mockType as GraphQLObjectType,
28
19
  path: { key: 0, prev: undefined, typename: '' },
29
20
  returnType: mockType as GraphQLObjectType,
@@ -0,0 +1,35 @@
1
+ import { type ParentNode, isKind } from '@graphql-box/helpers';
2
+ import { type FieldNode, type InlineFragmentNode, Kind } from 'graphql';
3
+
4
+ export const getChildField = (node: ParentNode, names: string[] = []): FieldNode | undefined => {
5
+ if (!node.selectionSet || names.length === 0) {
6
+ return;
7
+ }
8
+
9
+ let fieldNode: FieldNode | undefined;
10
+ const [firstName, ...restNames] = names;
11
+
12
+ for (const selection of node.selectionSet.selections) {
13
+ if (isKind<FieldNode>(selection, Kind.FIELD) && selection.name.value === firstName) {
14
+ if (restNames.length > 0) {
15
+ const result = getChildField(selection, restNames);
16
+
17
+ if (result) {
18
+ fieldNode = result;
19
+ }
20
+ } else {
21
+ fieldNode = selection;
22
+ }
23
+ }
24
+
25
+ if (isKind<InlineFragmentNode>(selection, Kind.INLINE_FRAGMENT)) {
26
+ const result = getChildField(selection, names);
27
+
28
+ if (result) {
29
+ fieldNode = result;
30
+ }
31
+ }
32
+ }
33
+
34
+ return fieldNode;
35
+ };
@@ -38,6 +38,9 @@ export const buildArgsResolver =
38
38
  throw new GraphQLError(message, { nodes: fieldNodes, originalError: errors[0] });
39
39
  }
40
40
 
41
- setCacheMetadata(fieldName, headers);
41
+ if (headers.has('cache-control')) {
42
+ setCacheMetadata(data, info, headers);
43
+ }
44
+
42
45
  return data;
43
46
  };
@@ -20,6 +20,7 @@ export const buildNoObjArgsResolver =
20
20
  ...ctx,
21
21
  data: {
22
22
  ...ctx.data,
23
+ args: undefined,
23
24
  fieldPath,
24
25
  resolverRequestId: crypto.randomUUID(),
25
26
  resolverType: ResolverType.OptsObjAndArgs,
@@ -36,6 +37,9 @@ export const buildNoObjArgsResolver =
36
37
  throw new GraphQLError(message, { nodes: fieldNodes, originalError: errors[0] });
37
38
  }
38
39
 
39
- setCacheMetadata(fieldPath, headers);
40
+ if (headers.has('cache-control')) {
41
+ setCacheMetadata(data, info, headers);
42
+ }
43
+
40
44
  return data;
41
45
  };
@@ -17,13 +17,13 @@ export const buildObjArgsResolver =
17
17
  async (obj: Obj | undefined, args: Args, ctx: Context, info: GraphQLResolveInfo) => {
18
18
  const { logger, setCacheMetadata } = ctx;
19
19
  const { fieldName, fieldNodes } = info;
20
- const fieldPath = obj ? `${parentFieldName}.${fieldName}` : parentFieldName;
20
+ const id = obj && 'id' in obj && obj.id ? obj.id : 'id' in args ? args.id : undefined;
21
21
 
22
22
  const newCtx = {
23
23
  ...ctx,
24
24
  data: {
25
25
  ...ctx.data,
26
- args,
26
+ args: { ...args, id },
27
27
  fieldPath: parentFieldName,
28
28
  resolverRequestId: crypto.randomUUID(),
29
29
  resolverType: ResolverType.ObjAndArgs,
@@ -31,7 +31,6 @@ export const buildObjArgsResolver =
31
31
  };
32
32
 
33
33
  const childLogger = logger.child(newCtx.data);
34
- const id = obj && 'id' in obj && obj.id ? obj.id : 'id' in args ? args.id : undefined;
35
34
 
36
35
  const enrichLogMessage = (message: string) => {
37
36
  const enrichedMessage = `${message} ${parentFieldName}`;
@@ -57,8 +56,8 @@ export const buildObjArgsResolver =
57
56
  throw new GraphQLError(message, { nodes: fieldNodes, originalError: errors[0] });
58
57
  }
59
58
 
60
- if (headers) {
61
- setCacheMetadata(fieldPath, headers);
59
+ if (headers?.has('cache-control')) {
60
+ setCacheMetadata(data, info, headers);
62
61
  }
63
62
 
64
63
  return data;
@@ -21,8 +21,8 @@ export const buildObjResolver =
21
21
  ...ctx,
22
22
  data: {
23
23
  ...ctx.data,
24
+ args: obj?.id ? { id: obj.id } : undefined,
24
25
  fieldPath,
25
- parentFieldId: obj?.id,
26
26
  resolverRequestId: crypto.randomUUID(),
27
27
  resolverType: ResolverType.Obj,
28
28
  },
@@ -45,8 +45,8 @@ export const buildObjResolver =
45
45
  throw new GraphQLError(message, { nodes: fieldNodes, originalError: errors[0] });
46
46
  }
47
47
 
48
- if (headers) {
49
- setCacheMetadata(fieldPath, headers);
48
+ if (headers?.has('cache-control')) {
49
+ setCacheMetadata(data, info, headers);
50
50
  }
51
51
 
52
52
  return data;
@@ -8,7 +8,7 @@ export const createDefaultFieldResolver =
8
8
  Context extends PlainObject = PlainObject,
9
9
  Args extends PlainObject = PlainObject
10
10
  >(): GraphQLFieldResolver<Source, Context, Args> =>
11
- (object, _arguments, _context, { fieldNodes }) => {
11
+ (object, _arguments, _context, { fieldNodes }): unknown => {
12
12
  const currentField = fieldNodes[0]!;
13
13
  const { value: name } = currentField.name;
14
14
 
@@ -1,28 +1,39 @@
1
- import { type FragmentDefinitionNodeMap } from '@graphql-box/core';
2
- import { getChildFields, getName } from '@graphql-box/helpers';
3
- import { type FieldNode } from 'graphql';
1
+ import { isKind } from '@graphql-box/helpers';
2
+ import { type FieldNode, type InlineFragmentNode, Kind } from 'graphql';
4
3
 
5
4
  export const getAppendToResponseKeys = (
6
- parentFieldNode: FieldNode,
7
- appendToResponse: Record<string, string>,
8
- fragmentDefinitions?: FragmentDefinitionNodeMap
9
- ) =>
10
- (getChildFields(parentFieldNode, { fragmentDefinitions }) ?? []).reduce((acc: string[], { fieldNode }) => {
11
- const name = getName(fieldNode);
12
-
13
- if (!name) {
14
- return acc;
15
- }
5
+ node: FieldNode | InlineFragmentNode,
6
+ appendToResponseRecord: Record<string, string>
7
+ ): string[] => {
8
+ if (!node.selectionSet) {
9
+ return [];
10
+ }
11
+
12
+ const appendToResponseKeys: string[] = [];
16
13
 
17
- const key = appendToResponse[name];
14
+ for (const selection of node.selectionSet.selections) {
15
+ if (isKind<FieldNode>(selection, Kind.FIELD)) {
16
+ const appendToResponseKey = appendToResponseRecord[selection.name.value];
18
17
 
19
- if (!key) {
20
- return acc;
18
+ if (!appendToResponseKey) {
19
+ continue;
20
+ }
21
+
22
+ if (!appendToResponseKeys.includes(appendToResponseKey)) {
23
+ appendToResponseKeys.push(appendToResponseKey);
24
+ }
21
25
  }
22
26
 
23
- if (!acc.includes(key)) {
24
- acc.push(key);
27
+ if (isKind<InlineFragmentNode>(selection, Kind.INLINE_FRAGMENT)) {
28
+ const inlineFragmentKeys = getAppendToResponseKeys(selection, appendToResponseRecord);
29
+
30
+ for (const inlineFragmentKey of inlineFragmentKeys) {
31
+ if (!appendToResponseKeys.includes(inlineFragmentKey)) {
32
+ appendToResponseKeys.push(inlineFragmentKey);
33
+ }
34
+ }
25
35
  }
36
+ }
26
37
 
27
- return acc;
28
- }, []);
38
+ return appendToResponseKeys;
39
+ };
@@ -1,7 +1,7 @@
1
1
  import { type PlainObject } from '@graphql-box/core';
2
2
 
3
- export const removeNullValues = <P extends PlainObject>(props: P) =>
4
- Object.keys(props).reduce<PlainObject>((acc, propName) => {
3
+ export const removeNullValues = <P extends PlainObject<unknown>>(props: P) =>
4
+ Object.keys(props).reduce<PlainObject<unknown>>((acc, propName) => {
5
5
  if (props[propName] === null) {
6
6
  return acc;
7
7
  }
@@ -2,8 +2,8 @@ import { type PlainObject } from '@graphql-box/core';
2
2
  import { snakeCase } from 'lodash-es';
3
3
  import { type SnakeCasedPropertiesDeep } from 'type-fest';
4
4
 
5
- export const snakeCasePropNames = <P extends PlainObject>(props: P) =>
6
- Object.keys(props).reduce<PlainObject>((snakeCased, propName) => {
5
+ export const snakeCasePropNames = <P extends PlainObject<unknown>>(props: P) =>
6
+ Object.keys(props).reduce<PlainObject<unknown>>((snakeCased, propName) => {
7
7
  snakeCased[snakeCase(propName)] = props[propName];
8
8
  return snakeCased;
9
9
  }, {}) as SnakeCasedPropertiesDeep<P>;
@@ -1,5 +1,5 @@
1
1
  import { type PlainArray } from '@graphql-box/core';
2
- import { getChildFields, getOperationDefinitions } from '@graphql-box/helpers';
2
+ import { getOperationDefinitions } from '@graphql-box/helpers';
3
3
  import { jest } from '@jest/globals';
4
4
  import { EPISODE_PATH, type ShortcutMethodNames } from '@tmdb-graphql-api/rest-client';
5
5
  import { episodeDetails as episodeDetailsQuery } from '@tmdb-graphql-api/test-utils/requests/queries/episode/details.ts';
@@ -11,6 +11,7 @@ import { type GraphQLResolveInfo, OperationTypeNode, parse } from 'graphql';
11
11
  import { buildEndpoint } from '../__testUtils__/helpers/buildEndpoint.ts';
12
12
  import { createMockLogger } from '../__testUtils__/helpers/createMockLogger.ts';
13
13
  import { createRestClient } from '../__testUtils__/helpers/createRestClient.ts';
14
+ import { getChildField } from '../__testUtils__/helpers/getChildField.ts';
14
15
  import { EPISODE } from '../constants.ts';
15
16
  import { encodeId } from '../helpers/encodeId.ts';
16
17
  import { type Context } from '../types.ts';
@@ -45,7 +46,7 @@ describe('resolveEpisode >', () => {
45
46
 
46
47
  it('should return the correct episode details', async () => {
47
48
  const operationDefinition = getOperationDefinitions(parse(episodeDetailsQuery()), OperationTypeNode.QUERY)[0]!;
48
- const { fieldNode } = getChildFields(operationDefinition, { name: EPISODE })![0]!;
49
+ const fieldNode = getChildField(operationDefinition, [EPISODE]);
49
50
  const info = { fieldNodes: [fieldNode] } as unknown as GraphQLResolveInfo;
50
51
 
51
52
  await expect(
@@ -55,7 +56,7 @@ describe('resolveEpisode >', () => {
55
56
 
56
57
  it('should request the correct resources when append to response fields are found', async () => {
57
58
  const operationDefinition = getOperationDefinitions(parse(episodeDetailsLgQuery()), OperationTypeNode.QUERY)[0]!;
58
- const { fieldNode } = getChildFields(operationDefinition, { name: EPISODE })![0]!;
59
+ const fieldNode = getChildField(operationDefinition, [EPISODE]);
59
60
  const info = { fieldNodes: [fieldNode] } as unknown as GraphQLResolveInfo;
60
61
 
61
62
  const episodeFetchMock = jest
@@ -24,7 +24,7 @@ export const resolveEpisode = buildObjArgsResolver<
24
24
  | (EnrichedRawEpisodeWithAppendToResponse & { __headers?: Headers })
25
25
  | EnrichedRawEpisodeWithAppendToResponse[keyof EnrichedRawEpisodeWithAppendToResponse]
26
26
  >(EPISODE, async (obj, args, ctx, info) => {
27
- const { data: ctxData, fragmentDefinitions, languageCode, restClient } = ctx;
27
+ const { data: ctxData, languageCode, restClient } = ctx;
28
28
  const { fieldName, fieldNodes } = info;
29
29
  const typedFieldName = snakeCase(fieldName) as keyof RawEpisode;
30
30
  const { episodeNumber, id, seasonNumber } = getTvIdSeasonAndEpisode(obj, args);
@@ -39,7 +39,7 @@ export const resolveEpisode = buildObjArgsResolver<
39
39
  };
40
40
  }
41
41
 
42
- const appendToResponseKeys = getAppendToResponseKeys(fieldNodes[0]!, appendToResponse, fragmentDefinitions);
42
+ const appendToResponseKeys = getAppendToResponseKeys(fieldNodes[0]!, appendToResponse);
43
43
 
44
44
  const { data, errors, headers } = await restClient.episode<EnrichedRawEpisodeWithAppendToResponse>(
45
45
  {
@@ -1,5 +1,5 @@
1
1
  import { type PlainArray } from '@graphql-box/core';
2
- import { getChildFields, getOperationDefinitions } from '@graphql-box/helpers';
2
+ import { getOperationDefinitions } from '@graphql-box/helpers';
3
3
  import { jest } from '@jest/globals';
4
4
  import { MOVIE_PATH, type ShortcutMethodNames } from '@tmdb-graphql-api/rest-client';
5
5
  import { movieDetails as movieDetailsQuery } from '@tmdb-graphql-api/test-utils/requests/queries/movie/details.ts';
@@ -11,6 +11,7 @@ import { type GraphQLResolveInfo, OperationTypeNode, parse } from 'graphql';
11
11
  import { buildEndpoint } from '../__testUtils__/helpers/buildEndpoint.ts';
12
12
  import { createMockLogger } from '../__testUtils__/helpers/createMockLogger.ts';
13
13
  import { createRestClient } from '../__testUtils__/helpers/createRestClient.ts';
14
+ import { getChildField } from '../__testUtils__/helpers/getChildField.ts';
14
15
  import { MOVIE } from '../constants.ts';
15
16
  import { type Context } from '../types.ts';
16
17
  import { resolveMovie } from './movie.ts';
@@ -44,14 +45,14 @@ describe('resolveMovie >', () => {
44
45
 
45
46
  it('should return the correct movie details', async () => {
46
47
  const operationDefinition = getOperationDefinitions(parse(movieDetailsQuery()), OperationTypeNode.QUERY)[0]!;
47
- const { fieldNode } = getChildFields(operationDefinition, { name: MOVIE })![0]!;
48
+ const fieldNode = getChildField(operationDefinition, [MOVIE]);
48
49
  const info = { fieldNodes: [fieldNode] } as unknown as GraphQLResolveInfo;
49
50
  await expect(resolveMovie(undefined, { id: String(id) }, context, info)).resolves.toMatchSnapshot();
50
51
  });
51
52
 
52
53
  it('should request the correct resources when append to response fields are found', async () => {
53
54
  const operationDefinition = getOperationDefinitions(parse(movieDetailsLgQuery()), OperationTypeNode.QUERY)[0]!;
54
- const { fieldNode } = getChildFields(operationDefinition, { name: MOVIE })![0]!;
55
+ const fieldNode = getChildField(operationDefinition, [MOVIE]);
55
56
  const info = { fieldNodes: [fieldNode] } as unknown as GraphQLResolveInfo;
56
57
 
57
58
  const movieFetchMock = jest
@@ -51,7 +51,7 @@ export const resolveMovie = buildObjArgsResolver<
51
51
  | (RawMovieWithAppendToResponse & { __headers?: Headers })
52
52
  | RawMovieWithAppendToResponse[keyof RawMovieWithAppendToResponse]
53
53
  >(MOVIE, async (obj, args, ctx, info) => {
54
- const { data: ctxData, fragmentDefinitions, languageCode, restClient } = ctx;
54
+ const { data: ctxData, languageCode, restClient } = ctx;
55
55
  const { fieldName, fieldNodes } = info;
56
56
  const typedFieldName = snakeCase(fieldName) as keyof RawMovie;
57
57
 
@@ -63,7 +63,7 @@ export const resolveMovie = buildObjArgsResolver<
63
63
  }
64
64
 
65
65
  const id = obj ? obj.id : args.id;
66
- const appendToResponseKeys = getAppendToResponseKeys(fieldNodes[0]!, appendToResponse, fragmentDefinitions);
66
+ const appendToResponseKeys = getAppendToResponseKeys(fieldNodes[0]!, appendToResponse);
67
67
 
68
68
  const { data, errors, headers } = await restClient.movie<RawMovieWithAppendToResponse>(
69
69
  {
@@ -1,5 +1,5 @@
1
1
  import { type PlainArray } from '@graphql-box/core';
2
- import { getChildFields, getOperationDefinitions } from '@graphql-box/helpers';
2
+ import { getOperationDefinitions } from '@graphql-box/helpers';
3
3
  import { jest } from '@jest/globals';
4
4
  import { PERSON_PATH, type ShortcutMethodNames } from '@tmdb-graphql-api/rest-client';
5
5
  import { personDetails as personDetailsQuery } from '@tmdb-graphql-api/test-utils/requests/queries/person/details.ts';
@@ -11,6 +11,7 @@ import { type GraphQLResolveInfo, OperationTypeNode, parse } from 'graphql';
11
11
  import { buildEndpoint } from '../__testUtils__/helpers/buildEndpoint.ts';
12
12
  import { createMockLogger } from '../__testUtils__/helpers/createMockLogger.ts';
13
13
  import { createRestClient } from '../__testUtils__/helpers/createRestClient.ts';
14
+ import { getChildField } from '../__testUtils__/helpers/getChildField.ts';
14
15
  import { PERSON } from '../constants.ts';
15
16
  import { type Context } from '../types.ts';
16
17
  import { resolvePerson } from './person.ts';
@@ -44,14 +45,14 @@ describe('resolvePerson >', () => {
44
45
 
45
46
  it('should return the correct person details', async () => {
46
47
  const operationDefinition = getOperationDefinitions(parse(personDetailsQuery()), OperationTypeNode.QUERY)[0]!;
47
- const { fieldNode } = getChildFields(operationDefinition, { name: PERSON })![0]!;
48
+ const fieldNode = getChildField(operationDefinition, [PERSON]);
48
49
  const info = { fieldNodes: [fieldNode] } as unknown as GraphQLResolveInfo;
49
50
  await expect(resolvePerson(undefined, { id: String(id) }, context, info)).resolves.toMatchSnapshot();
50
51
  });
51
52
 
52
53
  it('should request the correct resources when append to response fields are found', async () => {
53
54
  const operationDefinition = getOperationDefinitions(parse(personDetailsLgQuery()), OperationTypeNode.QUERY)[0]!;
54
- const { fieldNode } = getChildFields(operationDefinition, { name: PERSON })![0]!;
55
+ const fieldNode = getChildField(operationDefinition, [PERSON]);
55
56
  const info = { fieldNodes: [fieldNode] } as unknown as GraphQLResolveInfo;
56
57
 
57
58
  const personFetchMock = jest
@@ -31,7 +31,7 @@ export const resolvePerson = buildObjArgsResolver<
31
31
  | (RawPersonWithAppendToResponse & { __headers?: Headers })
32
32
  | RawPersonWithAppendToResponse[keyof RawPersonWithAppendToResponse]
33
33
  >(PERSON, async (obj, args, ctx, info) => {
34
- const { data: ctxData, fragmentDefinitions, languageCode, restClient } = ctx;
34
+ const { data: ctxData, languageCode, restClient } = ctx;
35
35
  const { fieldName, fieldNodes } = info;
36
36
  const typedFieldName = snakeCase(fieldName) as keyof RawPerson;
37
37
 
@@ -43,7 +43,7 @@ export const resolvePerson = buildObjArgsResolver<
43
43
  }
44
44
 
45
45
  const id = obj ? obj.id : args.id;
46
- const appendToResponseKeys = getAppendToResponseKeys(fieldNodes[0]!, appendToResponse, fragmentDefinitions);
46
+ const appendToResponseKeys = getAppendToResponseKeys(fieldNodes[0]!, appendToResponse);
47
47
 
48
48
  const { data, errors, headers } = await restClient.person<RawPersonWithAppendToResponse>(
49
49
  {
@@ -1,5 +1,5 @@
1
1
  import { type PlainArray } from '@graphql-box/core';
2
- import { getChildFields, getOperationDefinitions } from '@graphql-box/helpers';
2
+ import { getOperationDefinitions } from '@graphql-box/helpers';
3
3
  import { jest } from '@jest/globals';
4
4
  import { SEASON_PATH, type ShortcutMethodNames } from '@tmdb-graphql-api/rest-client';
5
5
  import { seasonDetails as seasonDetailsQuery } from '@tmdb-graphql-api/test-utils/requests/queries/season/details.ts';
@@ -11,6 +11,7 @@ import { type GraphQLResolveInfo, OperationTypeNode, parse } from 'graphql';
11
11
  import { buildEndpoint } from '../__testUtils__/helpers/buildEndpoint.ts';
12
12
  import { createMockLogger } from '../__testUtils__/helpers/createMockLogger.ts';
13
13
  import { createRestClient } from '../__testUtils__/helpers/createRestClient.ts';
14
+ import { getChildField } from '../__testUtils__/helpers/getChildField.ts';
14
15
  import { SEASON } from '../constants.ts';
15
16
  import { encodeId } from '../helpers/encodeId.ts';
16
17
  import { type Context } from '../types.ts';
@@ -45,7 +46,7 @@ describe('resolveSeason >', () => {
45
46
 
46
47
  it('should return the correct season details', async () => {
47
48
  const operationDefinition = getOperationDefinitions(parse(seasonDetailsQuery()), OperationTypeNode.QUERY)[0]!;
48
- const { fieldNode } = getChildFields(operationDefinition, { name: SEASON })![0]!;
49
+ const fieldNode = getChildField(operationDefinition, [SEASON]);
49
50
  const info = { fieldNodes: [fieldNode] } as unknown as GraphQLResolveInfo;
50
51
 
51
52
  await expect(
@@ -55,7 +56,7 @@ describe('resolveSeason >', () => {
55
56
 
56
57
  it('should request the correct resources when append to response fields are found', async () => {
57
58
  const operationDefinition = getOperationDefinitions(parse(seasonDetailsLgQuery()), OperationTypeNode.QUERY)[0]!;
58
- const { fieldNode } = getChildFields(operationDefinition, { name: SEASON })![0]!;
59
+ const fieldNode = getChildField(operationDefinition, [SEASON]);
59
60
  const info = { fieldNodes: [fieldNode] } as unknown as GraphQLResolveInfo;
60
61
 
61
62
  const seasonFetchMock = jest
@@ -34,7 +34,7 @@ export const resolveSeason = buildObjArgsResolver<
34
34
  | (EnrichedRawSeasonWithAppendToResponse & { __headers?: Headers })
35
35
  | EnrichedRawSeasonWithAppendToResponse[keyof EnrichedRawSeasonWithAppendToResponse]
36
36
  >(SEASON, async (obj, args, ctx, info) => {
37
- const { data: ctxData, fragmentDefinitions, languageCode, restClient } = ctx;
37
+ const { data: ctxData, languageCode, restClient } = ctx;
38
38
  const { fieldName, fieldNodes } = info;
39
39
  const typedFieldName = snakeCase(fieldName) as keyof RawSeason;
40
40
  const { id, seasonNumber } = getTvIdSeasonAndEpisode(obj, args);
@@ -46,7 +46,7 @@ export const resolveSeason = buildObjArgsResolver<
46
46
  };
47
47
  }
48
48
 
49
- const appendToResponseKeys = getAppendToResponseKeys(fieldNodes[0]!, appendToResponse, fragmentDefinitions);
49
+ const appendToResponseKeys = getAppendToResponseKeys(fieldNodes[0]!, appendToResponse);
50
50
 
51
51
  const { data, errors, headers } = await restClient.season<EnrichedRawSeasonWithAppendToResponse>(
52
52
  {
@@ -1,5 +1,5 @@
1
1
  import { type PlainArray } from '@graphql-box/core';
2
- import { getChildFields, getOperationDefinitions } from '@graphql-box/helpers';
2
+ import { getOperationDefinitions } from '@graphql-box/helpers';
3
3
  import { jest } from '@jest/globals';
4
4
  import { type ShortcutMethodNames, TV_PATH } from '@tmdb-graphql-api/rest-client';
5
5
  import { tvDetails as tvDetailsQuery } from '@tmdb-graphql-api/test-utils/requests/queries/tv/details.ts';
@@ -11,6 +11,7 @@ import { type GraphQLResolveInfo, OperationTypeNode, parse } from 'graphql';
11
11
  import { buildEndpoint } from '../__testUtils__/helpers/buildEndpoint.ts';
12
12
  import { createMockLogger } from '../__testUtils__/helpers/createMockLogger.ts';
13
13
  import { createRestClient } from '../__testUtils__/helpers/createRestClient.ts';
14
+ import { getChildField } from '../__testUtils__/helpers/getChildField.ts';
14
15
  import { TV } from '../constants.ts';
15
16
  import { type Context } from '../types.ts';
16
17
  import { resolveTv } from './tv.ts';
@@ -44,14 +45,14 @@ describe('resolveTv >', () => {
44
45
 
45
46
  it('should return the correct tv details', async () => {
46
47
  const operationDefinition = getOperationDefinitions(parse(tvDetailsQuery()), OperationTypeNode.QUERY)[0]!;
47
- const { fieldNode } = getChildFields(operationDefinition, { name: TV })![0]!;
48
+ const fieldNode = getChildField(operationDefinition, [TV]);
48
49
  const info = { fieldNodes: [fieldNode] } as unknown as GraphQLResolveInfo;
49
50
  await expect(resolveTv(undefined, { id: String(id) }, context, info)).resolves.toMatchSnapshot();
50
51
  });
51
52
 
52
53
  it('should request the correct resources when append to response fields are found', async () => {
53
54
  const operationDefinition = getOperationDefinitions(parse(tvDetailsLgQuery()), OperationTypeNode.QUERY)[0]!;
54
- const { fieldNode } = getChildFields(operationDefinition, { name: TV })![0]!;
55
+ const fieldNode = getChildField(operationDefinition, [TV]);
55
56
  const info = { fieldNodes: [fieldNode] } as unknown as GraphQLResolveInfo;
56
57
 
57
58
  const tvFetchMock = jest
package/src/queries/tv.ts CHANGED
@@ -52,7 +52,7 @@ export const resolveTv = buildObjArgsResolver<
52
52
  QueryTvArgs,
53
53
  (RawTvWithAppendToResponse & { __headers?: Headers }) | RawTvWithAppendToResponse[keyof RawTvWithAppendToResponse]
54
54
  >(TV, async (obj, args, ctx, info) => {
55
- const { data: ctxData, fragmentDefinitions, languageCode, restClient } = ctx;
55
+ const { data: ctxData, languageCode, restClient } = ctx;
56
56
  const { fieldName, fieldNodes } = info;
57
57
  const typedFieldName = snakeCase(fieldName) as keyof RawTv;
58
58
 
@@ -64,7 +64,7 @@ export const resolveTv = buildObjArgsResolver<
64
64
  }
65
65
 
66
66
  const id = obj ? obj.id : args.id;
67
- const appendToResponseKeys = getAppendToResponseKeys(fieldNodes[0]!, appendToResponse, fragmentDefinitions);
67
+ const appendToResponseKeys = getAppendToResponseKeys(fieldNodes[0]!, appendToResponse);
68
68
 
69
69
  const { data, errors, headers } = await restClient.tv<RawTvWithAppendToResponse>(
70
70
  {