Skip to content

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

Open
@jetwiwo

Description

@jetwiwo

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)

Activity

aribouius

aribouius commented on Apr 1, 2022

@aribouius
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

jetwiwo commented on Apr 5, 2022

@jetwiwo
Author

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @aribouius@jetwiwo

      Issue actions

        Client ignores the "fetch" option in config for fetch/mutate/delete · Issue #51 · aribouius/jsonapi-react