Skip to content

Commit 1965d28

Browse files
feat: config property to print schema (ExpediaGroup#1641)
* feat: config property to print schema * chore: update covered ratio
1 parent 32102b5 commit 1965d28

File tree

6 files changed

+45
-43
lines changed

6 files changed

+45
-43
lines changed

servers/graphql-kotlin-spring-server/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ tasks {
2727
limit {
2828
counter = "INSTRUCTION"
2929
value = "COVEREDRATIO"
30-
minimum = "0.86".toBigDecimal()
30+
minimum = "0.85".toBigDecimal()
3131
}
3232
limit {
3333
counter = "BRANCH"

servers/graphql-kotlin-spring-server/src/main/kotlin/com/expediagroup/graphql/server/spring/FederatedSchemaAutoConfiguration.kt

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 Expedia, Inc
2+
* Copyright 2023 Expedia, Inc
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -54,8 +54,12 @@ class FederatedSchemaAutoConfiguration(
5454

5555
@Bean
5656
@ConditionalOnMissingBean
57-
fun federatedSchemaGeneratorHooks(resolvers: Optional<List<FederatedTypeResolver>>): FederatedSchemaGeneratorHooks =
58-
FederatedSchemaGeneratorHooks(resolvers.orElse(emptyList()), config.federation.optInV2)
57+
fun federatedSchemaGeneratorHooks(
58+
resolvers: Optional<List<FederatedTypeResolver>>
59+
): FederatedSchemaGeneratorHooks = FederatedSchemaGeneratorHooks(
60+
resolvers.orElse(emptyList()),
61+
config.federation.optInV2
62+
)
5963

6064
@Bean
6165
@ConditionalOnMissingBean
@@ -79,18 +83,16 @@ class FederatedSchemaAutoConfiguration(
7983
subscriptions: Optional<List<Subscription>>,
8084
schemaConfig: FederatedSchemaGeneratorConfig,
8185
schemaObject: Optional<Schema>
82-
): GraphQLSchema {
83-
val schema = toFederatedSchema(
84-
config = schemaConfig,
85-
queries = queries.orElse(emptyList()).toTopLevelObjects(),
86-
mutations = mutations.orElse(emptyList()).toTopLevelObjects(),
87-
subscriptions = subscriptions.orElse(emptyList()).toTopLevelObjects(),
88-
schemaObject = schemaObject.orElse(null)?.toTopLevelObject()
89-
)
90-
91-
logger.info("\n${schema.print()}")
92-
93-
return schema
86+
): GraphQLSchema = toFederatedSchema(
87+
config = schemaConfig,
88+
queries = queries.orElse(emptyList()).toTopLevelObjects(),
89+
mutations = mutations.orElse(emptyList()).toTopLevelObjects(),
90+
subscriptions = subscriptions.orElse(emptyList()).toTopLevelObjects(),
91+
schemaObject = schemaObject.orElse(null)?.toTopLevelObject()
92+
).also { federatedSchema ->
93+
if (config.printSchema) {
94+
logger.info("\n${federatedSchema.print()}")
95+
}
9496
}
9597

9698
/**

servers/graphql-kotlin-spring-server/src/main/kotlin/com/expediagroup/graphql/server/spring/GraphQLConfigurationProperties.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ data class GraphQLConfigurationProperties(
2929
val endpoint: String = "graphql",
3030
/** List of supported packages that can contain GraphQL schema type definitions */
3131
val packages: List<String>,
32+
/** Boolean flag indicating whether to print the schema after generator creates it */
33+
val printSchema: Boolean = false,
3234
val federation: FederationConfigurationProperties = FederationConfigurationProperties(),
3335
val subscriptions: SubscriptionConfigurationProperties = SubscriptionConfigurationProperties(),
3436
val playground: PlaygroundConfigurationProperties = PlaygroundConfigurationProperties(),

servers/graphql-kotlin-spring-server/src/main/kotlin/com/expediagroup/graphql/server/spring/GraphQLSchemaConfiguration.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 Expedia, Inc
2+
* Copyright 2023 Expedia, Inc
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -136,7 +136,8 @@ class GraphQLSchemaConfiguration {
136136

137137
@Bean
138138
@ConditionalOnMissingBean
139-
fun springGraphQLContextFactory(): SpringGraphQLContextFactory = DefaultSpringGraphQLContextFactory()
139+
fun springGraphQLContextFactory(): SpringGraphQLContextFactory =
140+
DefaultSpringGraphQLContextFactory()
140141

141142
@Bean
142143
@ConditionalOnMissingBean

servers/graphql-kotlin-spring-server/src/main/kotlin/com/expediagroup/graphql/server/spring/NonFederatedSchemaAutoConfiguration.kt

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 Expedia, Inc
2+
* Copyright 2023 Expedia, Inc
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,27 +45,25 @@ import java.util.Optional
4545
@ConditionalOnProperty(value = ["graphql.federation.enabled"], havingValue = "false", matchIfMissing = true)
4646
@Configuration
4747
@Import(GraphQLExecutionConfiguration::class)
48-
class NonFederatedSchemaAutoConfiguration {
48+
class NonFederatedSchemaAutoConfiguration(
49+
private val config: GraphQLConfigurationProperties
50+
) {
4951

5052
private val logger = LoggerFactory.getLogger(NonFederatedSchemaAutoConfiguration::class.java)
5153

5254
@Bean
5355
@ConditionalOnMissingBean
5456
fun schemaConfig(
55-
config: GraphQLConfigurationProperties,
5657
topLevelNames: Optional<TopLevelNames>,
5758
hooks: Optional<SchemaGeneratorHooks>,
5859
dataFetcherFactoryProvider: KotlinDataFetcherFactoryProvider
59-
): SchemaGeneratorConfig {
60-
val generatorHooks = hooks.orElse(NoopSchemaGeneratorHooks)
61-
return SchemaGeneratorConfig(
62-
supportedPackages = config.packages,
63-
topLevelNames = topLevelNames.orElse(TopLevelNames()),
64-
hooks = generatorHooks,
65-
dataFetcherFactoryProvider = dataFetcherFactoryProvider,
66-
introspectionEnabled = config.introspection.enabled
67-
)
68-
}
60+
): SchemaGeneratorConfig = SchemaGeneratorConfig(
61+
supportedPackages = config.packages,
62+
topLevelNames = topLevelNames.orElse(TopLevelNames()),
63+
hooks = hooks.orElse(NoopSchemaGeneratorHooks),
64+
dataFetcherFactoryProvider = dataFetcherFactoryProvider,
65+
introspectionEnabled = config.introspection.enabled
66+
)
6967

7068
@Bean
7169
@ConditionalOnMissingBean
@@ -75,17 +73,15 @@ class NonFederatedSchemaAutoConfiguration {
7573
subscriptions: Optional<List<Subscription>>,
7674
schemaConfig: SchemaGeneratorConfig,
7775
schemaObject: Optional<Schema>
78-
): GraphQLSchema {
79-
val schema = toSchema(
80-
config = schemaConfig,
81-
queries = queries.orElse(emptyList()).toTopLevelObjects(),
82-
mutations = mutations.orElse(emptyList()).toTopLevelObjects(),
83-
subscriptions = subscriptions.orElse(emptyList()).toTopLevelObjects(),
84-
schemaObject = schemaObject.orElse(null)?.toTopLevelObject()
85-
)
86-
87-
logger.info("\n${schema.print()}")
88-
89-
return schema
76+
): GraphQLSchema = toSchema(
77+
config = schemaConfig,
78+
queries = queries.orElse(emptyList()).toTopLevelObjects(),
79+
mutations = mutations.orElse(emptyList()).toTopLevelObjects(),
80+
subscriptions = subscriptions.orElse(emptyList()).toTopLevelObjects(),
81+
schemaObject = schemaObject.orElse(null)?.toTopLevelObject()
82+
).also { schema ->
83+
if (config.printSchema) {
84+
logger.info("\n${schema.print()}")
85+
}
9086
}
9187
}

website/docs/server/spring-server/spring-properties.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ details on the supported configuration properties.
1111
|-----------------------------------------|------------------------------------------------------------------------------------------------------------------|-------------------------------|
1212
| graphql.endpoint | GraphQL server endpoint | graphql |
1313
| graphql.packages | List of supported packages that can contain GraphQL schema type definitions | |
14+
| graphql.printSchema | Boolean flag indicating whether to print the schema after generator creates it | false |
1415
| graphql.federation.enabled | Boolean flag indicating whether to generate federated GraphQL model | false |
1516
| graphql.federation.optInV2 | Boolean flag indicating whether to generate Federation v2 GraphQL model | false |
1617
| graphql.federation.tracing.enabled | Boolean flag indicating whether add federated tracing data to the extensions | true (if federation enabled) |

0 commit comments

Comments
 (0)