|
19 | 19 |
|
20 | 20 | package com.oembedler.moon.graphql.boot; |
21 | 21 |
|
| 22 | +import com.coxautodev.graphql.tools.PerFieldObjectMapperProvider; |
| 23 | +import com.fasterxml.jackson.databind.InjectableValues; |
| 24 | +import com.fasterxml.jackson.databind.ObjectMapper; |
22 | 25 | import graphql.execution.AsyncExecutionStrategy; |
23 | 26 | import graphql.execution.ExecutionStrategy; |
24 | 27 | import graphql.execution.SubscriptionExecutionStrategy; |
25 | 28 | import graphql.execution.instrumentation.ChainedInstrumentation; |
26 | 29 | import graphql.execution.instrumentation.Instrumentation; |
27 | 30 | import graphql.execution.preparsed.PreparsedDocumentProvider; |
28 | 31 | import graphql.schema.GraphQLSchema; |
29 | | -import graphql.servlet.*; |
| 32 | +import graphql.servlet.AbstractGraphQLHttpServlet; |
| 33 | +import graphql.servlet.DefaultExecutionStrategyProvider; |
| 34 | +import graphql.servlet.DefaultGraphQLSchemaProvider; |
| 35 | +import graphql.servlet.ExecutionStrategyProvider; |
| 36 | +import graphql.servlet.GraphQLContextBuilder; |
| 37 | +import graphql.servlet.GraphQLErrorHandler; |
| 38 | +import graphql.servlet.GraphQLInvocationInputFactory; |
| 39 | +import graphql.servlet.GraphQLObjectMapper; |
| 40 | +import graphql.servlet.GraphQLQueryInvoker; |
| 41 | +import graphql.servlet.GraphQLRootObjectBuilder; |
| 42 | +import graphql.servlet.GraphQLSchemaProvider; |
| 43 | +import graphql.servlet.GraphQLServletListener; |
| 44 | +import graphql.servlet.ObjectMapperConfigurer; |
| 45 | +import graphql.servlet.ObjectMapperProvider; |
| 46 | +import graphql.servlet.SimpleGraphQLHttpServlet; |
30 | 47 | import org.springframework.beans.factory.annotation.Autowired; |
31 | | -import org.springframework.beans.factory.annotation.Value; |
32 | 48 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; |
33 | | -import org.springframework.boot.autoconfigure.condition.*; |
| 49 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
| 50 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; |
| 51 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
| 52 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| 53 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; |
34 | 54 | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
35 | 55 | import org.springframework.boot.web.servlet.ServletRegistrationBean; |
36 | 56 | import org.springframework.context.annotation.Bean; |
|
45 | 65 | import java.util.Map; |
46 | 66 | import java.util.Optional; |
47 | 67 |
|
| 68 | +import static graphql.servlet.GraphQLObjectMapper.newBuilder; |
| 69 | + |
48 | 70 |
|
49 | 71 | /** |
50 | 72 | * @author <a href="mailto:java.lang.RuntimeException@gmail.com">oEmbedler Inc.</a> |
@@ -182,20 +204,35 @@ public GraphQLQueryInvoker queryInvoker(ExecutionStrategyProvider executionStrat |
182 | 204 |
|
183 | 205 | @Bean |
184 | 206 | @ConditionalOnMissingBean |
185 | | - public GraphQLObjectMapper graphQLObjectMapper() { |
186 | | - GraphQLObjectMapper.Builder builder = GraphQLObjectMapper.newBuilder(); |
| 207 | + public GraphQLObjectMapper graphQLObjectMapper(Optional<ObjectMapperProvider> objectMapperProvider) { |
| 208 | + GraphQLObjectMapper.Builder builder = newBuilder(); |
187 | 209 |
|
188 | 210 | if (errorHandler != null) { |
189 | 211 | builder.withGraphQLErrorHandler(errorHandler); |
190 | 212 | } |
191 | 213 |
|
192 | | - if (objectMapperConfigurer != null) { |
| 214 | + if (objectMapperProvider.isPresent()){ |
| 215 | + builder.withObjectMapperProvider(objectMapperProvider.get()); |
| 216 | + } else if (objectMapperConfigurer != null) { |
193 | 217 | builder.withObjectMapperConfigurer(objectMapperConfigurer); |
194 | 218 | } |
195 | 219 |
|
196 | 220 | return builder.build(); |
197 | 221 | } |
198 | 222 |
|
| 223 | + @Bean |
| 224 | + @ConditionalOnMissingBean |
| 225 | + @ConditionalOnProperty(value="graphql.servlet.use-default-objectmapper", havingValue = "true", |
| 226 | + matchIfMissing = true) |
| 227 | + public ObjectMapperProvider objectMapperProvider(ObjectMapper objectMapper) { |
| 228 | + |
| 229 | + InjectableValues.Std injectableValues = new InjectableValues.Std(); |
| 230 | + injectableValues.addValue(ObjectMapper.class, objectMapper); |
| 231 | + objectMapper.setInjectableValues(injectableValues); |
| 232 | + return () -> objectMapper; |
| 233 | + } |
| 234 | + |
| 235 | + |
199 | 236 |
|
200 | 237 | @Bean |
201 | 238 | @ConditionalOnMissingBean |
|
0 commit comments