0

I have implemented GraphQL endpoints with spring boot using the following lib - https://github.com/leangen/graphql-spqr. I currently have junits for REST endpoints using WebTestClient and have tried writing junits for spqr in a similar way but that doesn't work.

GraphQL supports POST method for all the endpoints, so does anybody know how to pass query and mutation requests with web test client OR Is there any other way to write junits for spqr lib?

Som
  • 91
  • 1
  • 10

1 Answers1

0

What is it that doesn't work? GraphQL requests are just normal HTTP requests with (usually) a JSON body, nothing special.

Just POST a JSON with the following fields:

  • query - the query/mutation/subscription
  • operationName - only needed if you're posting multiple queries at once
  • variables - an object with variables e.g. {'name' : 'value'}

You can also pass these as GET params. Check the GraphQL over HTTP spec for more details and examples.

You can use JsonPath to make assertions on the result then.

assertEquals("John Doe", JsonPath.read(result, "$.data.book[0].author"));
kaqqao
  • 12,984
  • 10
  • 64
  • 118