使用联接怪物

时间:2019-01-23 10:51:14

标签: express-graphql

这是我的模式

const graphql = require('graphql');
const joinMonster = require('join-monster');
const FilmDb  = require('../model/Films');
const { GraphQLObjectType, GraphQLList, GraphQLString, GraphQLInt,GraphQLSchema } = graphql;

const Films = new GraphQLObjectType({
  name: 'films',

  fields: () => ({
    id: {
        type: GraphQLInt,

      },

      name: {
          type: GraphQLString,

      },
  })
})
Films._typeConfig = {
    sqlTable: 'films',
    uniqueKey: 'id'
  }

const QueryRoot = new GraphQLObjectType({
  name: 'Query',
  fields: () => ({
    films: {
      type: new GraphQLList(Films),
      resolve: (parent, args, context, resolveInfo) => {
        return joinMonster.default(resolveInfo, {}, sql => {

            return FilmDb.query(sql).then(function(result) {

                return result;
              });

        })
      }
    }
  })
})

module.exports = new GraphQLSchema({
    query: QueryRoot
})

当我点击以下查询

{       电影{         ID       }     }

它显示了一个错误

{
  "errors": [
    {
      "message": "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.\"id\" AS \"id\"\nFROM films \"films\"' at line 1",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "films"
      ]
    }
  ],
  "data": {
    "films": null
  }
}

我的SQL查询终端中生成的是

选择   “电影”。“ id” AS“ id” 从电影“电影”

我在这里使用nodejs,在数据库中使用Sequelize
这是什么错误?我找不到确切的错误。

0 个答案:

没有答案