graphql
、sequelize
およびを使用していますが、 「IS A」関係graphql-sequelize
を解決するのに問題があります。
私の続編モデルは次のとおりです。
// models.js
// User table
let User = sequelize.define('user', {
id: Sequelize.INTEGER
name: Sequelize.STRING
});
// Patient table
let Patient = sequelize.define('patient', {
bloodType: Sequelize.STRING
});
// Defines "IS A" relationship: [Patient] IS A [User]
Patient.belongsTo(models.User, {
foreignKey: {
name: 'id',
type: DataTypes.INTEGER,
primaryKey: true
},
foreignKeyConstraint: true
})
// Doctor table
let Doctor = sequelize.define('doctor', {
registry: Sequelize.STRING
});
// Defines "IS A" relationship: [Doctor] IS A [User]
Doctor.belongsTo(models.User, {
foreignKey: {
name: 'id',
type: DataTypes.INTEGER,
primaryKey: true
},
foreignKeyConstraint: true
})
そして、これは私のgraphqlスキーマです:
// graphql.js
import resolver from 'graphql-sequelize';
import * as models from './models';
let userType = new GraphQLObjectType({
name: 'User',
fields: {
id: { type: new GraphQLNonNull(GraphQLInt) },
name: { type: GraphQLString }
}
});
let patientType = new GraphQLObjectType({
name: 'Patient',
fields: {
id: { type: new GraphQLNonNull(GraphQLInt) },
bloodType: { type: GraphQLString },
user: {
type: new GraphQLNonNull(userType),
// IMPORTANT!
// How can I call resolver if I don't have a assotiation property like Patient.User?
resolve: resolver()
}
}
});
// [doctorType omitted]
let schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
users: {
type: userType,
resolve: resolver(models.User)
},
patients: {
type: patientType,
resolve: resolver(models.Patient)
}
// [doctor field omitted]
}
})
});
スキーマ ( and )resolver
のフィールドでメソッドを呼び出すと問題なく動作しますが、関連付けプロパティがないため、リゾルバーを呼び出してユーザーを返す方法が問題です。users
patients
patientType
ありがとう。