-
Notifications
You must be signed in to change notification settings - Fork 653
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
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7c84d42
Fix an NPE when a non-imported @catch directive is used
BoD c503433
Validation: check that directives/enums with the same name as those i…
BoD af1ae42
Update API dump
BoD 079bd01
Merge IncompatibleDirectiveDefinition and IncompatibleEnumDefinition
BoD 8b74204
Directives are order sensitive
BoD 4152f04
Simplify semanticEquals
BoD 5349007
Make KOTLIN_LABS_VERSION and NULLABILITY_VERSION internal
BoD eddcccc
Update libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/a…
BoD e152504
Improve semanticEquals following review
BoD 8ae0337
Add support for GQLInputObjectTypeDefinition and GQLScalarTypeDefinit…
BoD feb420c
Remove useless and failing test
BoD b0a6291
Revert isDefinedAndMatchesOriginalName
BoD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
204 changes: 204 additions & 0 deletions
204
...apollo-ast/src/commonMain/kotlin/com/apollographql/apollo3/ast/internal/semanticEquals.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
package com.apollographql.apollo3.ast.internal | ||
|
||
import com.apollographql.apollo3.ast.GQLArgument | ||
import com.apollographql.apollo3.ast.GQLBooleanValue | ||
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.GQLFloatValue | ||
import com.apollographql.apollo3.ast.GQLInputValueDefinition | ||
import com.apollographql.apollo3.ast.GQLIntValue | ||
import com.apollographql.apollo3.ast.GQLListType | ||
import com.apollographql.apollo3.ast.GQLListValue | ||
import com.apollographql.apollo3.ast.GQLNamed | ||
import com.apollographql.apollo3.ast.GQLNamedType | ||
import com.apollographql.apollo3.ast.GQLNode | ||
import com.apollographql.apollo3.ast.GQLNonNullType | ||
import com.apollographql.apollo3.ast.GQLNullValue | ||
import com.apollographql.apollo3.ast.GQLObjectValue | ||
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 { | ||
martinbonnin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
when (this) { | ||
is GQLDirectiveDefinition -> { | ||
if (other !is GQLDirectiveDefinition) { | ||
return false | ||
martinbonnin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if (locations != other.locations) { | ||
return false | ||
} | ||
|
||
if (repeatable != other.repeatable) { | ||
return false | ||
} | ||
} | ||
|
||
is GQLInputValueDefinition -> { | ||
if (other !is GQLInputValueDefinition) { | ||
return false | ||
} | ||
|
||
if (!type.semanticEquals(other.type)) { | ||
return false | ||
} | ||
|
||
if (defaultValue != null && other.defaultValue != null) { | ||
if (!defaultValue.semanticEquals(other.defaultValue)) { | ||
return false | ||
} | ||
} else if (defaultValue != null || other.defaultValue != null) { | ||
return false | ||
} | ||
} | ||
|
||
is GQLNonNullType -> { | ||
if (other !is GQLNonNullType) { | ||
return false | ||
} | ||
} | ||
|
||
is GQLListType -> { | ||
if (other !is GQLListType) { | ||
return false | ||
} | ||
} | ||
|
||
is GQLNamedType -> { | ||
if (other !is GQLNamedType) { | ||
return false | ||
} | ||
} | ||
|
||
is GQLNullValue -> { | ||
if (other !is GQLNullValue) { | ||
return false | ||
} | ||
} | ||
|
||
is GQLListValue -> { | ||
if (other !is GQLListValue) { | ||
return false | ||
} | ||
} | ||
|
||
is GQLObjectValue -> { | ||
if (other !is GQLObjectValue) { | ||
return false | ||
} | ||
} | ||
|
||
is GQLStringValue -> { | ||
if (other !is GQLStringValue) { | ||
return false | ||
} | ||
if (value != other.value) { | ||
return false | ||
} | ||
} | ||
|
||
is GQLBooleanValue -> { | ||
if (other !is GQLBooleanValue) { | ||
return false | ||
} | ||
if (value != other.value) { | ||
return false | ||
} | ||
} | ||
|
||
is GQLIntValue -> { | ||
if (other !is GQLIntValue) { | ||
return false | ||
} | ||
if (value != other.value) { | ||
return false | ||
} | ||
} | ||
|
||
is GQLFloatValue -> { | ||
if (other !is GQLFloatValue) { | ||
return false | ||
} | ||
if (value != other.value) { | ||
return false | ||
} | ||
} | ||
|
||
is GQLEnumValue -> { | ||
if (other !is GQLEnumValue) { | ||
return false | ||
} | ||
if (value != other.value) { | ||
return false | ||
} | ||
} | ||
|
||
is GQLVariableValue -> { | ||
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) { | ||
return false | ||
} | ||
} | ||
|
||
else -> {} | ||
martinbonnin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if (this is GQLNamed) { | ||
if (other !is GQLNamed) { | ||
return false | ||
} | ||
if (name != other.name) { | ||
return false | ||
} | ||
} | ||
|
||
if (children.size != other.children.size) { | ||
return false | ||
} | ||
for (i in children.indices) { | ||
if (!children[i].semanticEquals(other.children[i])) { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
internal fun GQLDirectiveDefinition.toSemanticSdl(): String { | ||
return copy(description = null, arguments = arguments.map { it.copy(description = null) }).toUtf8().trim() | ||
} | ||
|
||
internal fun GQLEnumTypeDefinition.toSemanticSdl(): String { | ||
return copy(description = null, enumValues = enumValues.map { it.copy(description = null) }).toUtf8().replace(Regex("[\\n ]+"), " ").trim() | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for nitpicking this but I'd rather have the codegen crash than silently ignore missing directive definitions.
All directive usage of
@catch
must be validated at that point so if we don't have a directive definition, it's a programming error that I'd rather catch (no pun intended) earlyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why I had the impression it would still NPE without this, but it's not the case - just removed it 👍