urql-graphql / urql

The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
https://urql.dev/goto/docs
MIT License
8.54k stars 444 forks source link

update docs on composeExchanges #3589

Closed aamir-mns closed 1 month ago

aamir-mns commented 1 month ago

The code and code-docs says its right to left (and tested it locally, it is right left) but the official docs says its left to right

Helpful links:

Summary

I was using composeExchanges. Read official docs but it works in the opposite direction.

Set of changes

Update docs

changeset-bot[bot] commented 1 month ago

⚠️ No Changeset found

Latest commit: 97bc1e2d03e69f8bad37c6461c5e58be9a431965

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

kitten commented 1 month ago

Both are correct, actually. Sorry about the confusion! Let me explain.

The TSDocs state:

[...] calling them from right to left, with the prior Exchange’s ExchangeIO function as the ExchangeInput.forward input.

The docs site states:

It chains them in the order that they're given, left to right.

Both are correct. The exchanges themselves are chained from left to right, meaning, the operations run through from left to right, just like the exchanges array on the Client are given (i.e. natural order, basically)

However, the TSDocs explain the code and what's going on there. What's going on in the code is that the exchanges are called from right to left, which composes them to be chained in the natural order, as given. This is further complicated by the operation results running in reverse order basically, so I know it's confusing, but the docs must state left-to-right to clarify that that's the expected order

aamir-mns commented 1 month ago

@kitten thanks for the quick reply. I got your point. I will close this PR but I think the docs not be a bit more clear as you said :) thanks

aamir-mns commented 1 month ago

@kitten Actually, I'm still confused. The docs say, 'It chains them in the order that they're given, left to right.' What does that mean? One would assume that it executes in the order they are provided, i.e., the first item will execute first and so on. By reading this, one can never assume that they will execute from right to left, i.e., the last will execute first and then it travels towards the left

JoviDeCroock commented 1 month ago

It means that the requests that come in will be executed in the order of the exchanges left-to-right, and then return as a result from right-to-left

princekumar-d commented 1 month ago

If I understand this correctly, is it something similar to this diagram?

image

If this is the case then maybe the docs could be updated to make it a bit more obvious?

kitten commented 1 month ago

That's a great suggestion :+1: Originally, this diagram served to explain this, but it isn't quite up-to-date and good enough anymore: https://urql.dev/goto/docs/architecture/#the-client-and-exchanges

Generally, we'll need to work on some documentation changes to get things back into shape