Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide hook with access to schema mappings inspection report #672

Closed
rstoyanchev opened this issue Apr 20, 2023 · 6 comments
Closed

Provide hook with access to schema mappings inspection report #672

rstoyanchev opened this issue Apr 20, 2023 · 6 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Apr 20, 2023

We can expose a hook that provides access to the Report and allows applications to take some actions. The default action would be to log it, which is what we do currently.

Requested in #386 (comment).

@rstoyanchev rstoyanchev added the type: enhancement A general enhancement label Apr 20, 2023
@rstoyanchev rstoyanchev added this to the 1.2.0 milestone Apr 20, 2023
@rstoyanchev rstoyanchev self-assigned this Apr 20, 2023
@rstoyanchev
Copy link
Contributor Author

rstoyanchev commented Apr 20, 2023

Something like this, which can then be applied from a GraphQlSourceBuilderCustomizer bean with Boot:

GraphQlSource.schemaResourceBuilder()
		.schemaResources()
		.inspectSchemaMappings(report -> {
			// ...
		})
		.build();

If this is configured, we won't log the report. It'll be all up to the callback.

@danielshiplett
Copy link

Yes. I think that is a good approach with the customizer + default with the option to use our own implementation.

@bclozel
Copy link
Member

bclozel commented Apr 21, 2023

I think we need to significantly refactor the Report contract to provide higher abstractions and prepare for new behavior.

@rstoyanchev
Copy link
Contributor Author

@danielshiplett I've added a Consumer<SchemaReport> hook to GraphQlSource.Builder that also enables the inspection. So you can configure it, and either log and/or take any other action. If not configured, the inspection does not run. Please, have a look to see what's in the report, and give us your feedback.

@danielshiplett
Copy link

@rstoyanchev This seems to work as expected. I have created a demonstration that invokes Spring's Failure Analysis feature to stop the application and provide feedback. Here is the configuration class that does that.

Here is some example output where a single mapping and a single registration were in error:

2023-04-28T13:50:26.685-04:00  INFO 2216713 --- [  restartedMain] efaultSchemaResourceGraphQlSourceBuilder : Loaded 2 resource(s) in the GraphQL schema.
2023-04-28T13:50:26.828-04:00  WARN 2216713 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'routerFunctionMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Error creating bean with name 'graphQlRouterFunction' defined in class path resource [org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfiguration.class]: Unsatisfied dependency expressed through method 'graphQlRouterFunction' parameter 0: Error creating bean with name 'graphQlHttpHandler' defined in class path resource [org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfiguration.class]: Unsatisfied dependency expressed through method 'graphQlHttpHandler' parameter 0: Error creating bean with name 'webGraphQlHandler' defined in class path resource [org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfiguration.class]: Unsatisfied dependency expressed through method 'webGraphQlHandler' parameter 0: Error creating bean with name 'executionGraphQlService' defined in class path resource [org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfiguration.class]: Unsatisfied dependency expressed through method 'executionGraphQlService' parameter 0: Error creating bean with name 'graphQlSource' defined in class path resource [org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfiguration.class]: Failed to instantiate [org.springframework.graphql.execution.GraphQlSource]: Factory method 'graphQlSource' threw exception with message: See description
2023-04-28T13:50:26.830-04:00  INFO 2216713 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2023-04-28T13:50:26.840-04:00  INFO 2216713 --- [  restartedMain] .s.b.a.l.ConditionEvaluationReportLogger : 

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-04-28T13:50:26.853-04:00 ERROR 2216713 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Invalid schema mappings.  SchemaReport:

GraphQL schema inspection:
        Unmapped fields: {User=[comments]}
        Unmapped registrations: {User.age=UserController#age[1 args]}
        Skipped types: []


Action:

See description for details of invalid schema mappings.

@rstoyanchev
Copy link
Contributor Author

rstoyanchev commented May 2, 2023

Thanks for confirming and for the example! I noticed a few bullet items under the Status section in the README. Is there anything there that remains not done?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants