Is `V3Interaction` compatible with `ApolloGraphqlI...
# pact-js
m
Is
V3Interaction
compatible with
ApolloGraphqlInteraction
? I’m getting type errors:
Copy code
Type 'ApolloGraphQLInteraction' is not assignable to type 'V3Interaction'.
  Types of property 'uponReceiving' are incompatible.
    Type '(description: string) => ApolloGraphQLInteraction' is not assignable to type 'string'.ts(2322)
After fiddling with it a bit more it seem that the main problem is types of query object. I tried to manually convert
ApolloGqlInteraciton
to V3 interface but
query
there is a string while
query
in V3 is a record. Hm…
m
No, we haven't added graphql to the new v3 interface just yet. See the migration notes. Somebody asked about this in the channel yesterday. It should be a simple enough PR to support. Somebody helpfully shared some code on pact.canny.io for it you could pull in and/contribute if you're up for it
m
I think I already made required changes - can PR it later today
Its pretty simple as far as I understand
Copy code
const interaction = new ApolloGraphQLInteraction()
    .uponReceiving(interactionDescription)
    .withRequest({
      path: '/graphql',
      method: 'POST',
      headers: {
        Authorization: `Bearer ${token}`,
        'Content-Type': 'application/json',
      },
    })
    .withOperation(getOperationName(query))
    .withQuery(printQueryToString(query))
    .withVariables(variables)
    .willRespondWith({
      status: 200,
      body: {
        data: respondWith,
      },
    })
    .json();

  return {
    states,
    uponReceiving: interaction.description,
    withRequest: {
      method: interaction.request?.method,
      path: interaction.request?.path,
      query: {}, // this is not used on gql interactions
      body: interaction.request?.body,
      headers: interaction.request?.headers,
    },
    willRespondWith: {
      status: interaction.response?.status,
      body: interaction.response?.body,
      headers: interaction.response?.headers,
    },
  };
kinda took slighly different approach - we have wrapped pack in a think layer ourselves which provides GQL wrapper. So I only need to change wrapper in one place instead of creating full blown separate class. I think.. still testing it
t
Nice work. Probably instead of doing this:
Copy code
method: interaction.request?.method,
You might want to confirm whether the
request
is there and throw an error if it is not - otherwise users might get surprise results if they use the DSL incorrectly.
👍 1