Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private fun List<GQLSelection>.addRequiredFields(
requiredFieldNames.add("__typename")
}

val fieldNames = parentFields + selectionSet.filterIsInstance<GQLField>().map { it.name }.toSet()
val fieldNames = parentFields + selectionSet.filterIsInstance<GQLField>().map { it.alias ?: it.name }.toSet()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val fieldNames = parentFields + selectionSet.filterIsInstance<GQLField>().map { it.alias ?: it.name }.toSet()
val fieldNames = parentFields + selectionSet.filterIsInstance<GQLField>().map { it.responseName() }.toSet()


var newSelections = selectionSet.map {
when (it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ internal fun checkKeyFields(
schema: Schema,
allFragmentDefinitions: Map<String, GQLFragmentDefinition>,
) {
CheckKeyFieldsScope(schema, allFragmentDefinitions).checkField("Fragment(${fragmentDefinition.name})", fragmentDefinition.selections, fragmentDefinition.typeCondition.name)
CheckKeyFieldsScope(schema, allFragmentDefinitions).checkField(
"Fragment(${fragmentDefinition.name})",
fragmentDefinition.selections,
fragmentDefinition.typeCondition.name
)
}

private fun CheckKeyFieldsScope.checkField(
Expand All @@ -61,9 +65,9 @@ private fun CheckKeyFieldsScope.checkFieldSet(path: String, selections: List<GQL

if (implementedTypes.contains(parentType)) {
// only check types that are actually possible
val fieldNames = mergedFields.map { it.first().field }
.filter { it.alias == null }
.map { it.name }.toSet()
val fieldNames = mergedFields
.flatMap { it.filter { it.field.alias == null }.map { it.field.name } }
.toSet()
val keyFieldNames = keyFields(possibleType)

val missingFieldNames = keyFieldNames.subtract(fieldNames)
Expand Down Expand Up @@ -101,13 +105,15 @@ private fun CheckKeyFieldsScope.collectFields(

listOf(FieldWithParent(it, parentType))
}

is GQLInlineFragment -> {
if (it.directives.hasCondition()) {
return@flatMap emptyList()
}

collectFields(it.selections, it.typeCondition?.name ?: parentType, implementedTypes)
}

is GQLFragmentSpread -> {
if (it.directives.hasCondition()) {
return@flatMap emptyList()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
query GetA {
a {
...AFragment1
}
}

fragment AFragment1 on A {
foo
...AFragment2
}

fragment AFragment2 on A {
bar
myId: id
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading