From 0362bdf100b4b89200a34807da61fad7d8bc8778 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Thu, 8 Dec 2022 17:06:43 +0100 Subject: [PATCH] Log schema resources during application startup This commit logs the number of schema resources that were loaded to create the GraphQL schema, at the INFO level. If DEBUG is enabled for this package, the description of all schema resources will be logged as well. Closes gh-566 --- .../DefaultSchemaResourceGraphQlSourceBuilder.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultSchemaResourceGraphQlSourceBuilder.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultSchemaResourceGraphQlSourceBuilder.java index 1a722f79..4aff26ec 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultSchemaResourceGraphQlSourceBuilder.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultSchemaResourceGraphQlSourceBuilder.java @@ -24,6 +24,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.function.BiFunction; +import java.util.stream.Collectors; import graphql.language.InterfaceTypeDefinition; import graphql.language.UnionTypeDefinition; @@ -36,6 +37,8 @@ import graphql.schema.idl.SchemaGenerator; import graphql.schema.idl.SchemaParser; import graphql.schema.idl.TypeDefinitionRegistry; import graphql.schema.idl.WiringFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.core.io.Resource; import org.springframework.lang.Nullable; @@ -53,6 +56,8 @@ final class DefaultSchemaResourceGraphQlSourceBuilder extends AbstractGraphQlSourceBuilder implements GraphQlSource.SchemaResourceBuilder { + private static final Log logger = LogFactory.getLog(DefaultSchemaResourceGraphQlSourceBuilder.class); + private final Set schemaResources = new LinkedHashSet<>(); private final List runtimeWiringConfigurers = new ArrayList<>(); @@ -98,6 +103,14 @@ final class DefaultSchemaResourceGraphQlSourceBuilder .reduce(TypeDefinitionRegistry::merge) .orElseThrow(MissingSchemaException::new); + logger.info("Loaded " + this.schemaResources.size() + " resource(s) in the GraphQL schema."); + if (logger.isDebugEnabled()) { + String resources = this.schemaResources.stream() + .map(Resource::getDescription) + .collect(Collectors.joining(",")); + logger.debug("Loaded GraphQL schema resources: (" + resources + ")"); + } + RuntimeWiring runtimeWiring = initRuntimeWiring(); TypeResolver typeResolver = initTypeResolver();