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

Fix RESTDataSource fetching a path with a colon #36

Closed
brandon-leapyear opened this issue Nov 4, 2020 · 2 comments
Closed

Fix RESTDataSource fetching a path with a colon #36

brandon-leapyear opened this issue Nov 4, 2020 · 2 comments

Comments

@brandon-leapyear
Copy link

RESTDataSource.resolveUrl doesn't work correctly for paths with a colon, e.g.

this.get('/foo:')

this throws

TypeError: Only absolute URLs are supported

The source code strips out the leading slash, which leads to the call new URL('foo:', 'http://example.com'), where foo: looks like an absolute URL without a host.

https://github.com/apollographql/apollo-server/blob/cd19cfeff260c4b948fb56f0b3b210a43858cc8c/packages/apollo-datasource-rest/src/RESTDataSource.ts#L74-L88

@brandon-leapyear
Copy link
Author

brandon-leapyear commented Nov 4, 2020

This is an old work account. Please reference @brandonchinn178 for all future communication


Suggested solution: change resolveURL to something like

let prefix = '', baseURL = undefined
if (this.baseURL) {
  const base = new URL(this.baseURL)
  const basePath = base.pathname
  prefix = basePath.endsWith('/') ? basePath : basePath.concat('/')
  baseURL = base.origin
}

return new URL(prefix + path, baseURL)

@glasser glasser transferred this issue from apollographql/apollo-server Oct 11, 2022
@glasser
Copy link
Member

glasser commented Nov 8, 2022

Duplicate of #23. Will pull your suggestion over there.

@glasser glasser closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants