Skip to content

Commit

Permalink
Expose preprocessing data
Browse files Browse the repository at this point in the history
Signed-off-by: Dotan Simha <[email protected]>
  • Loading branch information
dotansimha authored and Alan-Cha committed Mar 3, 2021
1 parent 15ed7f2 commit 2b98853
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 1,430 deletions.
1,499 changes: 83 additions & 1,416 deletions packages/openapi-to-graphql-cli/package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions packages/openapi-to-graphql/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@
import { Options, Report } from './types/options';
import { Oas3 } from './types/oas3';
import { Oas2 } from './types/oas2';
import { PreprocessingData } from './types/preprocessing_data';
import { GraphQLSchema } from 'graphql';
declare type Result = {
declare type Result<TSource, TContext, TArgs> = {
schema: GraphQLSchema;
report: Report;
data: PreprocessingData<TSource, TContext, TArgs>;
};
/**
* Creates a GraphQL interface from the given OpenAPI Specification (2 or 3).
*/
export declare function createGraphQLSchema<TSource, TContext, TArgs>(spec: Oas3 | Oas2 | (Oas3 | Oas2)[], options?: Options<TSource, TContext, TArgs>): Promise<Result>;
export declare function createGraphQLSchema<TSource, TContext, TArgs>(spec: Oas3 | Oas2 | (Oas3 | Oas2)[], options?: Options<TSource, TContext, TArgs>): Promise<Result<TSource, TContext, TArgs>>;
export { sanitize, CaseStyle } from './oas_3_tools';
export { GraphQLOperationType } from './types/graphql';
2 changes: 1 addition & 1 deletion packages/openapi-to-graphql/lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/openapi-to-graphql/lib/index.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions packages/openapi-to-graphql/lib/preprocessor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/openapi-to-graphql/lib/preprocessor.js.map

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions packages/openapi-to-graphql/lib/types/operation.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { OperationObject } from './oas3';
/**
* Type definitions for the objects created during preprocessing for every
* operation in the OAS.
Expand Down Expand Up @@ -40,6 +41,10 @@ export declare type DataDefinition = {
graphQLInputObjectType?: GraphQLInputObjectType | GraphQLList<any>;
};
export declare type Operation = {
/**
* The raw operation object from the OAS spec
*/
operation: OperationObject;
/**
* Identifier of the operation - may be created by concatenating method & path
*/
Expand All @@ -58,6 +63,10 @@ export declare type Operation = {
* Human-readable description of the operation
*/
description: string;
/**
* Tags from the original OAS
*/
tags: string[];
/**
* URL path of this operation
*/
Expand Down
4 changes: 0 additions & 4 deletions packages/openapi-to-graphql/lib/types/operation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/openapi-to-graphql/lib/types/operation.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions packages/openapi-to-graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ import debug from 'debug'
import { GraphQLSchemaConfig } from 'graphql/type/schema'
import { sortObject, handleWarning, MitigationTypes } from './utils'

type Result = {
type Result<TSource, TContext, TArgs> = {
schema: GraphQLSchema
report: Report
data: PreprocessingData<TSource, TContext, TArgs>
}

const translationLog = debug('translation')
Expand All @@ -82,7 +83,7 @@ const translationLog = debug('translation')
export function createGraphQLSchema<TSource, TContext, TArgs>(
spec: Oas3 | Oas2 | (Oas3 | Oas2)[],
options?: Options<TSource, TContext, TArgs>
): Promise<Result> {
): Promise<Result<TSource, TContext, TArgs>> {
return new Promise((resolve, reject) => {
if (typeof options === 'undefined') {
options = {}
Expand Down Expand Up @@ -224,7 +225,7 @@ function translateOpenAPIToGraphQL<TSource, TContext, TArgs>(
provideErrorExtensions,
equivalentToMessages
}: InternalOptions<TSource, TContext, TArgs>
): { schema: GraphQLSchema; report: Report } {
): Result<TSource, TContext, TArgs> {
const options = {
strict,
report,
Expand Down Expand Up @@ -630,7 +631,7 @@ function translateOpenAPIToGraphQL<TSource, TContext, TArgs>(

const schema = new GraphQLSchema(schemaConfig)

return { schema, report: options.report }
return { schema, report: options.report, data }
}

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/openapi-to-graphql/src/preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ function processOperation<TSource, TContext, TArgs>(
description += `\n\nEquivalent to ${operationString}`
}

// Determine tags
const tags = operation.tags || []

// Hold on to the operationId
const operationId =
typeof operation.operationId !== 'undefined'
Expand Down Expand Up @@ -161,10 +164,12 @@ function processOperation<TSource, TContext, TArgs>(
securityRequirements.length > 0 && data.options.viewer !== false

return {
operation,
operationId,
operationString,
operationType,
description,
tags,
path,
method,
payloadContentType,
Expand Down
11 changes: 11 additions & 0 deletions packages/openapi-to-graphql/src/types/operation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { OperationObject } from './oas3'
// Copyright IBM Corp. 2018. All Rights Reserved.
// Node module: openapi-to-graphql
// This file is licensed under the MIT License.
Expand Down Expand Up @@ -89,6 +90,11 @@ export type DataDefinition = {
}

export type Operation = {
/**
* The raw operation object from the OAS spec
*/
operation: OperationObject

/**
* Identifier of the operation - may be created by concatenating method & path
*/
Expand All @@ -110,6 +116,11 @@ export type Operation = {
*/
description: string

/**
* Tags from the original OAS
*/
tags: string[]

/**
* URL path of this operation
*/
Expand Down

0 comments on commit 2b98853

Please sign in to comment.