strongloop / loopback4-example-javascript

LoopBack 4 application in JavaScript
3 stars 0 forks source link

Question: error when implementing new rest datasource #5

Open mindaugasnakrosis opened 5 years ago

mindaugasnakrosis commented 5 years ago

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 commented 5 years ago

@hacksparrow any ideas?

bbl-jcastaneda commented 1 year ago

Got the same issue going on. Any solutions?