Здесь я создал несколько типов объектов для тестирования (например, рецепт и контакт).
Я пытаюсь вставить контактную информацию в тип рецепта.
он мне даетошибка как
"Ошибка проверки рецепта: recipeContacts: преобразование в массив не выполнено для значения \" [{contactFname: 'Richa', \ n contactLname: 'Sharma', \ n
contactCompanyName: 'XYZ '}] \ "at path \" recipeContacts \ ""
Я новичок в Graphql, было бы полезно, если бы вы могли подробно описать точную ошибку.
Спасибозаранее.
**//Schema File**
exports.typeDefs = `
input ContactDemoInput
{
id:String
contactFname: String!
contactLname: String!
contactCompanyName: String
contactNotes: String
contactBirthday: String
contactCreatedDate:String
username: String
},
type Contact {
id:String
contactFname: String!
contactLname: String!
contactCompanyName: String
contactNotes: String
contactBirthday: String
contactCreatedDate:String
username: String
},
input RecipeDemoInput {
id:String
name: String!
category: String!
description: String!
instructions: String!
createdDate:String
likes: Int
recipeContacts: [ContactDemoInput]
},
type Recipe {
id:String
name: String!
category: String!
description: String!
instructions: String!
createdDate:String
likes: Int
recipeContacts: [Contact]
},
**//mutation to add recipe**
type Mutation {
addRecipe(name: String!, description: String!, category: String!, instructions: String!, username: String ,recipeContacts:[ContactDemoInput]): Recipe
}
**// Graphql query file**
export const ADD_RECIPE = gql`
mutation(
$name: String!
$category: String!
$description: String!
$instructions: String!
$username: String
$recipeContacts: [ContactDemoInput]
) {
addRecipe(
name: $name
category: $category
description: $description
instructions: $instructions
username: $username
recipeContacts: $recipeContacts
) {
name
recipeContacts {
contactFname
contactLname
}
}
}
`;
**// passing values**
mutation(
$name: String!
$category: String!
$description: String!
$instructions: String!
$username: String
$recipeContacts: [ContactDemoInput]
) {
addRecipe(
name: $name
category: $category
description: $description
instructions: $instructions
username: $username
recipeContacts: $recipeContacts
) {
name
category
cont{
contactFname
contactLname
}
}
}
{
"name": "Sandwitch",
"category": "snacks",
"description": "test",
"instructions": "test",
"recipeContacts":[ {
"contactFname": "richa",
"contactLname": "sharma",
"contactCompanyName": "XYZ"
}]
}
// Recipe Model
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const { Contactschema } = require("./Contact");
// Recipe Model
const RecipeSchema = new Schema({
name: {
type: String,
required: true
},
category: {
type: String,
required: true
},
description: {
type: String,
required: true
},
instructions: {
type: String,
required: true
},
createdDate: {
type: Date,
default: Date.now
},
likes: {
type: Number,
default: 0
},
recipeContacts: {
type: [Schema.Types.ObjectId],
ref: "Contact"
}
});
module.exports = mongoose.model("Recipe", RecipeSchema);