From 835a2521a5c097d5bfe2764adef19d9268e521a2 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Thu, 21 Jul 2022 19:55:02 -0700 Subject: [PATCH 1/3] Type findMissingAuthServices --- package.json | 3 ++- src/auth.ts | 2 +- src/helpers.ts | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 40a10b9..7b4b7df 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "build": "tsc", "clean": "mkdir -p dist && rm -r dist", "prepare": "npm run build", - "prettier": "prettier --write \"src/**/*.ts\"" + "prettier": "prettier --write \"src/**/*.ts\"", + "release": "yarn build && npm publish" }, "keywords": [], "author": "Netlify Inc.", diff --git a/src/auth.ts b/src/auth.ts index a09fba1..f8c0d5e 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -1202,7 +1202,7 @@ export class NetlifyGraphAuth { this._accessToken = null; }; - findMissingAuthServices: any = findMissingAuthServices; + findMissingAuthServices = findMissingAuthServices; } export default NetlifyGraphAuth; diff --git a/src/helpers.ts b/src/helpers.ts index 4b9f60d..f5947d8 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -1,4 +1,16 @@ -export function findMissingAuthServices(results: any) { +type error = { + extensions?: { + type: string; + graphQLField?: string; + } +} + +type results = { + errors?: error[]; + graphQLErrors?: error[]; +}; + +export function findMissingAuthServices(results: results): string[] { /* Detect and normalize between: 1. The full graphql result 2. The `result.errors` of a graphql result @@ -23,7 +35,7 @@ export function findMissingAuthServices(results: any) { ); const missingServices = missingServiceErrors - .map((error) => error.extensions.graphQLField) + .map((error) => error?.extensions?.graphQLField!) .filter(Boolean); return missingServices; From 752cb8e8d0bbd4c61ca519ef134c189bb8c9cd80 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Thu, 21 Jul 2022 20:04:51 -0700 Subject: [PATCH 2/3] fix types --- src/helpers.ts | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index f5947d8..be4a67c 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -2,30 +2,35 @@ type error = { extensions?: { type: string; graphQLField?: string; - } -} + }; +}; type results = { errors?: error[]; graphQLErrors?: error[]; }; -export function findMissingAuthServices(results: results): string[] { +export function findMissingAuthServices(results: results | error[]): string[] { /* Detect and normalize between: 1. The full graphql result 2. The `result.errors` of a graphql result 3. Apollo's GraphQL error structure */ - let errors = - results && - // Full GraphQL result - (results.errors || + let errors: error[] | undefined; + + if (Array.isArray(results)) { + errors = results; + } else if ( + results != null && + ('errors' in results || 'graphQLErrors' in results) + ) { + errors = + // Full GraphQL result + results.errors || // Apollo error - results.graphQLErrors || - // Possibly result.errors - results); + results.graphQLErrors; + } - // If errors aren't an array, bail if (!Array.isArray(errors)) { return []; } From 6fa46983513249c52fd740b5495ffc42c299fdc4 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Thu, 21 Jul 2022 20:20:08 -0700 Subject: [PATCH 3/3] return `{graphQLField: 'field'}` --- src/helpers.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index be4a67c..8e35e22 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -10,7 +10,11 @@ type results = { graphQLErrors?: error[]; }; -export function findMissingAuthServices(results: results | error[]): string[] { +type MissingAuthService = {graphQLField: string}; + +export function findMissingAuthServices( + results: results | error[], +): MissingAuthService[] { /* Detect and normalize between: 1. The full graphql result 2. The `result.errors` of a graphql result @@ -40,8 +44,14 @@ export function findMissingAuthServices(results: results | error[]): string[] { ); const missingServices = missingServiceErrors - .map((error) => error?.extensions?.graphQLField!) - .filter(Boolean); + .map((error) => { + const field = error?.extensions?.graphQLField; + + if (field != null) { + return {graphQLField: field}; + } + }) + .filter(Boolean) as Array; return missingServices; }