Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client ignores the "fetch" option in config for fetch/mutate/delete #51

Open
jetwiwo opened this issue Feb 16, 2022 · 2 comments · May be fixed by #52
Open

Client ignores the "fetch" option in config for fetch/mutate/delete #51

jetwiwo opened this issue Feb 16, 2022 · 2 comments · May be fixed by #52

Comments

@jetwiwo
Copy link

jetwiwo commented Feb 16, 2022

ApiClient's types indicate that a fetch implementation may be provided in the config argument for delete(), fetch() and mutate(). The ApiClient does not use this implementation. Instead it always uses the fetch which was provided to the constructor.

My use-case is that I'd like to hook "fetch" to intercept request/response data in the manner suggested by #38 (comment)

@aribouius
Copy link
Owner

hi @jetwiwo,

Yeah I'm noticing now that the declared types were implemented incorrectly - the config argument for the client constructor is being portrayed as the same as that for the delete/fetch/mutate methods, as you noted.

That being said, would you mind expanding on how providing a custom implementation to the client constructor does not fit your use case, i.e. what does also supporting it at the method level enable?

@jetwiwo
Copy link
Author

jetwiwo commented Apr 5, 2022

Sure. Firstly, my project is only using the JSON API client part of jsonapi-react, not the caching part. The JSON API implementation my project uses (https://www.graphiti.dev/) supports some extended functionality beyond what JSON API provides as standard. As such I want to be able to modify the request body, while still retaining the ability to parse the response using jsonapi-react.

I've actually achieved this by putting a replaceBody function on the fetchOptions when calling mutate and providing a fetch implementation which uses fetchOptions. This works, but it seems like a fairly convoluted way of doing this.

Considering all of the use cases my project has, the thing which would really make me happy is a library with just your serialiser and deserialiser in it. Yours is the only (de)serialiser project I've found which actually works with deeply nested relationships (good job on that!). We need to be able to deserialise the data in both the browser (a React application) and NodeJS. Having access to your simple and reliable serialiser library would enable us to do this quite easily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants