Skip to content

Commit 6430fc7

Browse files
getlargeAlan-Cha
authored andcommitted
add createSubscriptionsFromCallbacks option ; code cleaning
Signed-off-by: getlarge <[email protected]>
1 parent e34321d commit 6430fc7

File tree

12 files changed

+75
-94
lines changed

12 files changed

+75
-94
lines changed

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

Lines changed: 7 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 14 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 8 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ export async function createGraphQLSchema(
107107
? options.createSubscriptionsFromCallbacks
108108
: false
109109

110+
options.createSubscriptionsFromCallbacks =
111+
typeof options.createSubscriptionsFromCallbacks === 'boolean'
112+
? options.createSubscriptionsFromCallbacks
113+
: false
114+
110115
// Authentication options
111116
options.viewer = typeof options.viewer === 'boolean' ? options.viewer : true
112117
options.sendOAuthTokenInQuery =
@@ -245,8 +250,6 @@ async function translateOpenAPIToGraphQL(
245250

246251
preliminaryChecks(options, data)
247252

248-
// console.log('PREPROCESS OPENAPI', data)
249-
250253
/**
251254
* Create GraphQL fields for every operation and structure them based on their
252255
* characteristics (query vs. mutation, auth vs. non-auth).
@@ -258,6 +261,8 @@ async function translateOpenAPIToGraphQL(
258261
let authMutationFields = {}
259262
let authSubscriptionFields = {}
260263

264+
// todo parse data.callbacks to recompose subscription ?
265+
261266
Object.entries(data.operations).forEach(([operationId, operation]) => {
262267
translationLog(`Process operation '${operation.operationString}'...`)
263268

@@ -416,7 +421,7 @@ async function translateOpenAPIToGraphQL(
416421
mutationFields[saneFieldName] = field
417422
}
418423
}
419-
} else {
424+
} else if (operation.isSubscription) {
420425
// handle subscriptions from operation.callbacks
421426
// 1) cbName would be the subscription field name
422427
// each paths contained in operation.callbacks[cbName]
@@ -625,7 +630,7 @@ function getFieldForOperation(
625630

626631
if (operation.isSubscription) {
627632
const responseSchemaName = operation.responseDefinition
628-
? operation.responseDefinition.graphQLInputObjectTypeName
633+
? operation.responseDefinition.graphQLTypeName
629634
: null
630635

631636
const resolve = getPublishResolver({

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,10 +1075,10 @@ export function getEndpointCallbacks(
10751075
data: PreprocessingData
10761076
): { [key: string]: CallbackObject } {
10771077
const callbacks = {}
1078-
const endpoint: OperationObject = oas.paths[path][method]
1078+
const operation: OperationObject = oas.paths[path][method]
10791079

1080-
if (typeof endpoint.callbacks === 'object') {
1081-
let callbacksObject: CallbacksObject = endpoint.callbacks
1080+
if (typeof operation.callbacks === 'object') {
1081+
let callbacksObject: CallbacksObject = operation.callbacks
10821082
for (let callbackName in callbacksObject) {
10831083
if (typeof callbacksObject[callbackName] === 'object') {
10841084
let callbackObject: CallbackObject | ReferenceObject =
@@ -1092,12 +1092,9 @@ export function getEndpointCallbacks(
10921092
} else {
10931093
callbackObject = (callbackObject as any) as CallbackObject
10941094
}
1095-
// console.log("CHECK CALLBACK OBJ", callbackName, callbackObject)
1096-
10971095
// Make sure CallbackObject contains PathItemObject:
10981096
for (let expression in callbackObject) {
10991097
let pathItem: PathItemObject = callbackObject[expression]
1100-
// console.log("CHECK CALLBACK ITEM", expression, pathItem)
11011098
if (typeof (pathItem as ReferenceObject).$ref === 'string') {
11021099
pathItem = resolveRef(callbackObject[callbackName]['$ref'], oas)
11031100
} else {

0 commit comments

Comments
 (0)