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

PathBuilder args merge of old & new values #102

Closed
samueldepooter opened this issue Apr 25, 2018 · 7 comments
Closed

PathBuilder args merge of old & new values #102

samueldepooter opened this issue Apr 25, 2018 · 7 comments
Labels
bug 🐛 enhancement💡 good first issue Issues that are suitable for first-time contributors.
Milestone

Comments

@samueldepooter
Copy link

Hi,

I was using the apollo-link-rest pathBuilder to map props to the request options. But I noticed that the pathBuilder function receives args

pathBuilder?: (args: object) => string;

that consist of a merge of old and new variables. So if I make an initial request with param1

const options = {
    variables: {
      param1,
      pathBuilder: args => ...,
    },
  };

and later make another request with only param2, the second request will consist of param1 and param2 unless I nullify param1

const options = {
    variables: {
      param2,
      pathBuilder: args => /* args now contains values of both param1 & param2? */,
    },
  };

Current behaviour
PathBuilder args consist of both old & new variable values

Expected behaviour
It would make more sense to me if the pathBuilder would only use the params stated in the variables object.


This has the same behaviour as seen when using fetchMore. For fetchMore it makes sense since your next request is based on the first request, but in this case it's a request that is not tied to the previous one.

It would also be nice to have some updated documentation around this feature since I cannot find it anywhere but in the source code!

@ghost ghost added the good first issue Issues that are suitable for first-time contributors. label Apr 25, 2018
@samueldepooter samueldepooter changed the title PathBuilder args contains merge of old & new values PathBuilder args merge of old & new values Apr 25, 2018
@ghost ghost added the good first issue Issues that are suitable for first-time contributors. label Apr 25, 2018
@fbartho
Copy link
Collaborator

fbartho commented Apr 25, 2018

@samueldepooter That's a good catch! I'd love to have PRs to help fix this. I have no idea where this bug is coming from.

Additionally, you're right, we need to improve the docs. -- If you add to the docs under ./docs/ then we can submit that as a PR to apollo-link!

@fbartho
Copy link
Collaborator

fbartho commented May 7, 2018

I'd like to get this fixed in v0.3.0 @samueldepooter -- do you think you can help make a PR to fix this?

@fbartho fbartho closed this as completed May 7, 2018
@fbartho fbartho added this to the v0.3.0 milestone May 7, 2018
@fbartho fbartho reopened this May 22, 2018
@ghost ghost added the good first issue Issues that are suitable for first-time contributors. label May 22, 2018
@fbartho
Copy link
Collaborator

fbartho commented May 22, 2018

I think I accidentally closed this!

@fbartho
Copy link
Collaborator

fbartho commented May 25, 2018

Heya, I just added a unit test that appears to disprove this case (227538e) , maybe there's something else going on @samueldepooter? Please let me know what you think, and I can reopen the issue.

@tomevans18
Copy link

tomevans18 commented Jul 26, 2018

Hi @fbartho,
Had a look through your test to confirm we are implementing this correctly.
We are experiencing a different result to your test and I think this is due to using fetchMore with updateQuery.

fetchMore({
    variables: {
        offset: data.feed.length,
        pathBuilder: pathBuilderFunction,
    },
    updateQuery: (prev, { fetchMoreResult }) => {
        if (!fetchMoreResult) return prev;
        return Object.assign({}, prev, {
            feed: [...prev.feed, ...fetchMoreResult.feed]
        });
    }
})

On running this we can see the variables are being passed correctly but the pathBuilderFunction has the original variables as the function args.

Any help around this would be much appreciated.

@fbartho
Copy link
Collaborator

fbartho commented Jul 26, 2018

Hey @tomevans18 I have no experience working with fetchMore and updateQuery -- if you can provide unit tests that demonstrate the problem, it would be really helpful!

I'm going on vacation in a week, and in crunch until then, so I wouldn't expect any movement from my side until mid August.

@tomevans18
Copy link

@fbartho thanks for the quick reply.
I will try to write a test case over the weekend to show the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 enhancement💡 good first issue Issues that are suitable for first-time contributors.
Projects
None yet
Development

No branches or pull requests

3 participants