Skip to content

Commit

Permalink
Expose preprocessing data
Browse files Browse the repository at this point in the history
Signed-off-by: Dotan Simha <dotansimha@gmail.com>
  • Loading branch information
dotansimha authored and Alan-Cha committed Mar 3, 2021
1 parent 15ed7f2 commit 28167f3
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 1,426 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
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.

10 changes: 9 additions & 1 deletion packages/openapi-to-graphql/lib/types/operation.d.ts
Expand Up @@ -2,7 +2,7 @@
* Type definitions for the objects created during preprocessing for every
* operation in the OAS.
*/
import { Oas3, LinkObject, ParameterObject, ServerObject, SchemaObject } from './oas3';
import { Oas3, LinkObject, OperationObject, ParameterObject, ServerObject, SchemaObject } from './oas3';
import { GraphQLOperationType } from './graphql';
import { GraphQLScalarType, GraphQLObjectType, GraphQLInputObjectType, GraphQLList, GraphQLEnumType, GraphQLUnionType } from 'graphql';
import { HTTP_METHODS } from '../oas_3_tools';
Expand Down Expand Up @@ -40,6 +40,10 @@ export declare type DataDefinition = {
graphQLInputObjectType?: GraphQLInputObjectType | GraphQLList<any>;
};
export declare type Operation = {
/**
* The raw operation object from the OAS
*/
operation: OperationObject;
/**
* Identifier of the operation - may be created by concatenating method & path
*/
Expand All @@ -58,6 +62,10 @@ export declare type Operation = {
* Human-readable description of the operation
*/
description: string;
/**
* Tags of this operation
*/
tags: string[];
/**
* URL path of this operation
*/
Expand Down
9 changes: 5 additions & 4 deletions packages/openapi-to-graphql/src/index.ts
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
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
Expand Up @@ -11,6 +11,7 @@
import {
Oas3,
LinkObject,
OperationObject,
ParameterObject,
ServerObject,
SchemaObject
Expand Down Expand Up @@ -89,6 +90,11 @@ export type DataDefinition = {
}

export type Operation = {
/**
* The raw operation object from the OAS
*/
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 of this operation
*/
tags: string[]

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

0 comments on commit 28167f3

Please sign in to comment.