Darryl
06/21/2018, 10:09 AMRecipeCreateinstructionsInput
(mentioned in the first error) is:
input RecipeCreateinstructionsInput {
set: [String!]
}
nilan
06/21/2018, 11:45 AMset
part in your mutation.nilan
06/21/2018, 11:45 AMinstructions: [ 'Step 1', 'Step 2' ],
needs to be instructions: { set: [ 'Step 1', 'Step 2' ] },
Darryl
06/21/2018, 11:50 AM# import Category from './generated/prisma.graphql'
# import Recipe from './generated/prisma.graphql'
# import User from './generated/prisma.graphql'
enum Categories {
BREAKFAST
LUNCH
DINNER
SNACK
}
input RecipeInput {
name: String!
ingredients: [IngredientInput!]!
instructions: [String!]!
categories: [CategoryInput!]!
}
input IngredientInput {
name: String!
quantity: String!
}
input CategoryInput {
name: Categories
}
type Query {
recipes: [Recipe!]!
categories: [Category!]!
user(id: ID!): User
}
type Mutation {
createUser(name: String!, email: String, password: String!): Recipe
createCategory(name: Categories!): Category
deleteCategory(categoryId: ID!): Category
createRecipe(
name: String!
ingredients: [IngredientInput!]!
instructions: [String!]!
categories: [CategoryInput!]!
): Recipe
}
index.js (mutation)
createRecipe: (_, args, context, info) => {
return context.prisma.mutation.createRecipe(
{
data: {
name: args.name,
ingredients: args.ingredients,
instructions: args.instructions,
categories: args.categories
}
},
info
);
}
Darryl
06/21/2018, 11:51 AMnilan
06/21/2018, 11:51 AMDarryl
06/21/2018, 11:51 AMtype User @model {
id: ID! @unique
name: String!
email: String! @unique
password: String
recipes: [Recipe!]!
createdAt: DateTime!
updatedAt: DateTime!
}
type Recipe @model {
id: ID! @unique
name: String! @unique
ingredients: [Ingredient!]!
instructions: [String!]!
categories: [Category!]! @relation(name: "CategoryOnRecipe")
}
type Category @model {
id: ID! @unique
name: Categories! @unique
recipes: [Recipe!]! @relation(name: "CategoryOnRecipe")
}
type Ingredient {
name: String!
quantity: String!
}
enum Categories {
BREAKFAST
LUNCH
DINNER
SNACK
}
Darryl
06/21/2018, 11:51 AMError: Variable "$_v0_data" got invalid value {"name":"New Recipe","ingredients":[{"name":"Ingredient 1","quantity":"1"},{"name":"Ingredient 2","quantity":"2"}],"instructions":["Step 1","Step 2"],"categories":[{"name":"SNACK"},{"name":"DINNER"}]}; Field "0" is not defined by type RecipeCreateinstructionsInput at value.instructions.
Variable "$_v0_data" got invalid value {"name":"New Recipe","ingredients":[{"name":"Ingredient 1","quantity":"1"},{"name":"Ingredient 2","quantity":"2"}],"instructions":["Step 1","Step 2"],"categories":[{"name":"SNACK"},{"name":"DINNER"}]}; Field "1" is not defined by type RecipeCreateinstructionsInput at value.instructions.
Variable "$_v0_data" got invalid value {"name":"New Recipe","ingredients":[{"name":"Ingredient 1","quantity":"1"},{"name":"Ingredient 2","quantity":"2"}],"instructions":["Step 1","Step 2"],"categories":[{"name":"SNACK"},{"name":"DINNER"}]}; Field "0" is not defined by type IngredientCreateManyInput at value.ingredients.
Variable "$_v0_data" got invalid value {"name":"New Recipe","ingredients":[{"name":"Ingredient 1","quantity":"1"},{"name":"Ingredient 2","quantity":"2"}],"instructions":["Step 1","Step 2"],"categories":[{"name":"SNACK"},{"name":"DINNER"}]}; Field "1" is not defined by type IngredientCreateManyInput at value.ingredients.
Variable "$_v0_data" got invalid value {"name":"New Recipe","ingredients":[{"name":"Ingredient 1","quantity":"1"},{"name":"Ingredient 2","quantity":"2"}],"instructions":["Step 1","Step 2"],"categories":[{"name":"SNACK"},{"name":"DINNER"}]}; Field "0" is not defined by type CategoryCreateManyWithoutRecipesInput at value.categories.
Variable "$_v0_data" got invalid value {"name":"New Recipe","ingredients":[{"name":"Ingredient 1","quantity":"1"},{"name":"Ingredient 2","quantity":"2"}],"instructions":["Step 1","Step 2"],"categories":[{"name":"SNACK"},{"name":"DINNER"}]}; Field "1" is not defined by type CategoryCreateManyWithoutRecipesInput at value.categories.
at new CombinedError (/Users/Darryl/Projects/server/node_modules/graphql-tools/dist/stitching/errors.js:83:28)
at Object.checkResultAndHandleErrors (/Users/Darryl/Projects/server/node_modules/graphql-tools/dist/stitching/errors.js:101:15)
at CheckResultAndHandleErrors.transformResult (/Users/Darryl/Projects/server/node_modules/graphql-tools/dist/transforms/CheckResultAndHandleErrors.js:10:25)
at /Users/Darryl/Projects/server/node_modules/graphql-tools/dist/transforms/transforms.js:19:54
at Array.reduce (<anonymous>)
at applyResultTransforms (/Users/Darryl/Projects/server/node_modules/graphql-tools/dist/transforms/transforms.js:18:23)
at /Users/Darryl/Projects/server/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:82:50
at step (/Users/Darryl/Projects/server/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:32:23)
at Object.next (/Users/Darryl/Projects/server/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:13:53)
at fulfilled (/Users/Darryl/Projects/server/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:4:58)
nilan
06/21/2018, 11:52 AMnilan
06/21/2018, 11:52 AMnilan
06/21/2018, 11:52 AM"categories":[{"name":"SNACK"},{"name":"DINNER"}]
you need "categories":[create: {"name":"SNACK"},{"name":"DINNER"}]}
or something like thatDarryl
06/21/2018, 11:53 AMDarryl
06/21/2018, 11:53 AMmutation CreateRecipe {
createRecipe(
name: "New Recipe"
instructions: { set: [ "Step 1", "Step 2" ] }
ingredients: [
{
name: "Ingredient 1"
quantity: "1"
}
{
name: "Ingredient 2"
quantity: "2"
}
]
categories: [
{
name: SNACK
}
{
name: DINNER
}
]
) {
id
name
}
}
Darryl
06/21/2018, 11:53 AMnilan
06/21/2018, 11:53 AMDarryl
06/21/2018, 11:54 AMnilan
06/21/2018, 11:54 AMDarryl
06/21/2018, 11:55 AMnilan
06/21/2018, 11:55 AMnilan
06/21/2018, 11:56 AMnilan
06/21/2018, 11:56 AMset
nilan
06/21/2018, 11:56 AMDarryl
06/21/2018, 11:56 AMDarryl
06/21/2018, 11:56 AMnilan
06/21/2018, 11:58 AMcreateRecipe: (_, args, context, info) => {
return context.prisma.mutation.createRecipe(
{
data: {
name: args.name,
ingredients: args.ingredients,
instructions: args.instructions,
categories: args.categories
}
},
info
);
}
nilan
06/21/2018, 11:58 AMinstructions: set: { args.instructions },
for sure, and I'm not sure about ingredients
and categories
.Darryl
06/21/2018, 11:58 AMDarryl
06/21/2018, 11:58 AMnilan
06/21/2018, 11:59 AMschema.graphql
, now the resolver itself is the missing link which takes care of the mappingnilan
06/21/2018, 12:00 PMgraphql-tools
and I'm not sure if this is already being tracked somewhere. It might be worth to raise this problem here: https://github.com/apollographql/graphql-tools/.Darryl
06/21/2018, 12:00 PMDarryl
06/21/2018, 12:01 PM...
set: { instructions: args.instructions },
...
Darryl
06/21/2018, 12:01 PMnilan
06/21/2018, 12:02 PMnilan
06/21/2018, 12:25 PMDarryl
06/21/2018, 12:30 PMDarryl
06/21/2018, 12:37 PMnilan
06/21/2018, 12:44 PMmutation a {
createRecipe(data: {
name: "Cake"
instructions: {
set: ["Step 1", "Step 2"]
},
ingredients: {
create: [{
name: "Butter"
quantity: "two"
}, {
name: "Sugar"
quantity: "twelve"
}]
}
categories: {
create: [{
name: BREAKFAST
}, {
name: LUNCH
}]
}
}) {
id
}
}
nilan
06/21/2018, 12:44 PMDarryl
06/21/2018, 12:46 PMDarryl
06/21/2018, 12:48 PMDarryl
06/21/2018, 12:51 PMnilan
06/21/2018, 12:51 PMcreateRecipe: (_, args, context, info) => {
return context.prisma.mutation.createRecipe(
{
data: {
name: args.name,
instructions: {
set: args.instructions
},
ingredients: {
create: [...args.ingredients]
},
categories: {
connect: [...args.categories]
}
}
},
info
);
}
nilan
06/21/2018, 12:51 PMDarryl
06/21/2018, 12:57 PMDarryl
06/21/2018, 12:57 PMDarryl
06/21/2018, 12:58 PMnilan
06/21/2018, 12:58 PMnilan
06/21/2018, 12:58 PMgraphql-tools
, it should be much more helpfulDarryl
06/21/2018, 12:58 PMDarryl
06/21/2018, 12:59 PMnilan
06/21/2018, 12:59 PMDarryl
06/21/2018, 1:00 PMDarryl
06/21/2018, 1:00 PMnilan
06/21/2018, 1:00 PM