OpenAPI properties may be nullable & required. required only indicates that a key must be present in an object to be valid, it makes no restriction on the type of the value corresponding to that key. openapi-to-graphql assumes that required OpenAPI properties are non-nullable:
|
const requiredProperty = |
|
typeof def.required === 'object' && def.required.includes(fieldTypeKey) |
To Reproduce
Use openapi-to-graphql on a spec with type with a required field that is also nullable. Queries for that type which return a null for that nullable field cause unexpected validation errors.
Expected behavior
No validation errors when returning nulls for explicitly nullable fields.
OpenAPI properties may be
nullable&required.requiredonly indicates that a key must be present in an object to be valid, it makes no restriction on the type of the value corresponding to that key.openapi-to-graphqlassumes thatrequiredOpenAPI properties are non-nullable:openapi-to-graphql/packages/openapi-to-graphql/src/schema_builder.ts
Lines 622 to 623 in a06d6f4
To Reproduce
Use
openapi-to-graphqlon a spec with type with a required field that is also nullable. Queries for that type which return a null for that nullable field cause unexpected validation errors.Expected behavior
No validation errors when returning nulls for explicitly nullable fields.