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

How to make calls to arbitrary URLs? #192

Closed
timhwang21 opened this issue Feb 16, 2019 · 8 comments
Closed

How to make calls to arbitrary URLs? #192

timhwang21 opened this issue Feb 16, 2019 · 8 comments
Labels
bug 🐛 enhancement💡 good first issue Issues that are suitable for first-time contributors. help wanted 🛠

Comments

@timhwang21
Copy link

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.

@fbartho
Copy link
Collaborator

fbartho commented Feb 20, 2019

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.

@timhwang21
Copy link
Author

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.

@fbartho
Copy link
Collaborator

fbartho commented Jun 14, 2019

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

@matsilva
Copy link

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.

@timhwang21
Copy link
Author

timhwang21 commented Jul 22, 2019 via email

@matsilva
Copy link

rest service to GraphQL.

yup that'll work too 😁

@basicdays
Copy link

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.

@fbartho
Copy link
Collaborator

fbartho commented Jan 5, 2022

If somebody wants to implement this, I'm still happy to review the PR w/ Tests & Documentation!

@fbartho fbartho closed this as completed Jan 5, 2022
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. help wanted 🛠
Projects
None yet
Development

No branches or pull requests

4 participants