Skip to content

Commit 15ed7f2

Browse files
committed
Improve evaluation script
Signed-off-by: Alan Cha <[email protected]>
1 parent 0daf771 commit 15ed7f2

File tree

6 files changed

+111
-94
lines changed

6 files changed

+111
-94
lines changed

packages/openapi-to-graphql/lib/index.js

+24-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/preprocessor.js

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/preprocessor.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/src/index.ts

+36-29
Original file line numberDiff line numberDiff line change
@@ -149,32 +149,39 @@ export function createGraphQLSchema<TSource, TContext, TArgs>(
149149
if (Array.isArray(spec)) {
150150
// Convert all non-OAS 3 into OAS 3
151151
Promise.all(
152-
spec.map(ele => {
152+
spec.map((ele) => {
153153
return Oas3Tools.getValidOAS3(ele)
154154
})
155-
).then(oass => {
156-
resolve(
157-
translateOpenAPIToGraphQL(
158-
oass,
159-
options as InternalOptions<TSource, TContext, TArgs>
155+
)
156+
.then((oass) => {
157+
resolve(
158+
translateOpenAPIToGraphQL(
159+
oass,
160+
options as InternalOptions<TSource, TContext, TArgs>
161+
)
160162
)
161-
)
162-
})
163+
})
164+
.catch((error) => {
165+
reject(error)
166+
})
163167
} else {
164168
/**
165169
* Check if the spec is a valid OAS 3
166170
* If the spec is OAS 2.0, attempt to translate it into 3, then try to
167171
* translate the spec into a GraphQL schema
168172
*/
169-
170-
Oas3Tools.getValidOAS3(spec).then(oas => {
171-
resolve(
172-
translateOpenAPIToGraphQL(
173-
[oas],
174-
options as InternalOptions<TSource, TContext, TArgs>
173+
Oas3Tools.getValidOAS3(spec)
174+
.then((oas) => {
175+
resolve(
176+
translateOpenAPIToGraphQL(
177+
[oas],
178+
options as InternalOptions<TSource, TContext, TArgs>
179+
)
175180
)
176-
)
177-
})
181+
})
182+
.catch((error) => {
183+
reject(error)
184+
})
178185
}
179186
})
180187
}
@@ -518,15 +525,15 @@ function translateOpenAPIToGraphQL<TSource, TContext, TArgs>(
518525
mutationFields = sortObject(mutationFields)
519526
subscriptionFields = sortObject(subscriptionFields)
520527
authQueryFields = sortObject(authQueryFields)
521-
Object.keys(authQueryFields).forEach(key => {
528+
Object.keys(authQueryFields).forEach((key) => {
522529
authQueryFields[key] = sortObject(authQueryFields[key])
523530
})
524531
authMutationFields = sortObject(authMutationFields)
525-
Object.keys(authMutationFields).forEach(key => {
532+
Object.keys(authMutationFields).forEach((key) => {
526533
authMutationFields[key] = sortObject(authMutationFields[key])
527534
})
528535
authSubscriptionFields = sortObject(authSubscriptionFields)
529-
Object.keys(authSubscriptionFields).forEach(key => {
536+
Object.keys(authSubscriptionFields).forEach((key) => {
530537
authSubscriptionFields[key] = sortObject(authSubscriptionFields[key])
531538
})
532539

@@ -719,13 +726,13 @@ function checkCustomResolversStructure<TSource, TContext, TArgs>(
719726
if (typeof customResolvers === 'object') {
720727
// Check that all OASs that are referenced in the customResolvers are provided
721728
Object.keys(customResolvers)
722-
.filter(title => {
729+
.filter((title) => {
723730
// If no OAS contains this title
724-
return !data.oass.some(oas => {
731+
return !data.oass.some((oas) => {
725732
return title === oas.info.title
726733
})
727734
})
728-
.forEach(title => {
735+
.forEach((title) => {
729736
handleWarning({
730737
mitigationType: MitigationTypes.CUSTOM_RESOLVER_UNKNOWN_OAS,
731738
message:
@@ -737,16 +744,16 @@ function checkCustomResolversStructure<TSource, TContext, TArgs>(
737744
})
738745

739746
// TODO: Only run the following test on OASs that exist. See previous check.
740-
Object.keys(customResolvers).forEach(title => {
747+
Object.keys(customResolvers).forEach((title) => {
741748
// Get all operations from a particular OAS
742-
const operations = Object.values(data.operations).filter(operation => {
749+
const operations = Object.values(data.operations).filter((operation) => {
743750
return title === operation.oas.info.title
744751
})
745752

746-
Object.keys(customResolvers[title]).forEach(path => {
747-
Object.keys(customResolvers[title][path]).forEach(method => {
753+
Object.keys(customResolvers[title]).forEach((path) => {
754+
Object.keys(customResolvers[title][path]).forEach((method) => {
748755
if (
749-
!operations.some(operation => {
756+
!operations.some((operation) => {
750757
return path === operation.path && method === operation.method
751758
})
752759
) {
@@ -775,7 +782,7 @@ function preliminaryChecks<TSource, TContext, TArgs>(
775782
data: PreprocessingData<TSource, TContext, TArgs>
776783
): void {
777784
// Check if OASs have unique titles
778-
const titles = data.oass.map(oas => {
785+
const titles = data.oass.map((oas) => {
779786
return oas.info.title
780787
})
781788

@@ -784,7 +791,7 @@ function preliminaryChecks<TSource, TContext, TArgs>(
784791
titles.filter((title, index) => {
785792
return titles.indexOf(title) !== index
786793
})
787-
).forEach(title => {
794+
).forEach((title) => {
788795
handleWarning({
789796
mitigationType: MitigationTypes.MULTIPLE_OAS_SAME_TITLE,
790797
message: `Multiple OAS share the same title '${title}'`,

0 commit comments

Comments
 (0)