Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ export class NetlifyGraphAuth {
this._accessToken = null;
};

findMissingAuthServices: any = findMissingAuthServices;
findMissingAuthServices = findMissingAuthServices;
}

export default NetlifyGraphAuth;
49 changes: 38 additions & 11 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
export function findMissingAuthServices(results: any) {
type error = {
extensions?: {
type: string;
graphQLField?: string;
};
};

type results = {
errors?: error[];
graphQLErrors?: error[];
};

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
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 [];
}
Expand All @@ -23,8 +44,14 @@ export function findMissingAuthServices(results: any) {
);

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<MissingAuthService>;

return missingServices;
}