jestjs – I am looking to find a way to a test graphql server with graphql-request library

I am using graphql-tag and supertest-graphql to test my apollo-server-express app.

The following is my current approach.

  it('Query a quote', async () => {
    const id = '123456';
    const res = await request(app)
      .query(
        gql`
          query ($id: String!) {
            word(id: $id) {
              id
            }
            words {
              id
            }
          }
        `
      )
      .variables({ id: id });
    console.log(res.data);
    expect((res.data as any).word.id).toBe('123456');
  });

In the client side, I am using graphql-request. This is why I want to use graphql-request’s request instead of supertest-graphql’s request in my unit tests.

However, I cannot find any solution to do this job. Anyone has any idea?

Read more here: Source link