https://pact.io logo
#pact-js
Title
# pact-js
a

Alan Boshier

03/04/2022, 5:49 PM
Hi - does anyone have a simple example of using
GraphQLInteraction
with PactV3? I'm struggling with how to use it in the following approach as I'm not sure PactV3 has an
addInteraction()
method:
Copy code
const provider = new PactV3(...);

describe('query', () => {
  beforeEach(() => {
    const graphqlQuery = new GraphQLInteraction()
      .uponReceiving('a query')
      .withQuery('...')
      .withVariables({})
      .withRequest({
        path: '/graphql',
        method: 'POST',
      })
      .willRespondWith({
        status: 200,
        headers: { ... },
        body: { ... }
      });

    return provider.addInteraction(graphqlQuery);  <-- IS THIS VALID?
  )};
)};
m

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

03/04/2022, 11:35 PM
V3 doesn't have a graphql API at the moment
a

Alan Boshier

03/05/2022, 12:03 AM
Thanks Matt
m

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

03/05/2022, 1:05 AM
If you take a look at the current graphql interface you could see how it's done. It's a very simple facade
Or a PR into the v3.x.x branch would be great too
a

Alan Boshier

03/05/2022, 7:01 AM
I'll take a look - thanks again.
๐Ÿ‘ 1
@Matt (pactflow.io / pact-js / pact-go) for the PactV3 class, would the correct approach here be to subclass that class with the additional Graphql dsl methods (e.g. withVariables()) - just want to make sure I understand the intention behind the new design.
m

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

03/06/2022, 10:52 AM
I think for now thatโ€™s probably the best idea
๐Ÿ‘ 1