Skip to content

Commit 28167f3

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

File tree

10 files changed

+124
-1426
lines changed

10 files changed

+124
-1426
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-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Type definitions for the objects created during preprocessing for every
33
* operation in the OAS.
44
*/
5-
import { Oas3, LinkObject, ParameterObject, ServerObject, SchemaObject } from './oas3';
5+
import { Oas3, LinkObject, OperationObject, ParameterObject, ServerObject, SchemaObject } from './oas3';
66
import { GraphQLOperationType } from './graphql';
77
import { GraphQLScalarType, GraphQLObjectType, GraphQLInputObjectType, GraphQLList, GraphQLEnumType, GraphQLUnionType } from 'graphql';
88
import { HTTP_METHODS } from '../oas_3_tools';
@@ -40,6 +40,10 @@ export declare type DataDefinition = {
4040
graphQLInputObjectType?: GraphQLInputObjectType | GraphQLList<any>;
4141
};
4242
export declare type Operation = {
43+
/**
44+
* The raw operation object from the OAS
45+
*/
46+
operation: OperationObject;
4347
/**
4448
* Identifier of the operation - may be created by concatenating method & path
4549
*/
@@ -58,6 +62,10 @@ export declare type Operation = {
5862
* Human-readable description of the operation
5963
*/
6064
description: string;
65+
/**
66+
* Tags of this operation
67+
*/
68+
tags: string[];
6169
/**
6270
* URL path of this operation
6371
*/

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
@@ -11,6 +11,7 @@
1111
import {
1212
Oas3,
1313
LinkObject,
14+
OperationObject,
1415
ParameterObject,
1516
ServerObject,
1617
SchemaObject
@@ -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)