0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

mean.ioのモジュールinnographのバグ?

Posted at

最近MEANスタックの勉強をしているのだが、その中で勉強のベースにしている__mean.io__。
いろいろいじっているうちにこれはバグちゃうか?というのが出てきた。
あまりにも初心者なので、正確なのかわからないが、疑問に思っている個所を上げておく。

ソースコード

問題だと思うのはこの箇所。といってもツールのコアすべてだが。

src/index.js
import express from 'express';
import graphqlHTTP from 'express-graphql';
import schema from './schema';
import defaultCtrl from './controllers';

function init(path, _app, _ctrl) {
  const app = _app || express();
  path = path || '/graphql';
  app.use(path, (req, res) => {
    const ctrl = {
      post: {
        load: (_ctrl && _ctrl.post) ? _ctrl.post.load : defaultCtrl.post.load,
        list: (_ctrl && _ctrl.post) ? _ctrl.post.list : defaultCtrl.post.list,
        create: (_ctrl && _ctrl.post) ? _ctrl.post.create : defaultCtrl.post.create,
        remove: (_ctrl && _ctrl.post) ? _ctrl.post.remove : defaultCtrl.post.remove,
        update: (_ctrl && _ctrl.post) ? _ctrl.post.update : defaultCtrl.post.update
      }
    };
    graphqlHTTP({
      schema,
      graphiql: true,
      context: { ctrl }
    })(req, res);
  });
  if (!_app) app.listen(1111);
}

module.exports = {init};

initメソッド実行時にgraphQLで使用するAPIのpathappctrlを渡し、もし渡されなかったらツールのデフォルトcontrollerを使うように設定されている。

が、mongoDBのスキーマ定義を渡してあげるところがどこにもない。

ここの動作で数時間はまった。
サンプルソースのどこにどんな設定をしてもデフォルトのスキーマ以外のデータは登録できなかった。

ということです。
何か、実はこういう風に使うツールなのだ。ということがわかる方はコメントいただけたら嬉しいです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?