Skip to content

Commit

Permalink
Generate unions from oneOf return type
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Tatzky <[email protected]>
  • Loading branch information
ftatzky committed Jun 22, 2020
1 parent 1e845bf commit c473524
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 7 additions & 0 deletions packages/openapi-to-graphql/src/oas_3_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,13 @@ export function getSchemaTargetGraphQLType<TSource, TContext, TArgs>(
schema: SchemaObject,
data: PreprocessingData<TSource, TContext, TArgs>
): string | null {
if (schema.oneOf) {
return 'union'
}

if (schema.allOf) {
return 'object'
}
// CASE: object
if (schema.type === 'object' || typeof schema.properties === 'object') {
// TODO: additionalProperties is more like a flag than a type itself
Expand Down
8 changes: 2 additions & 6 deletions packages/openapi-to-graphql/src/preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1504,14 +1504,10 @@ function createDataDefFromOneOf<TSource, TContext, TArgs>(
if (
oneOfData.allTargetGraphQLTypes.every(memberTargetGraphQLType => {
return memberTargetGraphQLType === 'object'
}) &&
oneOfData.allProperties.length > 0 // Redundant check
})
) {
// Ensure that parent schema is compatiable with oneOf
if (
def.targetGraphQLType === null ||
def.targetGraphQLType === 'object'
) {
if (def.targetGraphQLType === 'union') {
def.subDefinitions = []

collapsedSchema.oneOf.forEach(memberSchema => {
Expand Down

0 comments on commit c473524

Please sign in to comment.