Objects inside objects

Asked by At

GraphQL schema

Object inside an object

Here's the Schema:

ingredients {
  id
  amount
  unit
  food {
    name
  }
}

My input and what is working so far

ingredients: [{
  id: 2,
  amount: "1",
  unit: "BUND"
}]

How do I assign food the name of e.g Noodles?

1 Answers

0
Adriano On Best Solutions

So, your ingredients is a [] list of {} objects.

Each of the objects contained in ingredients contains a set of key/value pairs; e.g.: id: 2, amount: "1".

One of these keys has as its value an {} object again.

You can assign the key food the object with its key/value pairs as {name: "Noodles"} as following:

ingredients: [{
  id: 2,
  amount: "1",
  unit: "BUND",
  food: {
    name: "Noodles"
  }
}]

Let me know how it goes :)