Skip to content

Commit 47afef5

Browse files
Alan-ChaErikWittern
authored andcommitted
Change type to targetGraphQLType
Signed-off-by: Alan Cha <[email protected]>
1 parent 8b406eb commit 47afef5

13 files changed

+48
-45
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,9 @@ export declare function instantiatePathAndGetQuery(path: string, parameters: Par
8383
};
8484
};
8585
/**
86-
* Returns the "type" of the given JSON schema. Makes best guesses if the type
87-
* is not explicitly defined.
86+
* Returns the GraphQL type that the provided schema should be made into
8887
*/
89-
export declare function getSchemaType(schema: SchemaObject, data: PreprocessingData): string | null;
88+
export declare function getSchemaTargetGraphQLType(schema: SchemaObject, data: PreprocessingData): string | null;
9089
/**
9190
* Determines an approximate name for the resource at the given path.
9291
*/

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

Lines changed: 3 additions & 4 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: 7 additions & 7 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/schema_builder.js

Lines changed: 5 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/schema_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/lib/types/operation.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
*/
55
import { Oas3, LinkObject, ParameterObject, ServerObject, SchemaObject } from './oas3';
66
import { GraphQLScalarType, GraphQLObjectType, GraphQLInputObjectType, GraphQLList, GraphQLEnumType, GraphQLUnionType } from 'graphql';
7+
import * as GraphQLJSON from 'graphql-type-json';
78
export declare type DataDefinition = {
89
preferredName: string;
910
schema: SchemaObject;
10-
type: string;
11+
targetGraphQLType: string;
1112
links: {
1213
[key: string]: LinkObject;
1314
};
@@ -28,7 +29,7 @@ export declare type DataDefinition = {
2829
} | DataDefinition[];
2930
graphQLTypeName: string;
3031
graphQLInputObjectTypeName: string;
31-
graphQLType?: GraphQLObjectType | GraphQLList<any> | GraphQLUnionType | GraphQLEnumType | GraphQLScalarType;
32+
graphQLType?: GraphQLObjectType | GraphQLList<any> | GraphQLUnionType | GraphQLEnumType | GraphQLScalarType | GraphQLJSON;
3233
graphQLInputObjectType?: GraphQLInputObjectType | GraphQLList<any>;
3334
};
3435
export declare type Operation = {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,9 @@ export function instantiatePathAndGetQuery(
411411
}
412412

413413
/**
414-
* Returns the "type" of the given JSON schema. Makes best guesses if the type
415-
* is not explicitly defined.
414+
* Returns the GraphQL type that the provided schema should be made into
416415
*/
417-
export function getSchemaType(
416+
export function getSchemaTargetGraphQLType(
418417
schema: SchemaObject,
419418
data: PreprocessingData
420419
): string | null {

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,13 @@ export function createDataDef(
518518
const iotName = otName + 'Input'
519519

520520
// Determine the type of the schema
521-
const type = Oas3Tools.getSchemaType(schema as SchemaObject, data)
521+
const targetGraphQLType = Oas3Tools.getSchemaTargetGraphQLType(
522+
schema as SchemaObject,
523+
data
524+
)
522525

523526
// Only add type names if a type will be created
524-
if (type === 'object' || type === 'array' || type === 'enum') {
527+
if (targetGraphQLType === 'object' || targetGraphQLType === 'array' || targetGraphQLType === 'enum') {
525528
// Add the names to the master list
526529
data.usedTypeNames.push(otName)
527530

@@ -541,22 +544,21 @@ export function createDataDef(
541544
* currently, it does not.
542545
*/
543546
schema,
544-
545-
type,
547+
targetGraphQLType,
546548
subDefinitions: undefined,
547549
links: saneLinks,
548550
graphQLTypeName: otName,
549551
graphQLInputObjectTypeName: iotName
550552
}
551553

552-
if (type) {
554+
if (targetGraphQLType) {
553555
// Add the def to the master list
554556
data.defs.push(def)
555557

556558
// Break schema down into component parts
557559
// I.e. if it is an list type, create a reference to the list item type
558560
// Or if it is an object type, create references to all of the field types
559-
if (type === 'array' && typeof schema.items === 'object') {
561+
if (targetGraphQLType === 'array' && typeof schema.items === 'object') {
560562
let itemsSchema = schema.items
561563
let itemsName = `${name}ListItem`
562564

@@ -576,7 +578,7 @@ export function createDataDef(
576578

577579
// Add list item reference
578580
def.subDefinitions = subDefinition
579-
} else if (type === 'object') {
581+
} else if (targetGraphQLType === 'object') {
580582
def.subDefinitions = {}
581583

582584
// Resolve allOf element in schema if applicable
@@ -613,7 +615,7 @@ export function createDataDef(
613615

614616
// Add existing properties (regular object type)
615617
addObjectPropertiesToDataDef(def, schema, isInputObjectType, data, oas)
616-
} else if (type === 'union') {
618+
} else if (targetGraphQLType === 'union') {
617619
def.subDefinitions = []
618620

619621
schema.oneOf.forEach(subSchema => {

0 commit comments

Comments
 (0)