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 directivesMapping 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

directivesMapping

a Map from the foreign schema name to the final name in the schema. Ignored directives are absent from the map. Example: "@kotlin_labs_nonnull" -> "@nonnull"

directivesToStrip

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

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard

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
Link copied to clipboard
fun possibleTypes(typeDefinition: GQLTypeDefinition): Set<String>

returns all possible types:

Link copied to clipboard
fun rootTypeNameFor(operationType: String): String
Link copied to clipboard
fun rootTypeNameOrNullFor(operationType: String): String?
Link copied to clipboard

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

Link copied to clipboard
fun superTypes(typeDefinition: GQLTypeDefinition): Set<String>

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

Link copied to clipboard
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