Skip to content

Commit 4fef37f

Browse files
committed
Ability to set GraphQLFieldVisibility fix #373
1 parent 10ee43f commit 4fef37f

File tree

3 files changed

+421
-413
lines changed

3 files changed

+421
-413
lines changed

src/main/kotlin/graphql/kickstart/tools/SchemaObjects.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import graphql.schema.GraphQLCodeRegistry
44
import graphql.schema.GraphQLObjectType
55
import graphql.schema.GraphQLSchema
66
import graphql.schema.GraphQLType
7-
import graphql.schema.visibility.NoIntrospectionGraphqlFieldVisibility
87

98
/**
109
* @author Andrew Potter
@@ -14,11 +13,7 @@ data class SchemaObjects(val query: GraphQLObjectType, val mutation: GraphQLObje
1413
/**
1514
* Makes a GraphQLSchema with query, mutation and subscription.
1615
*/
17-
fun toSchema(introspectionEnabled: Boolean): GraphQLSchema {
18-
if (!introspectionEnabled) {
19-
codeRegistryBuilder.fieldVisibility(NoIntrospectionGraphqlFieldVisibility.NO_INTROSPECTION_FIELD_VISIBILITY)
20-
}
21-
16+
fun toSchema(): GraphQLSchema {
2217
return GraphQLSchema.newSchema()
2318
.query(query)
2419
.mutation(mutation)

src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import graphql.schema.*
66
import graphql.schema.idl.RuntimeWiring
77
import graphql.schema.idl.ScalarInfo
88
import graphql.schema.idl.SchemaGeneratorHelper
9+
import graphql.schema.visibility.NoIntrospectionGraphqlFieldVisibility
910
import org.slf4j.LoggerFactory
1011
import java.util.*
1112
import kotlin.reflect.KClass
@@ -62,9 +63,13 @@ class SchemaParser internal constructor(scanResult: ScannedSchemaObjects, privat
6263
* Parses the given schema with respect to the given dictionary and returns GraphQL objects.
6364
*/
6465
fun parseSchemaObjects(): SchemaObjects {
66+
if (!options.introspectionEnabled) {
67+
codeRegistryBuilder.fieldVisibility(NoIntrospectionGraphqlFieldVisibility.NO_INTROSPECTION_FIELD_VISIBILITY)
68+
}
69+
// this overrides the above introspection enabled setting obviously... todo: add documentation
70+
options.fieldVisilibity?.let { codeRegistryBuilder.fieldVisibility(it) }
6571

6672
// Create GraphQL objects
67-
// val inputObjects = inputObjectDefinitions.map { createInputObject(it, listOf())}
6873
val inputObjects: MutableList<GraphQLInputObjectType> = mutableListOf()
6974
inputObjectDefinitions.forEach {
7075
if (inputObjects.none { io -> io.name == it.name }) {
@@ -101,7 +106,7 @@ class SchemaParser internal constructor(scanResult: ScannedSchemaObjects, privat
101106
/**
102107
* Parses the given schema with respect to the given dictionary and returns a GraphQLSchema
103108
*/
104-
fun makeExecutableSchema(): GraphQLSchema = parseSchemaObjects().toSchema(options.introspectionEnabled)
109+
fun makeExecutableSchema(): GraphQLSchema = parseSchemaObjects().toSchema()
105110

106111
/**
107112
* Returns any unused type definitions that were found in the schema

0 commit comments

Comments
 (0)