@tmdb-graphql-api/resolvers 0.1.2-unstable.5 → 0.1.2-unstable.6

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/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.2-unstable.5",
4
+ "version": "0.1.2-unstable.6",
5
5
  "author": "Dylan Aubrey",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/badbatch/themoviedb-graphql-api",
@@ -26,16 +26,33 @@ export const buildObjArgsResolver =
26
26
  };
27
27
 
28
28
  const childLogger = logger.child(newCtx.data);
29
- childLogger.info(`Resolving ${fieldPath}`);
29
+ const loggingEnabled = !obj || fieldName === 'id';
30
+ const id = obj && 'id' in obj && obj.id ? obj.id : 'id' in args ? args.id : undefined;
31
+
32
+ const enrichLogMessage = (message: string) => {
33
+ const enrichedMessage = `${message} ${fieldPath}`;
34
+ return id ? `${enrichedMessage} ${String(id)}` : enrichedMessage;
35
+ };
36
+
37
+ if (loggingEnabled) {
38
+ childLogger.info(enrichLogMessage('Resolving'));
39
+ }
40
+
30
41
  const { data, errors, headers, source = 'api' } = await callback(obj, args, newCtx, info);
31
42
 
32
43
  if (errors?.length) {
33
- const message = `Failed to resolve ${fieldPath}`;
34
- childLogger.error(message, { errors });
44
+ const message = enrichLogMessage('Failed to resolve');
45
+
46
+ if (loggingEnabled) {
47
+ childLogger.error(message, { errors });
48
+ }
49
+
35
50
  throw new GraphQLError(message, { nodes: fieldNodes, originalError: errors[0] });
36
51
  }
37
52
 
38
- childLogger.info(`Successfully resolved ${fieldPath} from ${source}`);
53
+ if (loggingEnabled) {
54
+ childLogger.info(enrichLogMessage(`Successfully resolved from ${source}`));
55
+ }
39
56
 
40
57
  if (headers) {
41
58
  setCacheMetadata(fieldPath, headers);