@@ -951,20 +951,22 @@ private fun ValidationScope.keyFields(
951951 return cached
952952 }
953953
954- val (directives, interfaces ) = when (typeDefinition) {
954+ val (directives, allInterfaces ) = when (typeDefinition) {
955955 is GQLObjectTypeDefinition -> typeDefinition.directives to typeDefinition.implementsInterfaces
956956 is GQLInterfaceTypeDefinition -> typeDefinition.directives to typeDefinition.implementsInterfaces
957957 else -> error(" Unexpected type definition $typeDefinition " )
958958 }
959959
960- val interfacesKeyFields = interfaces.map { keyFields(typeDefinitions[it]!! , keyFieldsCache) }
961- .filter { it.isNotEmpty() }
960+ val interfacesToKeyFields: Map <String , Set <String >> = allInterfaces.associate { it to keyFields(typeDefinitions[it]!! , keyFieldsCache) }
961+ .filter { it.value.isNotEmpty() }
962+ val interfaces = interfacesToKeyFields.keys.toList()
963+ val interfacesKeyFields = interfacesToKeyFields.values.toList()
962964
963965 val distinct = interfacesKeyFields.distinct()
964966 if (distinct.size > 1 ) {
965- val extra = interfaces.indices.map {
967+ val extra = interfaces.indices.joinToString( " \n " ) {
966968 " ${interfaces[it]} : ${interfacesKeyFields[it]} "
967- }.joinToString( " \n " )
969+ }
968970
969971 registerIssue(
970972 message = " Apollo: Type '${typeDefinition.name} ' cannot inherit different keys from different interfaces:\n $extra " ,
@@ -975,9 +977,9 @@ private fun ValidationScope.keyFields(
975977 val keyFields = directives.filter { originalDirectiveName(it.name) == TYPE_POLICY }.toKeyFields()
976978 val ret = if (keyFields.isNotEmpty()) {
977979 if (distinct.isNotEmpty()) {
978- val extra = interfaces.indices.map {
980+ val extra = interfaces.indices.joinToString( " \n " ) {
979981 " ${interfaces[it]} : ${interfacesKeyFields[it]} "
980- }.joinToString( " \n " )
982+ }
981983
982984 registerIssue(
983985 message = " Type '${typeDefinition.name} ' cannot have key fields since it implements the following interfaces which also have key fields: $extra " ,
0 commit comments