I have a node.js server that uses sequelize and graphql to provide GraphQL endpoint.
Somehow object fields that are linked with belongsTo are always null in GraphQL query output.
Here are my graphql typedefs:
type Student {
id: ID!
name: String!
age: Int!
schoolClass: SchoolClass
}
type SchoolClass {
id: ID!
title: String!
}
Here is how sequelize model defined
const SchoolClass = sequelize.define('SchoolClass', {
title: Sequelize.STRING
});
const Student = sequelize.define('Student', {
name: Sequelize.STRING,
age: Sequelize.TINYINT
});
Student.belongsTo(SchoolClass);
The resolver is
students (root, args, context) {
return models.Student.findAll({}, context);
}
The query:
{
students {
id, name, age, schoolClass { id }
}
}
Typical output:
{
"data": {
"students": [
{
"id": "1",
"name": "John",
"age": "18",
"schoolClass": null
}
]
}
}
Is there any way to get actual data instead of nulls?