graphql.nadel.util.NamespacedUtil.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nadel Show documentation
Show all versions of nadel Show documentation
Nadel is a Java library that combines multiple GrahpQL services together into one API.
package graphql.nadel.util
import graphql.language.ObjectTypeDefinition
import graphql.language.ObjectTypeExtensionDefinition
import graphql.nadel.Service
import graphql.nadel.schema.NadelDirectives.namespacedDirectiveDefinition
import graphql.normalized.ExecutableNormalizedField
import graphql.schema.GraphQLFieldDefinition
import graphql.schema.GraphQLObjectType
import graphql.schema.GraphQLSchema
object NamespacedUtil {
fun serviceOwnsNamespacedField(namespacedObjectType: GraphQLObjectType, service: Service): Boolean {
return serviceOwnsNamespacedField(namespacedObjectType.name, service)
}
fun serviceOwnsNamespacedField(namespacedObjectTypeName: String, service: Service): Boolean {
return service
.definitionRegistry
.getDefinitionsOfType()
.stream() // the type can't be an extension in the owning service
.filter { it !is ObjectTypeExtensionDefinition }
.anyMatch { it.name == namespacedObjectTypeName }
}
fun isNamespacedField(overallField: ExecutableNormalizedField, schema: GraphQLSchema): Boolean {
return overallField
.getFieldDefinitions(schema)
.any {
isNamespacedField(it)
}
}
fun isNamespacedField(definition: GraphQLFieldDefinition): Boolean {
return definition.hasAppliedDirective(namespacedDirectiveDefinition.name)
}
}