GraphQL以多对多关系显示表中的自定义字段

时间:2019-03-26 18:40:37

标签: graphql sequelize.js apollo-server

我想显示我的自定义字段“位置”与多对多的关系。

  

id | fk_language_id |代码

  

阻止

id |代码

  

Bucket_Block

id | fk_bucket_id | fk_block_id |位置

schema.js

# Bucket
type Bucket {
  id: Int!,
  code: String
  language(id: Int): Language
  blocks: [Block]
}

# Block
type Block {
  id: Int!,
  code: String,
  is_active: Boolean,
  position: Int
}

# query for types
type Query {
  buckets: [Bucket]
}

resolvers.js

Bucket: {
        blocks(bucket) {
            return bucket.getBlocks();
        }
    },

connectors.js

// define bucket
const BucketModel = db.define('bucket', {
    code     : {type: Sequelize.STRING},
    is_active: {type: Sequelize.BOOLEAN}
});

// define block
const BlockModel = db.define('block', {
    code     : {type: Sequelize.STRING},
    is_active: {type: Sequelize.BOOLEAN}
});

// define bucket_block
const BucketBlockModel = db.define('bucket_block', {
    position: {type: Sequelize.INTEGER}
});

BucketModel.belongsToMany(BlockModel, {
    through   : 'bucket_block',
    foreignKey: 'fk_bucket_id'
});

BlockModel.belongsToMany(BucketModel, {
    through   : 'bucket_block',
    foreignKey: 'fk_block_id'
});

我尝试添加数据透视表:架构中的Int,但字段没有

  

“位置”:空

0 个答案:

没有答案