This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
Replies: 2 comments
-
@Nxtra What is the need to set objectMapper in 3 different beans. Just SchemaparserOptions should suffice. Have you tried removing the other beans and checking if its working? |
Beta Was this translation helpful? Give feedback.
0 replies
-
I had problems with ObjectMapper trying to serialize ApplicationPart (uploaded file). This is how I did it ( I intercept the import com.coxautodev.graphql.tools.SchemaParserOptions;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import graphql.schema.*;
import graphql.servlet.core.ApolloScalars;
import graphql.servlet.core.DefaultObjectMapperConfigurer;
import org.apache.catalina.core.ApplicationPart;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class GraphQLConfig {
@Bean
public GraphQLScalarType uploadScalar() {
return ApolloScalars.Upload;
}
@Bean
public SchemaParserOptions schemaParserOptions() {
var defaultObjectMapperConfigurer = new DefaultObjectMapperConfigurer();
return SchemaParserOptions.newOptions()
.objectMapperProvider(fieldDefinition -> {
var mapper = new ObjectMapper() {
@Override
protected Object _convert(Object fromValue, JavaType toValueType) throws IllegalArgumentException {
if (toValueType.getRawClass().equals(ApplicationPart.class)) {
return fromValue;
}
if (toValueType.hasContentType()
&& toValueType.getContentType().getRawClass().equals(ApplicationPart.class)) {
return fromValue;
}
return super._convert(fromValue, toValueType);
}
};
defaultObjectMapperConfigurer.configure(mapper);
return mapper;
})
.build();
}
} This is what I have in the graphql Mutation scalar Upload
type Mutation {
saveOrder(attachments: [Upload!]!, order: OrderInput!): Order
} In the service: import com.coxautodev.graphql.tools.GraphQLMutationResolver;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class OrderService implements GraphQLMutationResolver {
@Transactional
public Order saveOrder(List<ApplicationPart> attachments, @NotNull Order order) {
//
}
} my build.gradle: dependencies {
implementation("com.graphql-java-kickstart:graphql-spring-boot-starter:5.10.0")
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How can I specify an ObjectMapper that has to be used when calling the
/graphql
endpoint?I found this issue: #97. Where a combination of
ObjectMapperConfigurer
andschemaParserOptions
is mentioned.I currently have the following
JacksonConfig
.As you can see I am trying to set a different setting for
DefaultPropertyInclusion
when calling the\graphql
endpoint.(This is because I want the empty
interfaces: []
array to be in the response from the introspection)However, currently with the above configuration, the ObjectMapper with
DefaultPropertyInclusion
=NON_EMPTY
is still being used when doing the graphql introspection. Instead of the ObjectMapper withDefaultPropertyInclusion
=NON_NULL
.Can you help me with how I should configure a custom ObjectMapper for the queries on
/graphql
?Beta Was this translation helpful? Give feedback.
All reactions