Skip to content
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

Add validation to check schema definitions are compatible with the bundled ones #5444

Merged
merged 12 commits into from
Dec 12, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.apollographql.apollo3.ast.GQLDirective
import com.apollographql.apollo3.ast.GQLDirectiveDefinition
import com.apollographql.apollo3.ast.GQLEnumTypeDefinition
import com.apollographql.apollo3.ast.GQLEnumValue
import com.apollographql.apollo3.ast.GQLEnumValueDefinition
import com.apollographql.apollo3.ast.GQLFloatValue
import com.apollographql.apollo3.ast.GQLInputValueDefinition
import com.apollographql.apollo3.ast.GQLIntValue
Expand All @@ -21,7 +22,13 @@ import com.apollographql.apollo3.ast.GQLStringValue
import com.apollographql.apollo3.ast.GQLVariableValue
import com.apollographql.apollo3.ast.toUtf8

internal fun GQLNode.semanticEquals(other: GQLNode): Boolean {
/**
* Returns true if the two nodes are semantically equal, which ignores the source location and the description.
* Note that not all cases are implemented - currently [GQLEnumTypeDefinition] and [GQLDirectiveDefinition] are fully supported, and
martinbonnin marked this conversation as resolved.
Show resolved Hide resolved
* unsupported types will throw.
*/
internal fun GQLNode.semanticEquals(other: GQLNode?): Boolean {
if (other == null) return false
when (this) {
is GQLDirectiveDefinition -> {
if (other !is GQLDirectiveDefinition) {
Expand All @@ -46,11 +53,11 @@ internal fun GQLNode.semanticEquals(other: GQLNode): Boolean {
return false
}

if (defaultValue != null && other.defaultValue != null) {
if (defaultValue != null) {
if (!defaultValue.semanticEquals(other.defaultValue)) {
return false
}
} else if (defaultValue != null || other.defaultValue != null) {
} else if (other.defaultValue != null) {
return false
}
}
Expand Down Expand Up @@ -140,39 +147,35 @@ internal fun GQLNode.semanticEquals(other: GQLNode): Boolean {
if (other !is GQLVariableValue) {
return false
}
if (name != other.name) {
return false
}
}

is GQLEnumTypeDefinition -> {
if (other !is GQLEnumTypeDefinition) {
return false
}
if (name != other.name) {
return false
}
}

is GQLDirective -> {
if (other !is GQLDirective) {
return false
}
if (name != other.name) {
return false
}
}

is GQLArgument -> {
if (other !is GQLArgument) {
return false
}
if (name != other.name) {
}

is GQLEnumValueDefinition -> {
if (other !is GQLEnumValueDefinition) {
return false
}
}

else -> {}
else -> {
TODO("semanticEquals not supported for ${this::class.simpleName}")
}
}

if (this is GQLNamed) {
Expand Down