Schema

class Schema

A wrapper around a schema GQLDocument that ensures the GQLDocument is valid and caches some extra information. In particular, Schema:

  • always contain builtin definitions (SDL can omit them)

  • always has a schema definition for easier lookup of root operation types

  • has all type system extensions merged

  • has some helper functions to retrieve a type by name and/or possible types

  • caches keyFields for easier lookup during codegen

  • remembers foreignNames to keep track of renamed definitions

  • remembers directivesToStrip to keep track of client-only directives

Parameters

definitions

a list of validated and merged definitions

keyFields

a Map containing the key fields for each type

foreignNames

a Map from a type system name -> its original name in the foreign schema. To distinguish between directives and types, directive names must be prefixed by '@' Example: "@kotlin_labs_nonnull" -> "@nonnull"

directivesToStrip

directives to strip because they are coming from a foreign schema Example: "kotlin_labs_nonnull"

Constructors

Link copied to clipboard
fun Schema(definitions: List<GQLDefinition>)

Creates a new Schema from a list of definition. This doesn't support foreign schemas.

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun hasTypeWithTypePolicy(): Boolean

Returns whether the typePolicy directive is present on at least one object in the schema

Link copied to clipboard
fun implementedTypes(name: String): Set<String>

List all types (types, interfaces, unions) implemented by a given type (including itself)

Link copied to clipboard
fun isTypeASubTypeOf(type: String, superType: String): Boolean
Link copied to clipboard
fun isTypeASuperTypeOf(type: String, subType: String): Boolean
Link copied to clipboard
fun keyFields(name: String): Set<String>

Get the key fields for an object, interface or union type.

Link copied to clipboard
fun originalDirectiveName(name: String): String
Link copied to clipboard
fun originalTypeName(name: String): String
Link copied to clipboard
fun possibleTypes(typeDefinition: GQLTypeDefinition): Set<String>

returns all possible types:

fun possibleTypes(name: String): Set<String>
Link copied to clipboard
fun rootTypeNameFor(operationType: String): String
Link copied to clipboard
fun shouldStrip(name: String): Boolean

return whether the given directive should be removed from operation documents before being sent to the server

Link copied to clipboard
fun superTypes(objectTypeDefinition: GQLObjectTypeDefinition): Set<String>

List all direct super types (interfaces, unions) implemented by a given object type

Link copied to clipboard
fun toGQLDocument(): GQLDocument
Link copied to clipboard
fun toMap(): Map<String, Any>

Returns the Schema as a Map that can be easily serialized to Json

Link copied to clipboard
fun typeDefinition(name: String): GQLTypeDefinition

Properties

Link copied to clipboard
val connectionTypes: Set<String>
Link copied to clipboard
val directiveDefinitions: Map<String, GQLDirectiveDefinition>
Link copied to clipboard
val foreignNames: Map<String, String>
Link copied to clipboard
val mutationTypeDefinition: GQLTypeDefinition?
Link copied to clipboard
val queryTypeDefinition: GQLTypeDefinition
Link copied to clipboard
val subscriptionTypeDefinition: GQLTypeDefinition?
Link copied to clipboard
val typeDefinitions: Map<String, GQLTypeDefinition>

Extensions

Link copied to clipboard
fun Schema.toIntrospectionSchema(): IntrospectionSchema