@@ -10,12 +10,7 @@ import caliban.schema.{ RootSchema, RootSchemaBuilder, Types }
10
10
import caliban .validation .Utils .isObjectType
11
11
import caliban .validation .ValidationOps ._
12
12
13
- /*
14
- * TODO In the next major version:
15
- * 1. Make `SchemaValidator` an object and remove inheritance from Validator
16
- * 2. Make all methods private except `validateSchema` and `validateType`
17
- */
18
- private [caliban] trait SchemaValidator {
13
+ private [caliban] object SchemaValidator {
19
14
20
15
/**
21
16
* Verifies that the given schema is valid. Fails with a [[caliban.CalibanError.ValidationError ]] otherwise.
@@ -43,7 +38,7 @@ private[caliban] trait SchemaValidator {
43
38
case _ => unit
44
39
})
45
40
46
- private [caliban] def validateClashingTypes (types : List [__Type]): Either [ValidationError , Unit ] = {
41
+ private def validateClashingTypes (types : List [__Type]): Either [ValidationError , Unit ] = {
47
42
val check = types.groupBy(_.name).collectFirst { case (Some (name), v) if v.size > 1 => (name, v) }
48
43
check match {
49
44
case None => unit
@@ -108,7 +103,7 @@ private[caliban] trait SchemaValidator {
108
103
}
109
104
}
110
105
111
- private [caliban] def validateEnum (t : __Type): Either [ValidationError , Unit ] =
106
+ private def validateEnum (t : __Type): Either [ValidationError , Unit ] =
112
107
t.allEnumValues match {
113
108
case _ :: _ => unit
114
109
case Nil =>
@@ -118,7 +113,7 @@ private[caliban] trait SchemaValidator {
118
113
)
119
114
}
120
115
121
- private [caliban] def validateUnion (t : __Type): Either [ValidationError , Unit ] =
116
+ private def validateUnion (t : __Type): Either [ValidationError , Unit ] =
122
117
t.possibleTypes match {
123
118
case None | Some (Nil ) =>
124
119
failValidation(
@@ -134,7 +129,7 @@ private[caliban] trait SchemaValidator {
134
129
case _ => unit
135
130
}
136
131
137
- private [caliban] def validateInputObject (t : __Type): Either [ValidationError , Unit ] = {
132
+ private def validateInputObject (t : __Type): Either [ValidationError , Unit ] = {
138
133
lazy val inputObjectContext = s """ ${if (t._isOneOfInput) " OneOf " else " " }InputObject ' ${t.name.getOrElse(" " )}' """
139
134
140
135
def noDuplicateInputValueName (
@@ -184,7 +179,7 @@ private[caliban] trait SchemaValidator {
184
179
}
185
180
}
186
181
187
- private [caliban] def validateInputValue (
182
+ private def validateInputValue (
188
183
inputValue : __InputValue,
189
184
errorContext : => String
190
185
): Either [ValidationError , Unit ] = {
@@ -196,7 +191,7 @@ private[caliban] trait SchemaValidator {
196
191
} yield ()
197
192
}
198
193
199
- private [caliban] def validateInterface (t : __Type): Either [ValidationError , Unit ] = {
194
+ private def validateInterface (t : __Type): Either [ValidationError , Unit ] = {
200
195
lazy val interfaceContext = s " Interface ' ${t.name.getOrElse(" " )}' "
201
196
202
197
t.allFields match {
@@ -209,7 +204,7 @@ private[caliban] trait SchemaValidator {
209
204
}
210
205
}
211
206
212
- def validateObject (obj : __Type): Either [ValidationError , Unit ] = {
207
+ private def validateObject (obj : __Type): Either [ValidationError , Unit ] = {
213
208
lazy val objectContext = s " Object ' ${obj.name.getOrElse(" " )}' "
214
209
215
210
def validateInterfaceFields (obj : __Type) = {
@@ -315,7 +310,7 @@ private[caliban] trait SchemaValidator {
315
310
private def isListField (field : __Field) =
316
311
field._type.kind == __TypeKind.LIST
317
312
318
- private [caliban] def onlyInputType (`type` : __Type, errorContext : => String ): Either [ValidationError , Unit ] = {
313
+ private def onlyInputType (`type` : __Type, errorContext : => String ): Either [ValidationError , Unit ] = {
319
314
// https://spec.graphql.org/June2018/#IsInputType()
320
315
def isInputType (t : __Type): Either [__Type, Unit ] = {
321
316
import __TypeKind ._
@@ -336,7 +331,7 @@ private[caliban] trait SchemaValidator {
336
331
}
337
332
}
338
333
339
- private [caliban] def validateFields (fields : List [__Field], context : => String ): Either [ValidationError , Unit ] =
334
+ private def validateFields (fields : List [__Field], context : => String ): Either [ValidationError , Unit ] =
340
335
noDuplicateFieldName(fields, context) *>
341
336
validateAllDiscard(fields) { field =>
342
337
lazy val fieldContext = s " Field ' ${field.name}' of $context"
@@ -347,14 +342,14 @@ private[caliban] trait SchemaValidator {
347
342
} yield ()
348
343
}
349
344
350
- private [caliban] def noDuplicateFieldName (fields : List [__Field], errorContext : => String ) = {
345
+ private def noDuplicateFieldName (fields : List [__Field], errorContext : => String ) = {
351
346
val messageBuilder = (f : __Field) => s " $errorContext has repeated fields: ${f.name}"
352
347
def explanatory =
353
348
" The field must have a unique name within that Interface type; no two fields may share the same name"
354
349
noDuplicateName[__Field](fields, _.name, messageBuilder, explanatory)
355
350
}
356
351
357
- private [caliban] def onlyOutputType (`type` : __Type, errorContext : => String ): Either [ValidationError , Unit ] = {
352
+ private def onlyOutputType (`type` : __Type, errorContext : => String ): Either [ValidationError , Unit ] = {
358
353
// https://spec.graphql.org/June2018/#IsOutputType()
359
354
def isOutputType (t : __Type): Either [__Type, Unit ] = {
360
355
import __TypeKind ._
@@ -375,7 +370,7 @@ private[caliban] trait SchemaValidator {
375
370
}
376
371
}
377
372
378
- private [caliban] def noDuplicateName [T ](
373
+ private def noDuplicateName [T ](
379
374
listOfNamed : List [T ],
380
375
nameExtractor : T => String ,
381
376
messageBuilder : T => String ,
@@ -388,7 +383,7 @@ private[caliban] trait SchemaValidator {
388
383
failValidation(messageBuilder(duplicate), explanatoryText)
389
384
)
390
385
391
- private [caliban] def checkName (name : String , fieldContext : => String ): Either [ValidationError , Unit ] =
386
+ private def checkName (name : String , fieldContext : => String ): Either [ValidationError , Unit ] =
392
387
Parser
393
388
.parseName(name)
394
389
.left
@@ -399,7 +394,7 @@ private[caliban] trait SchemaValidator {
399
394
)
400
395
) *> doesNotStartWithUnderscore(name, fieldContext)
401
396
402
- private [caliban] def doesNotStartWithUnderscore (
397
+ private def doesNotStartWithUnderscore (
403
398
name : String ,
404
399
errorContext : => String
405
400
): Either [ValidationError , Unit ] =
@@ -408,7 +403,7 @@ private[caliban] trait SchemaValidator {
408
403
""" Names can not begin with the characters "__" (two underscores)"""
409
404
)
410
405
411
- private [caliban] def validateRootQuery [R ](
406
+ private def validateRootQuery [R ](
412
407
schema : RootSchemaBuilder [R ]
413
408
): Either [ValidationError , RootSchema [R ]] =
414
409
schema.query match {
@@ -427,7 +422,7 @@ private[caliban] trait SchemaValidator {
427
422
)
428
423
}
429
424
430
- private [caliban] def validateRootMutation [R ](schema : RootSchemaBuilder [R ]): Either [ValidationError , Unit ] =
425
+ private def validateRootMutation [R ](schema : RootSchemaBuilder [R ]): Either [ValidationError , Unit ] =
431
426
schema.mutation match {
432
427
case Some (mutation) if mutation.opType.kind != __TypeKind.OBJECT =>
433
428
failValidation(
@@ -437,7 +432,7 @@ private[caliban] trait SchemaValidator {
437
432
case _ => unit
438
433
}
439
434
440
- private [caliban] def validateRootSubscription [R ](schema : RootSchemaBuilder [R ]): Either [ValidationError , Unit ] =
435
+ private def validateRootSubscription [R ](schema : RootSchemaBuilder [R ]): Either [ValidationError , Unit ] =
441
436
schema.subscription match {
442
437
case Some (subscription) if subscription.opType.kind != __TypeKind.OBJECT =>
443
438
failValidation(
0 commit comments