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

apollo-datasource-rest URL not defined #1508

Closed
seanli3 opened this issue Aug 9, 2018 · 5 comments
Closed

apollo-datasource-rest URL not defined #1508

seanli3 opened this issue Aug 9, 2018 · 5 comments

Comments

@seanli3
Copy link

seanli3 commented Aug 9, 2018

Hi, I'm trying to wrap around existing REST endpoints with datasource-rest 2.0.0-rc.5.

I got he following error

 "ReferenceError: URL is not defined",
node_modules/apollo-datasource-rest/src/RESTDataSource.ts:102:17)

I looked at line 102 of RESTDataSource.ts and it looks like URL has not been imported correctly from apollo-server-env.

And here is my code

class IngestApi extends RESTDataSource {
  constructor() {
    super();
    this.baseURL = 'http://localhost/api';
  }

  async getDogs() {
    return this.get(`dogs`);
  }
}

I'm using babel7 with node 8.9.4

@ghost ghost added the ✋ blocking Prevents production or dev due to perf, bug, build error, etc.. label Aug 9, 2018
@sbrichardson
Copy link
Contributor

sbrichardson commented Aug 9, 2018

Are you importing from apollo-datasource-rest?

const { RESTDataSource } = require("apollo-datasource-rest")

I had just imported and tested the linked example below and it worked in my node environment.

Not sure if an issue, but did you try with a forward slash in front of dogs?

async getDogs() {
  return this.get(`/dogs`);
}

here's a working example

@seanli3
Copy link
Author

seanli3 commented Aug 10, 2018

Hi @sbrichardson thanks for getting back.

I suspect it is Babel that is messing with the imports. I created a repo here to reproduce the issue.
Just run yarn to install dependencies and yarn start. Try to query dogs in the playground and you'll see the issue in the graphql request response.

@sbrichardson
Copy link
Contributor

I fixed it and created a pull request

https://github.com/seanli3/apoll-datasource-rest-bug-report/pull/1

There were a few issues

  1. Libraries were out of date, especially the rest package
  2. Incorrect dataSources usage
  3. Incorrect express usage with apollo-server

@sbrichardson
Copy link
Contributor

This issue can be closed

@seanli3
Copy link
Author

seanli3 commented Aug 13, 2018

Thanks you very much @sbrichardson The PR did fix my issue. I didn't realize 0.1.1 is actually newer than 2.0.0-rc5, it is a bit confusing.

@seanli3 seanli3 closed this as completed Aug 13, 2018
@abernix abernix removed the ✋ blocking Prevents production or dev due to perf, bug, build error, etc.. label Sep 3, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 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

No branches or pull requests

3 participants