使用graphql

时间:2019-02-11 10:45:13

标签: express-graphql

如何通过带有graphql的节点使用联接怪物count()?

显示错误

这是我的代码

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

  fields: () => ({

viewStatus: {
            type: new GraphQLList(VideoLogs),
            args: {
                movie_id: {
                    type: GraphQLString
                }
            },

            sqlExpr: filmTable => `(SELECT count(id) FROM video_logs WHERE movie_id = ${filmTable}.id)`

        },

查询----------

var studio_id = " ";
const QueryRoot = new GraphQLObjectType({
  name: 'Query',
  fields: () => ({
    getContentDetails: {
      type: new GraphQLList(Films),
      args: {
        id: {
          type: GraphQLInt
        },
        permalink: {
            type: GraphQLString
        },
        studio_id: {
            type: GraphQLString
        },
        content_types_id: {
            type: GraphQLString
        },

      },

      resolve: (parent, args, context, resolveInfo) => {

         var sql = AuthDb.models.oauth_registration.findAll({attributes: ['oauth_token', 'studio_id'],where:{oauth_token:context.headers['authorization']},limit:1}).then(oauth_registration => { 

            for(var i = 0;i<=oauth_registration.length;i++){

                    if(oauth_registration[i].oauth_token == context.headers['authorization']){

                       studio_id = oauth_registration[i].studio_id;
                    return joinMonster.default(resolveInfo,{}, sql => {
                     return FilmDb.query(sql).then(function(result) {  

                            return result[0];
                        });   
                    } ,{dialect: 'mysql'});

                 }else{
                        throw new Error('Give Valid Parameters..');
                    }
                 }

                throw new Error('Give a Valid oauth token');
                })
       return sql;
      },
      where: (filmTable, args, context) => {
      return ` ${filmTable}.permalink = "${args.permalink}" and ${filmTable}.content_types_id = "${args.content_types_id}" and ${filmTable}.studio_id = "${studio_id}"`
        },
    }
  })
})

当我在邮递员中点击url时显示错误

如果一个对象类型映射到一个SQL表,并且其子对象是另一个也映射到SQL表的对象类型,\ n您必须在该字段上定义“ sqlJoin”,“ sqlBatch”或“ junction”以告诉joinMonster如何获取它

0 个答案:

没有答案