Closed wesleycoder closed 6 years ago
Debugging a little bit more:
this.Model.query('find', this.query)
on mongorito/lib/query.js:19
returns action => { … }
instead of a promise.
I've got it to work, but don't know exactly what was the solution.
Here's what I've done:
First I noticed I had followed the example in the readme into using mongorito-timestamps
but it was missing parenthesis (see #202).
Second I've disabled babel caching by setting BABEL_DISABLE_CACHE=1
on my environment and using a task on my package.json
to clear it inside babel module "clear:babel": "rimraf -rf ./node_modules/.cache/babel-loader/*"
.
It seems that using mongorito-timestamps
in the wrong way will not throw any errors or warning and will cause a unexpected behavior on mongorito.
I think the middleware should be validated by mongorito and throw an warning or error if it is not providing the expected behavior.
I've got it working, but I'm unsure what exactly make it happen.
I've disabled babel caching, cleaned node_modules
and reinstalled, also I've fixed mongorito-timestamps
usage, that was:
model.use(timestamps)
and should be:
model.use(timestamps())
One of those things actually made it work, but I'm unsure. I'm closing this as it is not affecting me anymore. I'll be subscribed if anyone has the same issue.
🐛 Trying to call
.find
and nothing worksI'm using
mongorito
withgraphql
and at some point.find
stopped working.You can see my project code here.
package.json:
```json { "name": "tavern-api", "version": "0.0.1", "main": "index.js", "repository": "git@github.com:TavernLab/tavern-api.git", "author": "Wésley Queirozdb/models/Player.js
```js import { Model } from 'mongorito' export class Player extends Model { } export default Player ```db/models/index.js
```js import Board from './Board' import Player from './Player' export * from './Board' export * from './Player' export const models = [ Board, Player ] export default models ```db/index.js
```js import { Database } from 'mongorito' import timestamps from 'mongorito-timestamps' import 'dotenv/config' import models from './models' const { MLAB_USER, MLAB_PASSWORD, MLAB_ENDPOINT } = process.env export const db = new Database(`mongodb://${MLAB_USER}:${MLAB_PASSWORD}@${MLAB_ENDPOINT}`) models.forEach((model) => { model.use(timestamps) db.register(model) }) export const connection = db.connect() export default connection ```Mongorito fails here:
schema/resolver.js
```js import { Board, Player } from '../db/models' import { GraphQLEmail, GraphQLURL, GraphQLDateTime, GraphQLUUID } from 'graphql-custom-types' export const resolvers = { Email: GraphQLEmail, UUID: GraphQLUUID, Url: GraphQLURL, Date: GraphQLDateTime, Query: { players: async () => (await Player.find()).map(p => p.get()), // mongorito fails on .find here boards: async () => (await Board.find()).mp(b => b.get()) }, Mutation: { addPlayer: async (_, {playerData}) => { const player = new Player(playerData) await player.save() return player } } } export default resolvers ```Error stacktrace:
``` TypeError: this.Model.query(...).then is not a function message: "this.Model.query(...).then is not a function" stack: "TypeError: this.Model.query(...).then is not a function at Query.find (/home/dev/tavern-api/node_modules/mongorito/lib/query.js:20:5) at Function.Model.(anonymous function) [as find] (/home/dev/tavern-api/node_modules/mongorito/lib/model.js:217:23) at _callee$ (/home/dev/tavern-api/schema/resolver.js:16:33) at tryCatch (/home/dev/tavern-api/node_modules/regenerator-runtime/runtime.js:65:40) at Generator.invoke [as _invoke] (/home/dev/tavern-api/node_modules/regenerator-runtime/runtime.js:303:22) at Generator.prototype.(anonymous function) [as next] (/home/dev/tavern-api/node_modules/regenerator-runtime/runtime.js:117:21) at step (/home/dev/tavern-api/schema/resolver.js:12:191) at /home/dev/tavern-api/schema/resolver.js:12:437 at new Promise (