如何访问嵌套对象

时间:2019-05-13 11:34:45

标签: javascript graphql

GraphQL嵌套突变

如何访问创建的成分键/值?

这是ingredients查询:

ingredients{
    amount 
    unit 
    food{
      bls 
     name 
    kcal
   }
}
mutation {
  createRecipe(
    data: {
      title: "ABC"
      author: "XYZ"
      level:  EASY
      ingredients: {amount: 250, unit: GRAMM,  food:  {name: "Flour", bls: "xxx", kcal: 203}
       }
    }

解析器

Mutation: {
  createRecipe: (_, args) => {
    const newRecipe = {
      title: args.data.title,
      author: args.data.author,
      level: args.data.level,
      ingredients: args.........??????
    };
}
}

结果

"data": {
    "createRecipe": {
      "title": "ABC",
      "author": "XYZ",
      "level": "EASY",
      "ingredients": null,
    }
  }

如何访问ingredients' amount, unit然后访问ingredients food name,bls,kcal并填充gql操场上的配料数组?

0 个答案:

没有答案
相关问题