出现以下情况。我无法显示以下数组中的必要值。
{
"data": {
"car": {
"mark": "BMW",
"models": [
{
"model": "315",
"generations": [
{
"generation": "(1934-1937)",
"bodies": [
{
"body": "Родстер"
},
{
"body": "Седан 2 дв."
}
]
}
]
},
{
"model": "321",
"generations": [
{
"generation": "I (1937-1950)",
"bodies": [
{
"body": "Седан 2 дв."
}
]
}
]
},
{
"model": "326",
"generations": [
{
"generation": "I (1936-1946)",
"bodies": [
{
"body": "Седан"
}
]
}
]
}
在graphql中我有以下方案
export default `
type Transmission{
transmission: String!
capacity: [Int!]
}
type Engine{
engine: String!
transmissions: [Transmission]
}
type Body{
body: String!
engines: [Engine]
}
type Generation {
generation: String!
years: [Int!]
bodies: [Body]
}
type Model {
model: String!
generations: [Generation]
}
type Car {
_id: String!
mark: String!
models: [Model]
}
type Query {
car(_id: ID, mark: String): Car!
cars: [Car!]!
}
type Mutation {
createCar(car: CreateCarInput): Car!
updateCar(_id: String!, car: UpdateCarInput!): Car!
deleteCar(_id: String!): Car!
}
input CreateCarInput {
name: String!
email: String!
age: Int!
}
input UpdateCarInput {
name: String
email: String
age: Int
}
`;
graphql中的解析器是我的下一个
import Cars from "../../../models/Cars";
export default {
Query: {
car: async (parent, { _, args, mark }, context, info) => {
return await Cars.findOne({ mark: mark }).exec();
},
cars: async (parent, args, context, info) => {
const cars = await Cars.find({})
.sort({ mark: 1 })
.populate()
.exec();
return cars.map(u => ({
_id: u._id.toString(),
mark: u.mark,
models: u.models
}));
}
},
我想在下一个请求时获取汽车型号
{
car(mark:"BMW"){
mark,
models(model:"Z4")
{
model,
generations
{
generation,
bodies
{
body
}
}
}
}
}
我遇到以下错误
{
"errors": [
{
"message": "Unknown argument \"mark\" on field \"models\" of type \"Car\".",
"locations": [
{
"line": 4,
"column": 10
}
]
}
]
}
我是编程新手。几天来,我一直在为下一个错误而绞尽脑汁。如果有人说我做错了,我将不胜感激。