Netflix / dgs-framework

GraphQL for Java with Spring Boot made easy.
https://netflix.github.io/dgs
Apache License 2.0
3.08k stars 296 forks source link

bug: Cannot disable introspection point due to an error. #2024

Open nmartin-RatedPower opened 1 month ago

nmartin-RatedPower commented 1 month ago

Please read our contributor guide before creating an issue.

Expected behavior

It is expected that setting the dgs.graphql.introspection.enabled=false property will disable introspection.

Actual behavior

The property dgs.graphql.introspection.enabled=false is set but the application returns the following message.

11:51:40.143 [main] WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'disableIntrospectionContextContributor' defined in class path resource [com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.class]: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=com.netflix.graphql.dgs.autoconfig.DgsAutoConfiguration; factoryMethodName=disableIntrospectionContextContributor; initMethodNames=null; destroyMethodNames=[(inferred)]; defined in class path resource [com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.class]] for bean 'disableIntrospectionContextContributor' since there is already [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=com.netflix.graphql.dgs.springgraphql.autoconfig.DgsSpringGraphQLAutoConfiguration; factoryMethodName=disableIntrospectionContextContributor; initMethodNames=null; destroyMethodNames=[(inferred)]; defined in class path resource [com/netflix/graphql/dgs/springgraphql/autoconfig/DgsSpringGraphQLAutoConfiguration.class]] bound. 
11:51:40.150 [main] INFO  o.s.b.a.l.ConditionEvaluationReportLogger - 

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 
11:51:40.166 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter - 

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

Description:

The bean 'disableIntrospectionContextContributor', defined in class path resource [com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [com/netflix/graphql/dgs/springgraphql/autoconfig/DgsSpringGraphQLAutoConfiguration.class] and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

It works correctly if done through the spring property.

Steps to reproduce

I just added the property in my .properties file. Anyways I think could be useful specify the versions wich in working with:

DGS version 9.1.1 Springboot version 3.3.0

If you have any doubt don't hesite to ask question about it.

Note: A test case would be highly appreciated, but we understand that's not always possible

ThomasD281 commented 3 weeks ago

I see same problem and can only enable introspection by setting these properties both to true

dgs.graphql.introspection.enabled: true spring.graphql.schema.introspectionenabled: true

If both are false the same exception as stated above occurs. Setting one of these properties to true and the other to false does not make introspection working for me.

dgs-version: 9.1.2 spring-boot: 3.3.0

nmartin-RatedPower commented 2 weeks ago

Any update?

ls-urs-keller commented 2 weeks ago

I also have this problem, I looked into the configurations:

Setting dgs.graphql.introspection.enabled=false also automagically sets spring.graphql.schema.introspection.enabled=false resulting in this error:

The bean 'disableIntrospectionContextContributor', defined in class path resource [com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [com/netflix/graphql/dgs/springgraphql/autoconfig/DgsSpringGraphQLAutoConfiguration.class] and overriding is disabled.

When running with debug=true:

   DgsAutoConfiguration#disableIntrospectionContextContributor matched:
      - @ConditionalOnProperty (dgs.graphql.introspection.enabled=false) matched (OnPropertyCondition)

   DgsSpringGraphQLAutoConfiguration#disableIntrospectionContextContributor matched:
      - @ConditionalOnProperty (spring.graphql.schema.introspection.enabled=false) matched (OnPropertyCondition)

I only set dgs.graphql.introspection.enabled=false the spring.graphql.schema.introspection.enabled=false seems to be automatically set when the former is set.

I guess since DgsSpringGraphQLAutoConfiguration runs before DgsAutoConfiguration the disableIntrospectionContextContributor bean defined in DgsAutoConfiguration should have the annotation @ConditionalOnMissingBean

Setting spring.graphql.schema.introspection.enabled=false instead of dgs.graphql.introspection.enabled=false is a workable solution for us.