Graphql 图形ql+;Sequalize+;现有的数据库-“;“讯息”:&引用;parent.getPages不是一个函数";对于一个模型,而不是另一个
GraphQL查询 早上好 我有一个很好的设置GraphQL->Sequalize->existingdb(由一个Laravel应用程序生成)。我构建了这个模式:Graphql 图形ql+;Sequalize+;现有的数据库-“;“讯息”:&引用;parent.getPages不是一个函数";对于一个模型,而不是另一个,graphql,sequelize.js,graphql-js,express-graphql,Graphql,Sequelize.js,Graphql Js,Express Graphql,GraphQL查询 早上好 我有一个很好的设置GraphQL->Sequalize->existingdb(由一个Laravel应用程序生成)。我构建了这个模式: type App { id: ID! userId: ID user: User pages: [Page] experiments: [Experiment] uri: String! createdAt: String! updatedAt: String!
type App {
id: ID!
userId: ID
user: User
pages: [Page]
experiments: [Experiment]
uri: String!
createdAt: String!
updatedAt: String!
}
type Page {
id: ID!
userId: ID
user: User
appId: ID!
app: App!
uri: String!
createdAt: String!
updatedAt: String!
}
type Experiment {
id: ID!
title: String!
appId: ID!
app: App!
createdAt: String!
updatedAt: String!
}
基于现有数据。查询应用程序实验非常有效:
query {
app(id: 6) {
id
title
experiments {
id
}
}
}
但我得到的是:
query {
app(id: 6) {
id
title
pages {
id
}
}
}
db列与解析程序相同:
/* jshint indent: 2 */
module.exports = function(sequelize, DataTypes) {
const Page = sequelize.define(
"page",
{
id: {
type: DataTypes.INTEGER(10).UNSIGNED,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
...
createdAt: {
type: DataTypes.DATE,
allowNull: true
},
updatedAt: {
type: DataTypes.DATE,
allowNull: true
}
},
{
tableName: "pages",
underscored: true
}
);
Page.associate = models => {
Page.belongsTo(models.app);
};
return Page;
};
您以前遇到过这个问题吗?您能为应用程序和页面提供完整的graphql定义吗。@iAmADeveloper已更新,以包含完整的架构。
{
"errors": [
{
"message": "parent.getPages is not a function",
"locations": [
{
"line": 5,
"column": 5
}
],
"path": [
"app",
"pages"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"TypeError: parent.getPages is not a function",
...
/* jshint indent: 2 */
module.exports = function(sequelize, DataTypes) {
const Page = sequelize.define(
"page",
{
id: {
type: DataTypes.INTEGER(10).UNSIGNED,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
...
createdAt: {
type: DataTypes.DATE,
allowNull: true
},
updatedAt: {
type: DataTypes.DATE,
allowNull: true
}
},
{
tableName: "pages",
underscored: true
}
);
Page.associate = models => {
Page.belongsTo(models.app);
};
return Page;
};
/* jshint indent: 2 */
module.exports = function(sequelize, DataTypes) {
const Experiment = sequelize.define(
"experiment",
{
id: {
type: DataTypes.INTEGER(10).UNSIGNED,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
...
createdAt: {
type: DataTypes.DATE,
allowNull: true
},
updatedAt: {
type: DataTypes.DATE,
allowNull: true
}
},
{
tableName: "experiments",
underscored: true
}
);
Experiment.associate = models => {
Experiment.belongsTo(models.app);
};
return Experiment;
};