Skip to content

Commit 218c997

Browse files
smyrickdariuszkuc
authored andcommitted
feat: update config settings for subscriptions (#160)
1 parent d0e3cd6 commit 218c997

File tree

14 files changed

+67
-60
lines changed

14 files changed

+67
-60
lines changed

example/src/main/kotlin/com/expedia/graphql/sample/Application.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ class Application {
7070
}
7171

7272
val schema = toSchema(
73-
queries = queries.toTopLevelObjectDefs(),
74-
mutations = mutations.toTopLevelObjectDefs(),
75-
config = schemaConfig
73+
queries = queries.toTopLevelObjectDefs(),
74+
mutations = mutations.toTopLevelObjectDefs(),
75+
config = schemaConfig
7676
)
7777
logger.info(SchemaPrinter(
7878
SchemaPrinter.Options.defaultOptions()

src/main/kotlin/com/expedia/graphql/SchemaGeneratorConfig.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ import com.expedia.graphql.hooks.SchemaGeneratorHooks
99
*/
1010
data class SchemaGeneratorConfig(
1111
val supportedPackages: List<String>,
12-
val topLevelQueryName: String = "Query",
13-
val topLevelMutationName: String = "Mutation",
12+
val topLevelNames: TopLevelNames = TopLevelNames(),
1413
val hooks: SchemaGeneratorHooks = NoopSchemaGeneratorHooks(),
1514
val dataFetcherFactoryProvider: KotlinDataFetcherFactoryProvider = KotlinDataFetcherFactoryProvider(hooks)
1615
)
16+
17+
/**
18+
*
19+
*/
20+
data class TopLevelNames(
21+
val query: String = "Query",
22+
val mutation: String = "Mutation"
23+
)

src/main/kotlin/com/expedia/graphql/generator/types/MutationTypeBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal class MutationTypeBuilder(generator: SchemaGenerator) : TypeBuilder(gen
1717
}
1818

1919
val mutationBuilder = GraphQLObjectType.Builder()
20-
mutationBuilder.name(config.topLevelMutationName)
20+
mutationBuilder.name(config.topLevelNames.mutation)
2121

2222
for (mutation in mutations) {
2323
if (!mutation.kClass.isPublic()) {

src/main/kotlin/com/expedia/graphql/generator/types/QueryTypeBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal class QueryTypeBuilder(generator: SchemaGenerator) : TypeBuilder(genera
1919
}
2020

2121
val queryBuilder = GraphQLObjectType.Builder()
22-
queryBuilder.name(config.topLevelQueryName)
22+
queryBuilder.name(config.topLevelNames.query)
2323

2424
for (query in queries) {
2525
if (!query.kClass.isPublic()) {

src/main/kotlin/com/expedia/graphql/toSchema.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import graphql.schema.GraphQLSchema
77
/**
88
* Entry point to generate a graphql schema using reflection on the passed objects.
99
*
10+
* @param config Schema generation configuration
1011
* @param queries List of [TopLevelObject] to use for GraphQL queries
1112
* @param mutations List of [TopLevelObject] to use for GraphQL mutations
12-
* @param config Schema generation configuration
1313
*
1414
* @return GraphQLSchema from graphql-java
1515
*/
1616
@Throws(GraphQLKotlinException::class)
1717
fun toSchema(
18+
config: SchemaGeneratorConfig,
1819
queries: List<TopLevelObject>,
19-
mutations: List<TopLevelObject> = emptyList(),
20-
config: SchemaGeneratorConfig
20+
mutations: List<TopLevelObject> = emptyList()
2121
): GraphQLSchema {
2222
val generator = SchemaGenerator(config)
2323
return generator.generate(queries, mutations)

src/test/kotlin/com/expedia/graphql/execution/CustomDataFetcherTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CustomDataFetcherTests {
1919
@Test
2020
fun `Custom DataFetcher can be used on functions`() {
2121
val config = SchemaGeneratorConfig(supportedPackages = listOf("com.expedia"), dataFetcherFactoryProvider = CustomDataFetcherFactoryProvider())
22-
val schema = toSchema(listOf(TopLevelObject(AnimalQuery())), config = config)
22+
val schema = toSchema(queries = listOf(TopLevelObject(AnimalQuery())), config = config)
2323

2424
val animalType = schema.getObjectType("Animal")
2525
assertEquals("AnimalDetails!", animalType.getFieldDefinition("details").type.deepName)

src/test/kotlin/com/expedia/graphql/execution/DataFetchPredicateTests.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class DataFetchPredicateTests {
1919
fun `A datafetcher execution is stopped if the predicate test is false`() {
2020
val config = getTestSchemaConfigWithHooks(PredicateHooks())
2121
val schema = toSchema(
22-
listOf(TopLevelObject(QueryWithValidations())),
23-
config = config
22+
queries = listOf(TopLevelObject(QueryWithValidations())),
23+
config = config
2424
)
2525
val graphQL = GraphQL.newGraphQL(schema).build()
2626
val result = graphQL.execute("{ greaterThan2Times10(greaterThan2: 1) }")
@@ -36,8 +36,8 @@ class DataFetchPredicateTests {
3636
fun `A datafetcher execution is stopped if the predicate test is false with complex argument under test`() {
3737
val config = getTestSchemaConfigWithHooks(PredicateHooks())
3838
val schema = toSchema(
39-
listOf(TopLevelObject(QueryWithValidations())),
40-
config = config
39+
queries = listOf(TopLevelObject(QueryWithValidations())),
40+
config = config
4141
)
4242
val graphQL = GraphQL.newGraphQL(schema).build()
4343
val result = graphQL.execute("{ complexPredicate(person: { age: 33, name: \"Alice\"}) }")

src/test/kotlin/com/expedia/graphql/generator/DirectiveTests.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import kotlin.test.assertTrue
1515
class DirectiveTests {
1616
@Test
1717
fun `SchemaGenerator marks deprecated fields in the return objects`() {
18-
val schema = toSchema(listOf(TopLevelObject(QueryWithDeprecatedFields())), config = testSchemaConfig)
18+
val schema = toSchema(queries = listOf(TopLevelObject(QueryWithDeprecatedFields())), config = testSchemaConfig)
1919
val topLevelQuery = schema.getObjectType("Query")
2020
val query = topLevelQuery.getFieldDefinition("deprecatedFieldQuery")
2121
val result = (query.type as? GraphQLNonNull)?.wrappedType as? GraphQLObjectType
@@ -27,7 +27,7 @@ class DirectiveTests {
2727

2828
@Test
2929
fun `SchemaGenerator marks deprecated queries and documents replacement`() {
30-
val schema = toSchema(listOf(TopLevelObject(QueryWithDeprecatedFields())), config = testSchemaConfig)
30+
val schema = toSchema(queries = listOf(TopLevelObject(QueryWithDeprecatedFields())), config = testSchemaConfig)
3131
val topLevelQuery = schema.getObjectType("Query")
3232
val query = topLevelQuery.getFieldDefinition("deprecatedQueryWithReplacement")
3333

@@ -37,7 +37,7 @@ class DirectiveTests {
3737

3838
@Test
3939
fun `SchemaGenerator marks deprecated queries`() {
40-
val schema = toSchema(listOf(TopLevelObject(QueryWithDeprecatedFields())), config = testSchemaConfig)
40+
val schema = toSchema(queries = listOf(TopLevelObject(QueryWithDeprecatedFields())), config = testSchemaConfig)
4141
val topLevelQuery = schema.getObjectType("Query")
4242
val query = topLevelQuery.getFieldDefinition("deprecatedQuery")
4343
assertTrue(query.isDeprecated)
@@ -46,7 +46,7 @@ class DirectiveTests {
4646

4747
@Test
4848
fun `Default directive names are normalized`() {
49-
val schema = toSchema(listOf(TopLevelObject(QueryObject())), config = testSchemaConfig)
49+
val schema = toSchema(queries = listOf(TopLevelObject(QueryObject())), config = testSchemaConfig)
5050

5151
val query = schema.queryType.getFieldDefinition("query")
5252
assertNotNull(query)
@@ -55,7 +55,7 @@ class DirectiveTests {
5555

5656
@Test
5757
fun `Custom directive names are not modified`() {
58-
val schema = toSchema(listOf(TopLevelObject(QueryObject())), config = testSchemaConfig)
58+
val schema = toSchema(queries = listOf(TopLevelObject(QueryObject())), config = testSchemaConfig)
5959

6060
val directive = assertNotNull(
6161
(schema.getType("Location") as? GraphQLObjectType)

src/test/kotlin/com/expedia/graphql/generator/PolymorphicTests.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal class PolymorphicTests {
1616

1717
@Test
1818
fun `Schema generator creates union types from marked up interface`() {
19-
val schema = toSchema(listOf(TopLevelObject(QueryWithUnion())), config = testSchemaConfig)
19+
val schema = toSchema(queries = listOf(TopLevelObject(QueryWithUnion())), config = testSchemaConfig)
2020

2121
val graphqlType = schema.getType("BodyPart") as? GraphQLUnionType
2222
assertNotNull(graphqlType)
@@ -33,7 +33,7 @@ internal class PolymorphicTests {
3333

3434
@Test
3535
fun `SchemaGenerator can expose an interface and its implementations`() {
36-
val schema = toSchema(listOf(TopLevelObject(QueryWithInterface())), config = testSchemaConfig)
36+
val schema = toSchema(queries = listOf(TopLevelObject(QueryWithInterface())), config = testSchemaConfig)
3737

3838
val interfaceType = schema.getType("AnInterface")
3939
assertNotNull(interfaceType)
@@ -47,20 +47,20 @@ internal class PolymorphicTests {
4747
@Test
4848
fun `Interfaces cannot be used as input field types`() {
4949
assertThrows(InvalidInputFieldTypeException::class.java) {
50-
toSchema(listOf(TopLevelObject(QueryWithUnAuthorizedInterfaceArgument())), config = testSchemaConfig)
50+
toSchema(queries = listOf(TopLevelObject(QueryWithUnAuthorizedInterfaceArgument())), config = testSchemaConfig)
5151
}
5252
}
5353

5454
@Test
5555
fun `Union cannot be used as input field types`() {
5656
assertThrows(InvalidInputFieldTypeException::class.java) {
57-
toSchema(listOf(TopLevelObject(QueryWithUnAuthorizedUnionArgument())), config = testSchemaConfig)
57+
toSchema(queries = listOf(TopLevelObject(QueryWithUnAuthorizedUnionArgument())), config = testSchemaConfig)
5858
}
5959
}
6060

6161
@Test
6262
fun `Object types implementing union and interfaces are only created once`() {
63-
val schema = toSchema(listOf(TopLevelObject(QueryWithInterfaceAnUnion())), config = testSchemaConfig)
63+
val schema = toSchema(queries = listOf(TopLevelObject(QueryWithInterfaceAnUnion())), config = testSchemaConfig)
6464

6565
val carType = schema.getType("Car") as? GraphQLObjectType
6666
assertNotNull(carType)
@@ -74,7 +74,7 @@ internal class PolymorphicTests {
7474

7575
@Test
7676
fun `Interfaces can declare properties of their own type`() {
77-
val schema = toSchema(listOf(TopLevelObject(QueryWithRecursiveType())), config = testSchemaConfig)
77+
val schema = toSchema(queries = listOf(TopLevelObject(QueryWithRecursiveType())), config = testSchemaConfig)
7878

7979
val personType = schema.getType("Person")
8080
assertNotNull(personType)

src/test/kotlin/com/expedia/graphql/generator/SchemaGeneratorAsyncTests.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,31 @@ class SchemaGeneratorAsyncTests {
2727

2828
@Test
2929
fun `SchemaGenerator strips type argument from CompletableFuture to support async servlet`() {
30-
val schema = toSchema(listOf(TopLevelObject(AsyncQuery())), config = testSchemaConfig)
30+
val schema = toSchema(queries = listOf(TopLevelObject(AsyncQuery())), config = testSchemaConfig)
3131
val returnTypeName =
3232
(schema.getObjectType("Query").getFieldDefinition("asynchronouslyDo").type as? GraphQLNonNull)?.wrappedType?.name
3333
assertEquals("Int", returnTypeName)
3434
}
3535

3636
@Test
3737
fun `SchemaGenerator strips type argument from RxJava2 Observable`() {
38-
val schema = toSchema(listOf(TopLevelObject(RxJava2Query())), config = configWithRxJavaMonads)
38+
val schema = toSchema(queries = listOf(TopLevelObject(RxJava2Query())), config = configWithRxJavaMonads)
3939
val returnTypeName =
4040
(schema.getObjectType("Query").getFieldDefinition("asynchronouslyDo").type as? GraphQLNonNull)?.wrappedType?.name
4141
assertEquals("Int", returnTypeName)
4242
}
4343

4444
@Test
4545
fun `SchemaGenerator strips type argument from RxJava2 Single`() {
46-
val schema = toSchema(listOf(TopLevelObject(RxJava2Query())), config = configWithRxJavaMonads)
46+
val schema = toSchema(queries = listOf(TopLevelObject(RxJava2Query())), config = configWithRxJavaMonads)
4747
val returnTypeName =
4848
(schema.getObjectType("Query").getFieldDefinition("asynchronouslyDoSingle").type as? GraphQLNonNull)?.wrappedType?.name
4949
assertEquals("Int", returnTypeName)
5050
}
5151

5252
@Test
5353
fun `SchemaGenerator strips type argument from RxJava2 Maybe`() {
54-
val schema = toSchema(listOf(TopLevelObject(RxJava2Query())), config = configWithRxJavaMonads)
54+
val schema = toSchema(queries = listOf(TopLevelObject(RxJava2Query())), config = configWithRxJavaMonads)
5555
val returnTypeName =
5656
(schema.getObjectType("Query").getFieldDefinition("maybe").type as? GraphQLNonNull)?.wrappedType?.name
5757
assertEquals("Int", returnTypeName)

0 commit comments

Comments
 (0)