https://pact.io logo
Join Slack
Powered by
# graphql
  • w

    Wellington Aquino

    02/08/2022, 2:04 PM
    Hi all 🙂 I had an interesting discussion at my company yesterday and wanted to know your point of view. A group of developer argued that Pact contact testing doesn’t provide much value when combined with Typescritp/Graphql because with Graphql we can use the schema to generate the type and use those types on our clients to ensure they are in sync with the API.
    m
    • 2
    • 6
  • t

    Taylor King

    08/17/2022, 10:06 PM
    anyone have any experience utilizing the graphql-codegen library to help generate the contracts Pact can use in a mock server? 🙂 been looking at lots of examples and what not, but haven't found anything around in particular with codegen yet.
    🤔 1
    m
    • 2
    • 4
  • t

    Taylor King

    08/29/2022, 6:05 PM
    Is state handlers something we can't utilize from the GraphQLInteraction? adding
    .given()
    does work, but it also creates two interactions for the same test apparently adding the given() call to my interaction. I don't know if having both uponReceiving and given in one interaction is creating those two tests, but based on the type defs of uponReceiving that wouldn't make sense to me.
    m
    • 2
    • 2
  • m

    Maxim Filimonov

    09/13/2022, 10:11 AM
    Wondering what are strategies people using to test Apollo’s
    useQuery
    hooks with Pact? The only working one I found so far is to write component tests and that does mean that we are tying pact to our UI implementation. Trying to make pact covered layer as close as possible to the direct http calls.
    t
    • 2
    • 3
  • t

    Taylor King

    09/20/2022, 9:17 PM
    Something my mind is still a little fuzzy on is the benefit (specifically in GraphQL world) of verifying the new GraphQLInteraction added with a call to a mocked server and expecting the response to match what we would expect it to be. I think the hurdle my mind is currently trying to jump over is when would that expectation reasonably fail ... it seems like it would be a failure because I wrote the expectation wrong itself but failure wouldn't happen otherwise(?). I think to highlight the general usecase a bit more, here is the last bit of a GraphQLInteraction and what I expect it to respond with:
    Copy code
    new GraphQLInteraction()
    .......
    .willRespondWith({
        status: 200,
        headers: {
            'Content-Type': 'application/json',
        },
        body: {
            data: {
                addTime: {
                    updatedRecord: {
                        id: like('62edadccafea8bf4d0d17bbd'),
                        currentTime: like(40),
                    },
                },
            },
        },
    });
    Calling then a mocked Pact server, I am essentially testing that the response would also equal that response defined in the GraphQLInteraction ... so when would my expectation within the test file itself actually fail other than me intentionally (or unintentionally) not writing correctly the object to match against the response. Seems like even the unintentional failure would be more prohibitive than beneficial. Totally could be misunderstanding the whole point (it's actually highly likely) ... but just wanted further documentation to unfuzzy this concept, and/or community discussion to help bridge this understanding in my head. Seems like, as I'm typing this, this would be more broad than just GraphQL itself and maybe it's a concept higher above I'm just not yet grasping, so would 1,000% love some insight and guidance to this scenario.
    m
    • 2
    • 9
  • j

    Jay Wang

    02/01/2023, 10:58 PM
    Is there documentation available on how to generate a graphql provider contract for bi-directional testing?
  • m

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

    02/02/2023, 1:26 AM
    We don’t support GraphQL for BDCT, unless you can document a GraphQL API as an OAS (which I don’t think you can do?)
  • j

    Jay Wang

    02/03/2023, 5:01 PM
    We were looking at a conversion tool such as this, https://www.npmjs.com/package/graphql-to-openapi, but it would mean another layer for potential failure.
    m
    m
    • 3
    • 3
  • m

    Mankirat Gulati

    05/12/2023, 5:24 PM
    hey, not sure if this has been answered already, but is there update for PactV3 support for graphql?
    m
    l
    • 3
    • 5
  • m

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

    07/12/2023, 12:51 AM
    set the channel description: All things GraphQL Example GraphQL interface in Pact JS: https://gist.github.com/wabrit/2d1e1f9520aa133908f0a3716338e5ff
  • v

    Vijaya Balla (External)

    07/21/2023, 3:11 PM
    hi all đź‘‹, I am looking for some help on using PACT for Apollo federated GraphQL. has anyone done this? Apologies, I can't see the slack history to search before asking. would really appreciate any help on this.
    đź‘‹ 1
  • y

    Yousaf Nabi (pactflow.io)

    07/21/2023, 3:34 PM
    There is some discussion in these feature reqs on our canny board https://pact.canny.io/feature-requests/p/v3-support-for-graphql-interactions And a feature request for a graphql plugin https://pact.canny.io/feature-requests/p/plugin-graphql Just as a tip, you can search via linen.dev which presents https://docs.pact.io/slack/ in a nicer searchable way https://www.linen.dev/s/pact-foundation/t/548324/i-ve-been-using-pact-pact-js-for-graphql-contracts-between-c#777b318a-c21d-4d63-875b-243dc0095ded note to self: maybe add that in to the slack bot, for slack history keyboard
    v
    • 2
    • 1
  • b

    Bas Dijkstra

    08/10/2023, 9:42 AM
    @Bas Dijkstra has left the channel
  • j

    Joel Whalen

    10/06/2023, 5:13 PM
    Hey @Matt (pactflow.io / pact-js / pact-go) long time no see, I’m coming back on my pact journey, this time using mock service worker (MSW). I’m using the msw pact package for javascript, and am running into an issue with setting up graphql handlers. The output of
    server.printHandlers()
    looks like this:
    Copy code
    console.log
        [graphql] query userAndInviteInfo (origin: *)
          Declaration: /Users/joel.whalen/Documents/src/frontend-core/.yarn/__virtual__/@updater-consumer-graph-virtual-1670450a42/1/packages/consumer-graph/dist/cjs/mocks.js:1113:64
    but I’m getting a pact msw error that says it cannot find any graphql handlers:
    Copy code
    ● useIsMoveUPO › returns true if the invite is marked as residentOnboaringEnabled
    
        Found errors on msw requests.
        Requests with missing msw handlers:
         <http://localhost:3000/graphql>
    
          56 | });
          57 | afterEach(() => {
        > 58 |   pactMswAdapter.verifyTest();
             |                  ^
          59 |   server.resetHandlers();
          60 | });
          61 | afterAll(async () => {
    I’m setting up my MSW handlers like this:
    Copy code
    const handlers = [
      mockUserAndInviteInfoQuery((req, res, ctx) => {
        console.log(`Request: ${req}`);
        console.log(ctx.data);
        return res(
          ctx.data({
            getUser: {
              user,
            },
            inviteByToken: {
              invite,
            },
          })
        );
      }),
    ];
    
    const server = setupServer(...handlers);
    so I’m wondering if I’m doing something wrong, since pact msw can’t see it. Thoughts?
    đź‘‹ 1
    y
    m
    • 3
    • 35
  • j

    Joel Whalen

    10/06/2023, 5:35 PM
    Also a more general question about graphql and how it works with pact-msw-adapter: How does the
    providers
    attribute work, since all providers are “hidden” by the
    /graphql
    endpoint?
  • r

    Ruth

    04/30/2024, 8:37 AM
    @Ruth has left the channel
  • h

    Haritima Haritima

    02/18/2025, 11:31 AM
    Hey All, I am new to Pact testing and am trying to write consumer side contract testing on our java SpringBoot application for graphql resquests The problem I am facing is that when I run all the tests it fails on every second test as I use a static port. Since it takes time to shutdown the previous mock connection and start new. Using a dynamic port for each tests work. I am trying to avoid using dynamic port. I have tried
    Executor.closeIdleConnections();
    with @afterEach tests but that doesnt work. Can someone please help with alternative solution to tear down the connection after each tests
    m
    • 2
    • 1