First define an object of type Product with basic fields such as ID, name, price, etc.

We then define a query that takes id and returns exactly the type Product:

To implement this query, I simply generate some random numbers for the price field of the product:

Testing:

Input query structure:

query {
  product(id:"5") {
    id
    name
    price
  }
}
Copy the code

Get the desired output:

For more of Jerry’s original articles, please follow the public account “Wang Zixi “: