Skip to content

use nullable #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions packages/openapi-to-graphql/src/oas_3_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,19 +376,6 @@ export function resolveAllOf<TSource, TContext, TArgs>(
collapsedSchema.anyOf.push(anyOfProperty)
})
}

// Collapse required if applicable
if ('required' in collapsedMemberSchema) {
if (!('required' in collapsedSchema)) {
collapsedSchema.required = []
}

collapsedMemberSchema.required.forEach((requiredProperty) => {
if (!collapsedSchema.required.includes(requiredProperty)) {
collapsedSchema.required.push(requiredProperty)
}
})
}
})
}

Expand Down
21 changes: 0 additions & 21 deletions packages/openapi-to-graphql/src/preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,6 @@ export function createDataDef<TSource, TContext, TArgs>(
return {
preferredName,
schema: null,
required: [],
links: null,
subDefinitions: null,
graphQLTypeName: null,
Expand Down Expand Up @@ -793,7 +792,6 @@ export function createDataDef<TSource, TContext, TArgs>(
* currently, it does not.
*/
schema,
required: [],
targetGraphQLType, // May change due to allOf and oneOf resolution
subDefinitions: undefined,
links: saneLinks,
Expand Down Expand Up @@ -825,7 +823,6 @@ export function createDataDef<TSource, TContext, TArgs>(
addObjectPropertiesToDataDef(
def,
collapsedSchema,
def.required,
isInputObjectType,
data,
oas
Expand Down Expand Up @@ -1223,22 +1220,10 @@ function collapseLinksIntoDataDefinition<TSource, TContext, TArgs>({
function addObjectPropertiesToDataDef<TSource, TContext, TArgs>(
def: DataDefinition,
schema: SchemaObject,
required: string[],
isInputObjectType: boolean,
data: PreprocessingData<TSource, TContext, TArgs>,
oas: Oas3
) {
/**
* Resolve all required properties
*
* TODO: required may contain duplicates, which is not necessarily a problem
*/
if (Array.isArray(schema.required)) {
schema.required.forEach((requiredProperty) => {
required.push(requiredProperty)
})
}

for (let propertyKey in schema.properties) {
if (!(propertyKey in def.subDefinitions)) {
let propSchemaName = propertyKey
Expand Down Expand Up @@ -1334,11 +1319,6 @@ function getMemberSchemaData<TSource, TContext, TArgs>(
if (schema.properties) {
result.allProperties.push(schema.properties)
}

// Consolidate required
if (schema.required) {
result.allRequired = result.allRequired.concat(schema.required)
}
})

return result
Expand Down Expand Up @@ -1478,7 +1458,6 @@ function createAnyOfObject<TSource, TContext, TArgs>(
addObjectPropertiesToDataDef(
def,
collapsedSchema,
def.required,
isInputObjectType,
data,
oas
Expand Down
9 changes: 4 additions & 5 deletions packages/openapi-to-graphql/src/schema_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,7 @@ function createFields<TSource, TContext, TArgs extends object>({
fetch
})

const requiredProperty =
typeof def.required === 'object' && def.required.includes(fieldName)
const nullableProperty = fieldTypeDefinition.schema.nullable

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

fields[sanePropName] = {
type: requiredProperty
? new GraphQLNonNull(objectType as GraphQLOutputType)
: (objectType as GraphQLOutputType),
type: nullableProperty
? (objectType as GraphQLOutputType)
: new GraphQLNonNull(objectType as GraphQLOutputType),

description:
typeof fieldSchema === 'object' ? fieldSchema.description : null
Expand Down
7 changes: 0 additions & 7 deletions packages/openapi-to-graphql/src/types/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ export type DataDefinition = {
// The schema of the data type, why may have gone through some resolution, and is used with preferredName to identify a specific GraphQL type
schema: SchemaObject

/**
* Similar to the required property in object schemas but because of certain
* keywords to combine schemas, e.g. "allOf", this resolves the required
* property in all member schemas
*/
required: string[]

// The type GraphQL type this dataDefintion will be created into
targetGraphQLType: TargetGraphQLType

Expand Down
Loading