Skip to content

Commit 1014ac6

Browse files
nlundquiststeverice
authored andcommitted
attempt at using nullable instead of required to determine nullability
Signed-off-by: Nils Lundquist <nils@bitovi.com>
1 parent d6f53e7 commit 1014ac6

File tree

3 files changed

+4
-33
lines changed

3 files changed

+4
-33
lines changed

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,6 @@ export function createDataDef<TSource, TContext, TArgs>(
695695
return {
696696
preferredName,
697697
schema: null,
698-
required: [],
699698
links: null,
700699
subDefinitions: null,
701700
graphQLTypeName: null,
@@ -793,7 +792,6 @@ export function createDataDef<TSource, TContext, TArgs>(
793792
* currently, it does not.
794793
*/
795794
schema,
796-
required: [],
797795
targetGraphQLType, // May change due to allOf and oneOf resolution
798796
subDefinitions: undefined,
799797
links: saneLinks,
@@ -825,7 +823,6 @@ export function createDataDef<TSource, TContext, TArgs>(
825823
addObjectPropertiesToDataDef(
826824
def,
827825
collapsedSchema,
828-
def.required,
829826
isInputObjectType,
830827
data,
831828
oas
@@ -1223,22 +1220,10 @@ function collapseLinksIntoDataDefinition<TSource, TContext, TArgs>({
12231220
function addObjectPropertiesToDataDef<TSource, TContext, TArgs>(
12241221
def: DataDefinition,
12251222
schema: SchemaObject,
1226-
required: string[],
12271223
isInputObjectType: boolean,
12281224
data: PreprocessingData<TSource, TContext, TArgs>,
12291225
oas: Oas3
12301226
) {
1231-
/**
1232-
* Resolve all required properties
1233-
*
1234-
* TODO: required may contain duplicates, which is not necessarily a problem
1235-
*/
1236-
if (Array.isArray(schema.required)) {
1237-
schema.required.forEach((requiredProperty) => {
1238-
required.push(requiredProperty)
1239-
})
1240-
}
1241-
12421227
for (let propertyKey in schema.properties) {
12431228
if (!(propertyKey in def.subDefinitions)) {
12441229
let propSchemaName = propertyKey
@@ -1334,11 +1319,6 @@ function getMemberSchemaData<TSource, TContext, TArgs>(
13341319
if (schema.properties) {
13351320
result.allProperties.push(schema.properties)
13361321
}
1337-
1338-
// Consolidate required
1339-
if (schema.required) {
1340-
result.allRequired = result.allRequired.concat(schema.required)
1341-
}
13421322
})
13431323

13441324
return result
@@ -1478,7 +1458,6 @@ function createAnyOfObject<TSource, TContext, TArgs>(
14781458
addObjectPropertiesToDataDef(
14791459
def,
14801460
collapsedSchema,
1481-
def.required,
14821461
isInputObjectType,
14831462
data,
14841463
oas

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,7 @@ function createFields<TSource, TContext, TArgs extends object>({
664664
fetch
665665
})
666666

667-
const requiredProperty =
668-
typeof def.required === 'object' && def.required.includes(fieldName)
667+
const nullableProperty = typeof def.schema.nullable
669668

670669
// Finally, add the object type to the fields (using sanitized field name)
671670
if (objectType) {
@@ -706,9 +705,9 @@ function createFields<TSource, TContext, TArgs extends object>({
706705
)
707706

708707
fields[sanePropName] = {
709-
type: requiredProperty
710-
? new GraphQLNonNull(objectType as GraphQLOutputType)
711-
: (objectType as GraphQLOutputType),
708+
type: nullableProperty
709+
? (objectType as GraphQLOutputType)
710+
: new GraphQLNonNull(objectType as GraphQLOutputType),
712711

713712
description:
714713
typeof fieldSchema === 'object' ? fieldSchema.description : null

packages/openapi-to-graphql/src/types/operation.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@ export type DataDefinition = {
6161
// The schema of the data type, why may have gone through some resolution, and is used with preferredName to identify a specific GraphQL type
6262
schema: SchemaObject
6363

64-
/**
65-
* Similar to the required property in object schemas but because of certain
66-
* keywords to combine schemas, e.g. "allOf", this resolves the required
67-
* property in all member schemas
68-
*/
69-
required: string[]
70-
7164
// The type GraphQL type this dataDefintion will be created into
7265
targetGraphQLType: TargetGraphQLType
7366

0 commit comments

Comments
 (0)