Skip to content

Commit d71ee6e

Browse files
dotansimhaAlan-Cha
authored andcommitted
Expose preprocessing data
Signed-off-by: Dotan Simha <[email protected]>
1 parent 15ed7f2 commit d71ee6e

File tree

12 files changed

+125
-1430
lines changed

12 files changed

+125
-1430
lines changed

packages/openapi-to-graphql-cli/package-lock.json

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

packages/openapi-to-graphql/lib/index.d.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@
2727
import { Options, Report } from './types/options';
2828
import { Oas3 } from './types/oas3';
2929
import { Oas2 } from './types/oas2';
30+
import { PreprocessingData } from './types/preprocessing_data';
3031
import { GraphQLSchema } from 'graphql';
31-
declare type Result = {
32+
declare type Result<TSource, TContext, TArgs> = {
3233
schema: GraphQLSchema;
3334
report: Report;
35+
data: PreprocessingData<TSource, TContext, TArgs>;
3436
};
3537
/**
3638
* Creates a GraphQL interface from the given OpenAPI Specification (2 or 3).
3739
*/
38-
export declare function createGraphQLSchema<TSource, TContext, TArgs>(spec: Oas3 | Oas2 | (Oas3 | Oas2)[], options?: Options<TSource, TContext, TArgs>): Promise<Result>;
40+
export declare function createGraphQLSchema<TSource, TContext, TArgs>(spec: Oas3 | Oas2 | (Oas3 | Oas2)[], options?: Options<TSource, TContext, TArgs>): Promise<Result<TSource, TContext, TArgs>>;
3941
export { sanitize, CaseStyle } from './oas_3_tools';
4042
export { GraphQLOperationType } from './types/graphql';

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

+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/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

+4
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/lib/types/operation.d.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { OperationObject } from './oas3';
12
/**
23
* Type definitions for the objects created during preprocessing for every
34
* operation in the OAS.
@@ -40,6 +41,10 @@ export declare type DataDefinition = {
4041
graphQLInputObjectType?: GraphQLInputObjectType | GraphQLList<any>;
4142
};
4243
export declare type Operation = {
44+
/**
45+
* The raw operation object from the OAS
46+
*/
47+
operation: OperationObject;
4348
/**
4449
* Identifier of the operation - may be created by concatenating method & path
4550
*/
@@ -58,6 +63,10 @@ export declare type Operation = {
5863
* Human-readable description of the operation
5964
*/
6065
description: string;
66+
/**
67+
* Tags of this operation
68+
*/
69+
tags: string[];
6170
/**
6271
* URL path of this operation
6372
*/

packages/openapi-to-graphql/lib/types/operation.js

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

packages/openapi-to-graphql/lib/types/operation.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

+5-4
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ import debug from 'debug'
6969
import { GraphQLSchemaConfig } from 'graphql/type/schema'
7070
import { sortObject, handleWarning, MitigationTypes } from './utils'
7171

72-
type Result = {
72+
type Result<TSource, TContext, TArgs> = {
7373
schema: GraphQLSchema
7474
report: Report
75+
data: PreprocessingData<TSource, TContext, TArgs>
7576
}
7677

7778
const translationLog = debug('translation')
@@ -82,7 +83,7 @@ const translationLog = debug('translation')
8283
export function createGraphQLSchema<TSource, TContext, TArgs>(
8384
spec: Oas3 | Oas2 | (Oas3 | Oas2)[],
8485
options?: Options<TSource, TContext, TArgs>
85-
): Promise<Result> {
86+
): Promise<Result<TSource, TContext, TArgs>> {
8687
return new Promise((resolve, reject) => {
8788
if (typeof options === 'undefined') {
8889
options = {}
@@ -224,7 +225,7 @@ function translateOpenAPIToGraphQL<TSource, TContext, TArgs>(
224225
provideErrorExtensions,
225226
equivalentToMessages
226227
}: InternalOptions<TSource, TContext, TArgs>
227-
): { schema: GraphQLSchema; report: Report } {
228+
): Result<TSource, TContext, TArgs> {
228229
const options = {
229230
strict,
230231
report,
@@ -630,7 +631,7 @@ function translateOpenAPIToGraphQL<TSource, TContext, TArgs>(
630631

631632
const schema = new GraphQLSchema(schemaConfig)
632633

633-
return { schema, report: options.report }
634+
return { schema, report: options.report, data }
634635
}
635636

636637
/**

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

+5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ function processOperation<TSource, TContext, TArgs>(
7373
description += `\n\nEquivalent to ${operationString}`
7474
}
7575

76+
// Determine tags
77+
const tags = operation.tags || []
78+
7679
// Hold on to the operationId
7780
const operationId =
7881
typeof operation.operationId !== 'undefined'
@@ -161,10 +164,12 @@ function processOperation<TSource, TContext, TArgs>(
161164
securityRequirements.length > 0 && data.options.viewer !== false
162165

163166
return {
167+
operation,
164168
operationId,
165169
operationString,
166170
operationType,
167171
description,
172+
tags,
168173
path,
169174
method,
170175
payloadContentType,

packages/openapi-to-graphql/src/types/operation.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { OperationObject } from './oas3'
12
// Copyright IBM Corp. 2018. All Rights Reserved.
23
// Node module: openapi-to-graphql
34
// This file is licensed under the MIT License.
@@ -89,6 +90,11 @@ export type DataDefinition = {
8990
}
9091

9192
export type Operation = {
93+
/**
94+
* The raw operation object from the OAS
95+
*/
96+
operation: OperationObject
97+
9298
/**
9399
* Identifier of the operation - may be created by concatenating method & path
94100
*/
@@ -110,6 +116,11 @@ export type Operation = {
110116
*/
111117
description: string
112118

119+
/**
120+
* Tags of this operation
121+
*/
122+
tags: string[]
123+
113124
/**
114125
* URL path of this operation
115126
*/

0 commit comments

Comments
 (0)