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

gateway: Support custom fetcher for RemoteGraphQLDataSource. #4149

Merged
merged 6 commits into from
May 27, 2020

Conversation

jhampton
Copy link
Contributor

add: Ability for the RemoteGraphQLDataSource to accept a fetcher implementation, the same as the Gateway (this is part 1 of 2, I think). The second sane step would be to use the Gateway's fetcher when instantiating a RGDS. That said, you can do that like so without that additional change:

const gateway = new ApolloGateway({
  ...
  buildService({ name, url }) {
    return new RemoteGraphQLDataSource({ url, fetcher: myFetcherImplementation });
  },
});

Note: I added a new suite and test for the fetcher for sanity, but I'm seeing snapshot failures unrelated to my work here. Are these test failures expected right now?

@jhampton jhampton requested review from abernix and trevor-scheer May 22, 2020 20:31
@apollo-cla
Copy link

@jhampton: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@abernix abernix added this to the Release 2.14.0 milestone May 26, 2020
@abernix abernix changed the base branch from master to release-2.14.0 May 26, 2020 12:37
@abernix abernix force-pushed the jhampton/rgds-fetcher branch from bd1a54a to 917c2c8 Compare May 26, 2020 12:45
abernix added 5 commits May 27, 2020 11:54
The relation is true right now, but that might change over time and this
test name might end up out of date.
Currently, our test suite isn't as strongly typed as would be ideal.  That
means that even though this is a typing error, it's only at the editor level
and won't affect compilation of the tests or their ability to pass.

The actual typing here seems to be skewed because of problems with our
`FetchMock` type that lives elsewhere in this repo.  That error is causing
a ripple affect of other typing errors in this `RemoteGraphQLDataSource`
test, where there are dozens if not hundreds of similar errors.

We will fix that typing outside of this PR (eventually; I hope soon), but
for now I'm afraid that adding this annotation may inadvertently mask
another error when we resolve the `FetchMock` type.
Due to the heavy-handed `Object.assign`-ing of all properties in the
constructor, no property on this `RemoteGraphQLDataSource` is actually
private since they can be provided and assigned directly over internally to
the class itself.

This is the reality of this pattern, which was - from what I understand -
intended to prevent subclassing, but overlooked the security model provided
by access modifiers and didn't consider the value or need to access a
function's `this` binding.  We need to fix this for other reasons, but for
now, the `private` indicator actually causes typings in other use cases and
creates a false sense of... well, privacy.

This also aligns the behavior with, e.g., the `apq` option, which lives
alongside.
We're already in `RemoteGraphQLDataSource`, and also, comply with the loose
expectation that `it ("reads like a sentence including the 'it' prefix")`.

:shrug:
@abernix abernix changed the title add: Ability for the RemoteGraphQLDataSource to accept a fetcher impl… gateway: Support custom fetcher for RemoteGraphQLDataSource. May 27, 2020
@abernix abernix merged commit 489139c into release-2.14.0 May 27, 2020
@abernix abernix deleted the jhampton/rgds-fetcher branch May 27, 2020 12:35
abernix added a commit to apollographql/federation that referenced this pull request Sep 4, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants