Hi, is it possible to use PactV3 to test GraphQL q...
# pact-js
j
Hi, is it possible to use PactV3 to test GraphQL queries in Pact-JS on the consumer side? According to the updated docs (thank you for your effort Matt) this is not possible, but I thought what shouldn't be a problem, is to test the POST method with the plain request body. But as soon as I add a body to the
withRequest
method, I get a 500 from the mock server what makes debugging really hard (pushing this issue as it makes it hard to find out whats going on). Is it intended to stick to PactV2 for GraphQL testing or is it possible to create a Pact with a body for the request with PactV3? Just asking here to see if i missed something, otherwise I think I will open a issue with an example.
Example
Copy code
.withRequest({
  method: 'POST',
  path: `/product/graphql`,
  headers: {
    'Content-Type': 'application/json',
    Accept: "application/json",
  },
  // body: { "query":"{ product { data { idProduct name } } }", "variables": null } // fails
  // body: MatchersV3.like({ "query":"{ product { data { idProduct name } } }", "variables": null }) // fails
})
m
We just need to port the graphql interaction from v2 to v3. Take a look at how it is implemented
There may also be an issue opened for this, and it's possible somebody has uploaded a suggested version of that interface which is just a thin wrapper
j
Thank you for the response. Unfortunately I could not find the question mentioned. Acording to the graphql support, I will try to have a look over the weekend. But you would say checking the plain body should be possible? Are there some eaxamples for PactV3 that would show this (examples in
<https://github.com/pact-foundation/pact-js/tree/573b00d5def4362914e885c40803a510ad249575/src/v3|v3>/pact.ts
don't use body in withRequest)? Or should I create a issue with a code example?
j
Ah, I'm quite new to Pact and wasn't aware of the board. Thank you for the link and with it the PoC.
🙌 1
m
nah all good, that probably should be on the Pact JS repo given it’s scoped there and not ecosystem wide. It took me a bit to find also