1
votes

Hi I've used SpringBoot to set up a GraphQL server. I've been able to send queries with no issue if I use GrapiQL, Postman, or a web browser to do so. The issue is I've got an Android app that uses ApolloClient to make requests to the same GraphQL server and whenever it sends a request I've been getting a 422 error.

I know now that the issue is with the content type header that ApolloClient sends out. It sets the content type to be "application/json; charset=UTF-8" while all the other methods set it to just "application/json".

So looking around online I see only two options. One is to modify the request ApolloClient sends out so it doesn't include "charset=UTF-8", and the other is to reconfigure my server so that it can accept that request as is.

Changing the request seems to be a relatively painful process and it seems like adding the charset is fairly common, so I'd like to have the server accept requests with the charset. My issue is that I'm really new to Springboot and I'm not really sure how to go about doing that.

To be honest I also did try to modify the request to remove the charset portion but somehow it still ended up in the final request.

I used the Spring Initializr site to set up the server and only added the Web dependency. I took it as is and the only thing I added was a logger.

I've included the pom file below, but please let me know if any other files or info would be helpful.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.graphql-java.tutorial</groupId>
    <artifactId>book-details</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>book-details</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>19.0</version>
        </dependency>

        <dependency>
            <groupId>com.graphql-java</groupId>
            <artifactId>graphql-java</artifactId>
            <version>11.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.graphql-java/graphql-java-spring-boot-starter-webmvc -->
        <dependency>
            <groupId>com.graphql-java</groupId>
            <artifactId>graphql-java-spring-boot-starter-webmvc</artifactId>
            <version>2019-06-24T11-47-27-31ab4f9</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

If someone could just help guide me as to how I can have my server accept requests with the content type set to "application/json; charset=UTF-8" I'd really appreciate it. I'd also like to make sure the server keeps accepting the content being just "application/json" as it is currently. I appreciate your help and thanks in advance.

1

1 Answers

0
votes

Try removing the charser=UTF-8, you should be able to get rid off the 422 error.