我是 GraphQL 的絕對初學(xué)者。如果問題是業(yè)余的,請道歉。我正在編寫這個 graphQL 端點,它將按姓名過濾人員。效果很好,但我希望能夠按姓名、年齡、電話號碼等多個參數(shù)過濾或者使用參數(shù)的組合來搜索..我目前的程序:var express = require("express");var express_graphql = require("express-graphql");var { buildSchema } = require("graphql");var Sequelize = require("sequelize")var db = new Sequelize( "users", "root", "pass", { host: "localhost", dialect: "mysql" });var calls = db.define( "calls", { person_id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true }, name: { type: Sequelize.STRING, allowNull: false }, age: { type: Sequelize.INTEGER, allowNull: false }, address: { type: Sequelize.STRING, allowNull: false }, company: { type: Sequelize.String, allowNull: false }, email: { type: Sequelize.STRING, allowNull: false } }, { tableName: "person" });// Construct a schema, using GraphQL schema languagevar schema = buildSchema(` type Query { Person(person_id: Integer!): [Person] } type Person { person_id: Integer name: String age: Integer address: String company: String email: String }`);var getperson = function(args) { if (args.person_id) { var p_name = args.person_id; return calls.findAll({ where: { name: p_name } }); }};// The root provides a resolver function for each API endpointvar root = { person: getperson};var app = express();app.use( "/graphql", express_graphql({ schema: schema, rootValue: root, graphiql: true }));app.listen(4000);console.log("Running a GraphQL API server at http://localhost:4000/graphql");嘗試這樣做: type Query { Person(person_id: Integer!): [Person] Person(name: String!): [Person] }但它說 Person 只能定義一次。
GraphQL 不允許查詢不同的字段
守候你守候我
2022-05-26 17:37:14