Skip to content

Commit

Permalink
Merge pull request #898 from sangria-graphql/mandatory_field_with_def…
Browse files Browse the repository at this point in the history
…ault_value_are_optional

mandatory fields with default values are considered optional
  • Loading branch information
yanns committed Aug 3, 2022
2 parents 3b09f61 + 430d7c0 commit 32f9dc8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ object SchemaComparator {
val added = newFields.diff(oldFields).toVector.map { name =>
val field = newType.fieldsByName(name)

SchemaChange.InputFieldAdded(newType, field, !isOptional(field))
val required = !isOptional(field) && field.defaultValue.isEmpty
SchemaChange.InputFieldAdded(newType, field, required)
}

val changed = oldFields.intersect(newFields).flatMap { name =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,12 @@ class SchemaComparatorSpec extends AnyWordSpec with Matchers {
c: [String]!
d: Int
e: Int!
f: Boolean! = true
}
""",
nonBreakingChange[TypeAdded]("`Int` type was added"),
breakingChange[InputFieldAdded]("Input field `e` was added to `Filter` type"),
nonBreakingChange[InputFieldAdded]("Input field `f` was added to `Filter` type"),
nonBreakingChange[InputFieldAdded]("Input field `d` was added to `Filter` type"),
breakingChange[InputFieldTypeChanged](
"`Filter.b` input field type changed from `String` to `[String]`"),
Expand Down Expand Up @@ -550,7 +552,7 @@ class SchemaComparatorSpec extends AnyWordSpec with Matchers {
type Query {
foo: String
}

"new description"
schema {
query: Query
Expand Down

0 comments on commit 32f9dc8

Please sign in to comment.