Apollo-link-rest: How to make calls to arbitrary URLs?

Created on 16 Feb 2019  ·  7Comments  ·  Source: apollographql/apollo-link-rest

Hi,

Is there any way to call arbitrary URLs in queries?

The docs say that path in the @rest directive can take a path or a full URL. However, when passing the following query, I get errors:

query getFoo {
  foo @rest(type: "Foo", path: "https://foo.com/foo") {
    bar
  }
}
Deprecated: '@rest(path:' contains a ':' colon, this format will be removed in future versions
index.js:1446 [Network error getIP]: Missing parameters to run query, specify it in the query params or use an export directive. (If you need to use ":" inside a variable string make sure to encode the variables properly using `encodeURIComponent`. Alternatively see documentation about using pathBuilder.)

When I then pass path="${encodeURIComponent('https://foo.com/foo')}", REST link tries to hit https://[my current url]https%3A%2F%2Ffoo.com%2Ffoo.

pathBuilder similarly appends my built path to my original URL.

Is the only option register every URL your app will call in the REST link setup? If so I think the docs should be updated to reflect path not taking full URLs.

bug 🐛 help wanted 🛠

All 7 comments

Thanks for reporting this @timhwang21 This is definitely a bug that was introduced about a year ago.

I guess many people configure their "base endpoints" once for the whole RestLink, so I guess people weren't using this feature very much. -- Suppressing this warning and restoring support for full-urls in the @rest() annotation should be pretty straightforward.

I would support helping review a PR if anyone wants to contribute the fix.

Awesome, I can take a crack over the weekend. @fbartho do you have any pointers as to which part of the codebase I should start looking at first? Thanks.

@timhwang21 Unfortunately, we really only have one source-file in the codebase, it's not incredibly long, but I expect you'd need to change several places throughout the file.

I ran into this and would find value in allowing a full url in the path or another option to define a new url, like url: "https://domain.com/api/path/1".

@timhwang21 were you able to whip something up?

Fwiw here is a little work around I did to get it to work in the meantime.

  1. Specify an empty endpoint in the config. Note there is an actual space in the value empty: ' '.
    image
  2. Use this as the endpoint in your query, here is an example of resolving waterfall requests...
    image

Thats pretty much it.

I have not, we ended up migrating our rest service to GraphQL.

On Mon, Jul 22, 2019 at 9:14 AM Mat Silva notifications@github.com wrote:

I ran into this and would find value in allowing a full url in the path or
another option to define a new url, like url: "
https://domain.com/api/path/1".

@timhwang21 https://github.com/timhwang21 were you able to whip
something up?

Fwiw here is a little work around I did to get it to work in the meantime.

  1. Specify an empty endpoint in the config. Note there is an actual
    space in the value empty: ' '.
    [image: image]
    https://user-images.githubusercontent.com/4511972/61635093-c85eba80-ac60-11e9-87aa-eae6cf788e59.png
  2. Use this as the endpoint in your query, here is an example of
    resolving waterfall requests...
    [image: image]
    https://user-images.githubusercontent.com/4511972/61635160-f0e6b480-ac60-11e9-8879-e78f0ae4d982.png

Thats pretty much it.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/apollographql/apollo-link-rest/issues/192?email_source=notifications&email_token=ABMPWCWNFOUEL4WFA3GSY7TQAWXEZA5CNFSM4GX3BPZ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2P4BCQ#issuecomment-513785994,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABMPWCVPMVEBZQSMS2CGQQLQAWXEZANCNFSM4GX3BPZQ
.

rest service to GraphQL.

yup that'll work too :grin:

Ran into this issue when consuming a mix of Github's API, some of which isn't in their GraphQL API yet. Their Rest API has a lot of absolute URL fields that I'd be able to export and reuse, however the : catch is preventing it from working. The workaround from @matsilva of hacking in an empty endpoint does work for me however.

Was this page helpful?
0 / 5 - 0 ratings