forked from sangria-graphql/sangria
/
model.scala
126 lines (106 loc) · 3.66 KB
/
model.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package sangria.introspection
import sangria.ast.Document
import sangria.renderer.{SchemaFilter, SchemaRenderer}
import sangria.schema.DirectiveLocation
case class IntrospectionSchema(
queryType: IntrospectionNamedTypeRef,
mutationType: Option[IntrospectionNamedTypeRef],
subscriptionType: Option[IntrospectionNamedTypeRef],
types: Seq[IntrospectionType],
directives: Seq[IntrospectionDirective],
description: Option[String]
) {
def toAst = SchemaRenderer.schemaAstFromIntrospection(this)
def toAst(filter: SchemaFilter): Document =
SchemaRenderer.schemaAstFromIntrospection(this, filter)
def renderPretty: String = toAst.renderPretty
def renderPretty(filter: SchemaFilter): String = toAst(filter).renderPretty
def renderCompact: String = toAst.renderCompact
def renderCompact(filter: SchemaFilter): String = toAst(filter).renderCompact
lazy val typesByName = types.groupBy(_.name).map { case (k, v) => (k, v.head) }
}
sealed trait IntrospectionType {
def kind: TypeKind.Value
def name: String
def description: Option[String]
}
case class IntrospectionScalarType(name: String, description: Option[String])
extends IntrospectionType {
val kind = TypeKind.Scalar
}
case class IntrospectionObjectType(
name: String,
description: Option[String],
fields: Seq[IntrospectionField],
interfaces: Seq[IntrospectionNamedTypeRef])
extends IntrospectionType {
val kind = TypeKind.Object
lazy val fieldsByName = fields.groupBy(_.name).map { case (k, v) => (k, v.head) }
}
case class IntrospectionInputObjectType(
name: String,
description: Option[String],
inputFields: Seq[IntrospectionInputValue])
extends IntrospectionType {
val kind = TypeKind.InputObject
lazy val inputFieldsByName = inputFields.groupBy(_.name).map { case (k, v) => (k, v.head) }
}
case class IntrospectionInterfaceType(
name: String,
description: Option[String],
fields: Seq[IntrospectionField],
interfaces: Seq[IntrospectionNamedTypeRef],
possibleTypes: Seq[IntrospectionNamedTypeRef])
extends IntrospectionType {
val kind = TypeKind.Interface
}
case class IntrospectionUnionType(
name: String,
description: Option[String],
possibleTypes: Seq[IntrospectionNamedTypeRef])
extends IntrospectionType {
val kind = TypeKind.Union
}
case class IntrospectionEnumType(
name: String,
description: Option[String],
enumValues: Seq[IntrospectionEnumValue])
extends IntrospectionType {
val kind = TypeKind.Enum
}
case class IntrospectionField(
name: String,
description: Option[String],
args: Seq[IntrospectionInputValue],
tpe: IntrospectionTypeRef,
isDeprecated: Boolean,
deprecationReason: Option[String]
) {
lazy val argsByName = args.groupBy(_.name).map { case (k, v) => (k, v.head) }
}
case class IntrospectionEnumValue(
name: String,
description: Option[String],
isDeprecated: Boolean,
deprecationReason: Option[String])
case class IntrospectionInputValue(
name: String,
description: Option[String],
tpe: IntrospectionTypeRef,
defaultValue: Option[String])
sealed trait IntrospectionTypeRef {
def kind: TypeKind.Value
}
case class IntrospectionNamedTypeRef(kind: TypeKind.Value, name: String)
extends IntrospectionTypeRef
case class IntrospectionListTypeRef(ofType: IntrospectionTypeRef) extends IntrospectionTypeRef {
val kind = TypeKind.List
}
case class IntrospectionNonNullTypeRef(ofType: IntrospectionTypeRef) extends IntrospectionTypeRef {
val kind = TypeKind.NonNull
}
case class IntrospectionDirective(
name: String,
description: Option[String],
locations: Set[DirectiveLocation.Value],
args: Seq[IntrospectionInputValue])