Skip to content

Commit

Permalink
feat: config property to print schema (#1645)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelAndalon authored Jan 17, 2023
1 parent cd32413 commit 46a7c77
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Expedia, Inc
* Copyright 2023 Expedia, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -79,18 +79,16 @@ class FederatedSchemaAutoConfiguration(
subscriptions: Optional<List<Subscription>>,
schemaConfig: FederatedSchemaGeneratorConfig,
schemaObject: Optional<Schema>
): GraphQLSchema {
val schema = toFederatedSchema(
config = schemaConfig,
queries = queries.orElse(emptyList()).toTopLevelObjects(),
mutations = mutations.orElse(emptyList()).toTopLevelObjects(),
subscriptions = subscriptions.orElse(emptyList()).toTopLevelObjects(),
schemaObject = schemaObject.orElse(null)?.toTopLevelObject()
)

logger.info("\n${schema.print()}")

return schema
): GraphQLSchema = toFederatedSchema(
config = schemaConfig,
queries = queries.orElse(emptyList()).toTopLevelObjects(),
mutations = mutations.orElse(emptyList()).toTopLevelObjects(),
subscriptions = subscriptions.orElse(emptyList()).toTopLevelObjects(),
schemaObject = schemaObject.orElse(null)?.toTopLevelObject()
).also { federatedSchema ->
if (config.printSchema) {
logger.info("\n${federatedSchema.print()}")
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ data class GraphQLConfigurationProperties(
val endpoint: String = "graphql",
/** List of supported packages that can contain GraphQL schema type definitions */
val packages: List<String>,
/** Boolean flag indicating whether to print the schema after generator creates it */
val printSchema: Boolean = false,
val federation: FederationConfigurationProperties = FederationConfigurationProperties(),
val subscriptions: SubscriptionConfigurationProperties = SubscriptionConfigurationProperties(),
val playground: PlaygroundConfigurationProperties = PlaygroundConfigurationProperties(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Expedia, Inc
* Copyright 2023 Expedia, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Expedia, Inc
* Copyright 2023 Expedia, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -45,27 +45,25 @@ import java.util.Optional
@ConditionalOnProperty(value = ["graphql.federation.enabled"], havingValue = "false", matchIfMissing = true)
@Configuration
@Import(GraphQLExecutionConfiguration::class)
class NonFederatedSchemaAutoConfiguration {
class NonFederatedSchemaAutoConfiguration(
private val config: GraphQLConfigurationProperties
) {

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

@Bean
@ConditionalOnMissingBean
fun schemaConfig(
config: GraphQLConfigurationProperties,
topLevelNames: Optional<TopLevelNames>,
hooks: Optional<SchemaGeneratorHooks>,
dataFetcherFactoryProvider: KotlinDataFetcherFactoryProvider
): SchemaGeneratorConfig {
val generatorHooks = hooks.orElse(NoopSchemaGeneratorHooks)
return SchemaGeneratorConfig(
supportedPackages = config.packages,
topLevelNames = topLevelNames.orElse(TopLevelNames()),
hooks = generatorHooks,
dataFetcherFactoryProvider = dataFetcherFactoryProvider,
introspectionEnabled = config.introspection.enabled
)
}
): SchemaGeneratorConfig = SchemaGeneratorConfig(
supportedPackages = config.packages,
topLevelNames = topLevelNames.orElse(TopLevelNames()),
hooks = hooks.orElse(NoopSchemaGeneratorHooks),
dataFetcherFactoryProvider = dataFetcherFactoryProvider,
introspectionEnabled = config.introspection.enabled
)

@Bean
@ConditionalOnMissingBean
Expand All @@ -75,17 +73,15 @@ class NonFederatedSchemaAutoConfiguration {
subscriptions: Optional<List<Subscription>>,
schemaConfig: SchemaGeneratorConfig,
schemaObject: Optional<Schema>
): GraphQLSchema {
val schema = toSchema(
config = schemaConfig,
queries = queries.orElse(emptyList()).toTopLevelObjects(),
mutations = mutations.orElse(emptyList()).toTopLevelObjects(),
subscriptions = subscriptions.orElse(emptyList()).toTopLevelObjects(),
schemaObject = schemaObject.orElse(null)?.toTopLevelObject()
)

logger.info("\n${schema.print()}")

return schema
): GraphQLSchema = toSchema(
config = schemaConfig,
queries = queries.orElse(emptyList()).toTopLevelObjects(),
mutations = mutations.orElse(emptyList()).toTopLevelObjects(),
subscriptions = subscriptions.orElse(emptyList()).toTopLevelObjects(),
schemaObject = schemaObject.orElse(null)?.toTopLevelObject()
).also { schema ->
if (config.printSchema) {
logger.info("\n${schema.print()}")
}
}
}

0 comments on commit 46a7c77

Please sign in to comment.