@@ -6,14 +6,13 @@ import com.github.pgutkowski.kgraphql.schema.builtin.BUILT_IN_TYPE
6
6
import com.github.pgutkowski.kgraphql.schema.directive.Directive
7
7
import com.github.pgutkowski.kgraphql.schema.directive.DirectiveLocation
8
8
import com.github.pgutkowski.kgraphql.schema.dsl.TypeDSL
9
- import com.github.pgutkowski.kgraphql.schema.introspection.__Schema
10
9
import com.github.pgutkowski.kgraphql.schema.introspection.TypeKind
11
10
import com.github.pgutkowski.kgraphql.schema.introspection.__Directive
12
11
import com.github.pgutkowski.kgraphql.schema.introspection.__EnumValue
13
12
import com.github.pgutkowski.kgraphql.schema.introspection.__Field
13
+ import com.github.pgutkowski.kgraphql.schema.introspection.__Schema
14
14
import com.github.pgutkowski.kgraphql.schema.introspection.__Type
15
15
import kotlin.reflect.KClass
16
- import kotlin.reflect.KProperty1
17
16
import kotlin.reflect.full.isSubclassOf
18
17
19
18
/* *
@@ -23,7 +22,8 @@ import kotlin.reflect.full.isSubclassOf
23
22
data class MutableSchemaDefinition (
24
23
private val objects : ArrayList <TypeDef .Object <* >> = arrayListOf(
25
24
TypeDef .Object (__Schema ::class.defaultKQLTypeName(), __Schema ::class),
26
- create__TypeDefinition()
25
+ create__TypeDefinition(),
26
+ create__DirectiveDefinition()
27
27
),
28
28
private val queries : ArrayList <QueryDef <* >> = arrayListOf(),
29
29
private val scalars : ArrayList <TypeDef .Scalar <* >> = arrayListOf(
@@ -145,4 +145,31 @@ private fun create__TypeDefinition() = TypeDSL(emptyList(), __Type::class){
145
145
transformation(__Type ::enumValues){ enumValues: List <__EnumValue >? , includeDeprecated: Boolean? ->
146
146
if (includeDeprecated == true ) enumValues else enumValues?.filterNot { it.isDeprecated }
147
147
}
148
- }.toKQLObject()
148
+ }.toKQLObject()
149
+
150
+ private fun create__DirectiveDefinition () = TypeDSL (emptyList(), __Directive ::class ){
151
+ property<Boolean >(" onField" ){
152
+ resolver { dir: __Directive ->
153
+ dir.locations.contains(DirectiveLocation .FIELD )
154
+ }
155
+ deprecate(" Use `locations`." )
156
+ }
157
+ property<Boolean >(" onFragment" ){
158
+ resolver { dir: __Directive -> dir.locations.containsAny (
159
+ DirectiveLocation .FRAGMENT_SPREAD ,
160
+ DirectiveLocation .FRAGMENT_DEFINITION ,
161
+ DirectiveLocation .INLINE_FRAGMENT )
162
+ }
163
+ deprecate(" Use `locations`." )
164
+ }
165
+ property<Boolean >(" onOperation" ){
166
+ resolver{ dir : __Directive -> dir.locations.containsAny (
167
+ DirectiveLocation .QUERY ,
168
+ DirectiveLocation .MUTATION ,
169
+ DirectiveLocation .SUBSCRIPTION )
170
+ }
171
+ deprecate(" Use `locations`." )
172
+ }
173
+ }.toKQLObject()
174
+
175
+ private fun <T > List<T>.containsAny (vararg elements : T ) = elements.filter { this .contains(it) }.any()
0 commit comments