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

Question: error when implementing new rest datasource #5

Open
mindaugasnakrosis opened this issue Mar 19, 2019 · 2 comments
Open

Question: error when implementing new rest datasource #5

mindaugasnakrosis opened this issue Mar 19, 2019 · 2 comments

Comments

@mindaugasnakrosis
Copy link

mindaugasnakrosis commented Mar 19, 2019

I try implementing rest datasource in color CRUD example instead of memory datasource.

datasources/rest.datasource.js

const config = {
  "name": "rest",
  "connector": "rest",
  "options": {
    "headers": {
      "accept": "application/json",
      "content-type": "application/json"
    },
  },
  "operations": [
    {
      "template": {
        "method": "GET",
        "url": "http://127.0.0.1:8529/api",
        "query": {
          "query": "{query}"
        },
        "responsePath": "$.results[0]"
      }
    }
  ]
};
exports.RestDataSource = datasourceFactory('rest', config);

datasources/index.js
exports.RestDataSource = require('./rest.datasource');

color.repository.js

exports.ColorRepository = repositoryFactory({
  modelName: 'color',
  datasourceName: 'rest',
});

While executing find query I get an error:

Unhandled error in GET /color: 500 TypeError: this.modelClass.find is not a function
    at classes.(anonymous function).find (/home/minnak/Darbas/market/node_modules/@loopback/repository/dist/repositories/legacy-juggler-bridge.js:205:60)
    at classes.(anonymous function).find (/home/minnak/Darbas/market/packages/lb4/realworld/src/lib/crud-controller-factory.js:29:46)
    at value_promise_1.transformValueOrPromise.args (/home/minnak/Darbas/market/node_modules/@loopback/context/dist/resolver.js:181:41)
    at Object.transformValueOrPromise (/home/minnak/Darbas/market/node_modules/@loopback/context/dist/value-promise.js:227:16)
    at Object.invokeMethod (/home/minnak/Darbas/market/node_modules/@loopback/context/dist/resolver.js:176:28)
    at ControllerRoute.invokeHandler (/home/minnak/Darbas/market/node_modules/@loopback/rest/dist/router/controller-route.js:65:32)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)
@mindaugasnakrosis mindaugasnakrosis changed the title Question: Question: error when implementing new rest datasource Mar 19, 2019
@mindaugasnakrosis
Copy link
Author

@hacksparrow any ideas?

@bbl-jcastaneda
Copy link

Got the same issue going on. Any solutions?

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