我正在使用graphql操场在mongodb中插入一个集合。我遇到架构问题(验证错误)。因此,呼叫不会转发到解析器。我已经附上了下面的代码。
TypeDefs
type User{
userName: String!,
password: String!,
confirmPassword: String!,
gender: String,
email:String!,
dob:String,
}
type Token{
token: String!
}
type Collection{
id:String
products:[Product]
}
type Product{
name: String!,
price: Price!,
brand: String!,
shippingCost: String!,
dispatchTime: String!,
childSku:[Skuobj]!
}
type Skuobj{
size: String!,
color:[SkuColors]!
}
type SkuColors{
color: String!
}
type Price{
inr: String,
usd: String
}
input ProductInput{
name: String!,
price: PriceInput!,
brand: String!,
shippingCost: String!,
dispatchTime: String!,
childSku:[SkuobjInput]!
}
input SkuobjInput{
size: String!,
color:[SkuColorsInput]!
}
input SkuColorsInput{
color: String!
}
input PriceInput{
inr: String,
usd: String
}
input CollectionInput{
id:String!,
product: [ProductInput]!
}
type Query{
getCurrentUser: User,
getUser: User!,
getCollection: Collection!
}
类型突变{
addUser(
userName: String!,
password: String!,
gender: String!,
email: String!,
dob: String!): Token
signupUser(
userName: String!,
password: String!,
gender: String!,
email: String!,
dob: String!): Token
signinUser(
email: String!,
password: String!,
): Token
checkValidUserName(
userName: String!
): User
putCollection(input: CollectionInput):Collection!
}
解析器:-
putCollection: async(_,{id,products})=>{
console.log('id',id);
let client = await MongoClient.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true
});
let db = client.db(process.env.DB_NAME);
let res = await db.collection('collection').insertOne({id,products}.collection);
console.log('res',res);
return res;
}
在Graphql游乐场上执行
mutation{
putCollection(id:"Men",product:[
{
name: "STAR WAR's GRAPHIC TEE'S",
price: {
inr: "2500",
usd: "35.37"
},
brand: "Levi's",
shippingCost: "80",
dispatchTime: "5 working days from the date of placing your order",
childSku: [
{
size: "XS",
color: [{color:"White"},{color:"Black"},{color:"red"},{color:"orange"}]
},
{
size: "S",
color: [{color:"White"},{color:"Black"},{color:"red"},{color:"orange"}]
},
{
size: "M",
color: [{color:"White"},{color:"Black"},{color:"red"},{color:"orange"}]
},
{
size: "L",
color: [{color:"White"},{color:"Black"},{color:"red"},{color:"orange"}]
},
{
size: "XL",
color: [{color:"White"},{color:"Black"},{color:"red"},{color:"orange"}]
}
]
}
]
)
响应错误 PFA GQL RESPONSE ERROR