GraphQL + Sequalize +现有数据库-一个模型的“ message”:“ parent.getPages不是函数”而不是另一个模型

时间:2019-10-10 04:51:09

标签: graphql sequelize.js graphql-js express-graphql

GraphQL查询

早上好

我有一个不错的设置GraphQL-> Sequalize->现有数据库(由Laravel应用程序生成)。我已经建立了这个模式:


  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
    }
  }
}
{
  "data": {
    "app": {
      "id": "6",
      "title": "C-Map Embark: Boating",
      "experiments": [
        {
          "id": "1"
        }
      ]
    }
  }
}

但是查询页面我得到这个:

query {
  app(id: 6) {
    id
    title
    pages {
      id
    }
  }
}
{
  "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;
};

您以前遇到过这个吗?

0 个答案:

没有答案