nearform / graphql-hooks

🎣 Minimal hooks-first GraphQL client
Other
1.88k stars 90 forks source link

using LocalGraphQLClient with passing localQueries for test purposes is not calling the middleware functions #1196

Closed amiroous closed 3 months ago

amiroous commented 4 months ago

Package

graphql-hooks

Environment

Description

using LocalGraphQLClient with passing localQueries for test purposes is not calling the middleware functions and causing the middleware not being tested completely

How to reproduce

  1. Create a GraphQL client and pass a middleware dummy function
  2. Use LocalGraphQLClient and define some localQueries to mock
  3. Debug and observe the middleware function is not getting called

Suggested solution (optional)

madshall commented 4 months ago

Another issue is that responseReducer isn't engaged either so the mocks should return the data in the shape the response reducer would have it, which could be used as a workaround if the shape of that data is an object. Otherwise it will be converted to an object. This code does it.

Steps to reproduce:

  1. call useQuery with responseReducer that returns an array
  2. create a mock which returns the same array as we expect after responseReducer is called
  3. receive an object instead

I think it would be less painful and technically more correct if LocalGraphQLClient overrode requestViaHttp and requestViaWS instead of request.