https://pact.io logo
#pactflow
Title
# pactflow
h

Harris Lee

05/23/2022, 3:17 AM
HI there, quick questions regarding BDCT graphql, I know supporting graphql schema is on a roadmap, but is there any way I can use quick BDCT POC for graphql? What is the best strategies for the provider side? convert graphql schema to openapi doc? , btw our provider is REST api but wrapped in graphql mesh, and consumer is graphql. thanks 🙂
m

Matt (pactflow.io / pact-js / pact-go)

05/23/2022, 3:19 AM
I haven’t come across any ways to make BDCT and GraphQL work with OAS at this stage. If you can do that, that’s definitely plausible. I’d be surprised though, because the queries would be pretty darn hard to transpose into OAS JSON Schemas
I’d probably stick with standard CDCT for this
h

Harris Lee

05/23/2022, 3:40 AM
cool thanks for that, the reason I want to try BDCT is I can use current MSW, but yeap I will stick to CDCT for now 🙂 thanks
👍 1
m

Matt (pactflow.io / pact-js / pact-go)

05/23/2022, 3:40 AM
That’s great to know! cc @Yousaf Nabi (pactflow.io)
when we get to GraphQL we’ll definitely announce it here in the #graphql chan
❤️ 1
y

Yousaf Nabi (pactflow.io)

05/23/2022, 10:27 AM
👋 I assume you’ve seen our MSW adapter https://docs.pactflow.io/docs/bi-directional-contract-testing/tools/msw I’ve not got support in for graphQL yet. I mentioned
Not currently tested, please feel free to help contribute or let us know if you want to see it!
I’ve not used gQL for some years now on a project. On gQL -> OpenAPI https://github.com/schwer/graphql-to-openapi On the OpenAPI -> gQL, I have seen https://github.com/IBM/openapi-to-graphql Wonder if they might be worth having a play around with? Open to contributions to the pact-msw-adapter 🙌🏻
👍 2
m

Matt (pactflow.io / pact-js / pact-go)

05/23/2022, 10:35 AM
Yeah, so https://schwer.github.io/graphql-to-openapi/ is useless as far as a contract test is concerned. Because, it turns a structured query into a
string
, so now we have zero confidence that a given consumer query is compatible with a given provider (the other way around is much easier, as IBM have discovered)
i.e. in their example:
Copy code
query scalarQuery (
  $input: String!,
  $otherInput: String!
) {
  arrayOfStrings(input: $input, otherInput: $otherInput)
}
Is type as a
string
in the OAS. So now any non-empty query will pass a contract test, because it will satisfy
string
😱 1
👍 1
h

Harris Lee

05/27/2022, 12:07 AM
hello just follow up question, for provider side, I can still use Pact? if converting grpahql to OpenAPI format hard to do that, I am thinking to stick provider side as Pact CDCT style. so workflow will be
consumer
generate Pact using MSW adator,
provider
write provider side like CDCT and compare consumer generated pact. the reason I want to do that is reusability from unit testing + contract in consumer side. so people easy to use do you think it is good idea or not much getting benefit?
m

Matt (pactflow.io / pact-js / pact-go)

05/27/2022, 12:28 AM
If the consumer side is written in Pact, yes
y

Yousaf Nabi (pactflow.io)

05/27/2022, 12:29 AM
unfortunately you aren’t going to be in for a pleasant time using the msw adapter + CDCT provider verification due to no ability to use provider states or matchers in the request/response interactions.
👍 1
☝️ 1
h

Harris Lee

05/27/2022, 12:30 AM
yeap that was my concern 🙂 thanks
y

Yousaf Nabi (pactflow.io)

05/27/2022, 12:30 AM
if using regular CDCT provider verification, I would advise using
jest-pact
/
mocha-pact
dependant on your framework, or use
pact-js
directly, which is test framework agnostic, and you can use with whichever framework you are using.
m

Matt (pactflow.io / pact-js / pact-go)

05/27/2022, 12:30 AM
👍
h

Harris Lee

05/27/2022, 12:31 AM
does jest-pact support graphql?
I was looking at that but not 100%sure
y

Yousaf Nabi (pactflow.io)

05/27/2022, 12:32 AM
It is just a wrapper around
pact-js
with convenience options for jest. so you should be able to follow this post https://pactflow.io/blog/contract-testing-a-graphql-api/
👍 1
h

Harris Lee

05/27/2022, 12:33 AM
Copy code
provider.addInteraction({
        state: "Server is healthy",
        uponReceiving: 'A request for API health',
        willRespondWith: {
          status: 200,
          body: {
            status: Matchers.like('up'),
          },
        },
        withRequest: {
          method: 'POST',
          path: '/graphql',
        },
      })
and I just add graphql extra info like
withQuery
withVariable
right?
y

Yousaf Nabi (pactflow.io)

05/27/2022, 12:34 AM
I’m about to hit the sack now mate, have a look at the pact-js example and it should be relatively straight-forward, see how you get on and if you get stuck, pop up a repo and ill have a gander tomo
its proper late here haha
h

Harris Lee

05/27/2022, 12:36 AM
🤣 haha yes those example are so useful cheers for good work 🙂