Skip to main content
added 1046 characters in body
Source Link
Alexey R.
  • 11.6k
  • 5
  • 20
  • 39

You should approach with REST Assured one more time. Actually it should perfectly fit your needs. When you run GraphQL service you basically run a REST end-point where you send some query and receive JSON as a response.

So nothing prevents you from using REST Assured since you can send whatever as a requests and at the same time it provides good tool set for parsing JSON response.

UPD:

Below you can find my example for your case (Rest Assured + TestNg):

@Test
public void testGraphQL() throws MalformedURLException {
    String actual = RestAssured.
                                given()
                                    .header(new Header("Content-type", "application/json"))
                                    .body("{\"query\":\"{\\n Country(id: \\\"us\\\") {\\n name\\n situation\\n }\\n}\\n \"}")
                                .post(new URL("https://portal.ehri-project.eu/api/graphql"))
                                .jsonPath().getString("data.Country.name");
    Assert.assertEquals(actual, "United Sttates");
}

With the following output:

java.lang.AssertionError: expected [United Sttates] but found [United States]
Expected :United Sttates
Actual   :United States
 <Click to see difference>

P.S. - This is the query that you have provided in your comment, however you can omit \n with no impact to your test.

You should approach with REST Assured one more time. Actually it should perfectly fit your needs. When you run GraphQL service you basically run a REST end-point where you send some query and receive JSON as a response.

So nothing prevents you from using REST Assured since you can send whatever as a requests and at the same time it provides good tool set for parsing JSON response.

You should approach with REST Assured one more time. Actually it should perfectly fit your needs. When you run GraphQL service you basically run a REST end-point where you send some query and receive JSON as a response.

So nothing prevents you from using REST Assured since you can send whatever as a requests and at the same time it provides good tool set for parsing JSON response.

UPD:

Below you can find my example for your case (Rest Assured + TestNg):

@Test
public void testGraphQL() throws MalformedURLException {
    String actual = RestAssured.
                                given()
                                    .header(new Header("Content-type", "application/json"))
                                    .body("{\"query\":\"{\\n Country(id: \\\"us\\\") {\\n name\\n situation\\n }\\n}\\n \"}")
                                .post(new URL("https://portal.ehri-project.eu/api/graphql"))
                                .jsonPath().getString("data.Country.name");
    Assert.assertEquals(actual, "United Sttates");
}

With the following output:

java.lang.AssertionError: expected [United Sttates] but found [United States]
Expected :United Sttates
Actual   :United States
 <Click to see difference>

P.S. - This is the query that you have provided in your comment, however you can omit \n with no impact to your test.

Source Link
Alexey R.
  • 11.6k
  • 5
  • 20
  • 39

You should approach with REST Assured one more time. Actually it should perfectly fit your needs. When you run GraphQL service you basically run a REST end-point where you send some query and receive JSON as a response.

So nothing prevents you from using REST Assured since you can send whatever as a requests and at the same time it provides good tool set for parsing JSON response.