graphql-editor / graphql-zeus

GraphQL client and GraphQL code generator with GraphQL autocomplete library generation ⚡⚡⚡ for browser,nodejs and react native ( apollo compatible )
https://graphqleditor.com/docs/tools/zeus/index/
MIT License
1.93k stars 103 forks source link

Using a Chain client within Jest #247

Open seanonthenet opened 2 years ago

seanonthenet commented 2 years ago

Is there a way to get a Chain client working within a Jest test? The error I get is: ReferenceError: fetch is not defined so I try to fix it with jest-fetch-mock and replaced in jestSetup.js as: require('jest-fetch-mock').enableMocks(); the error becomes:

FetchError {
  message: 'invalid json response body at  reason: Unexpected end of JSON input',
  type: 'invalid-json'
}

The client is defined as:

export const chainClient = Chain(getHasuraURL() + '/v1/graphql', {
  credentials: 'include',
});

Test query I'm trying:

const result = await chainClient('query')({
  testTable: [{}, { __typename: true, id: true, name: true }],
});

Any help is appreciated. Thanks. (Love Zeus ✊ ⚡️)

aexol commented 2 years ago

I will try to test in the new 5.0. As you can see all the generated functions are now legit .ts files being generated by produce-lib script back to string