---
title: "Understanding GraphQL for Beginners–Part Two"
description: "The second part of this beginner tutorial uses a food-focused Ruby on Rails application to show how GraphQL fields expose database data. It reviews the graphql directory, where mutations hold data-changing classes, types define returned structures, and food_app_schema.rb defines available queries. It distinguishes root fields, which are GraphQL entry points that define response structure, from object fields, which represent attributes, then demonstrates generating Food and Nutrition types and adding an all_food root field with a non-null list return type. Through GraphiQL at localhost:3000/graphiql, it runs selective queries, adds nutrition to food, and introduces an id argument for retrieving one record; requests pass through graphql_controller’s execute method and return JSON responses."
---

# Understanding GraphQL for Beginners–Part Two

[Shopify](https://yomu.fyi/company/shopify) · 2023-10-18 · Jul 2, 2021

**Type:** Tutorial

## Summary

The second part of this beginner tutorial uses a food-focused Ruby on Rails application to show how GraphQL fields expose database data. It reviews the graphql directory, where mutations hold data-changing classes, types define returned structures, and food\_app\_schema.rb defines available queries. It distinguishes root fields, which are GraphQL entry points that define response structure, from object fields, which represent attributes, then demonstrates generating Food and Nutrition types and adding an all\_food root field with a non-null list return type. Through GraphiQL at localhost:3000/graphiql, it runs selective queries, adds nutrition to food, and introduces an id argument for retrieving one record; requests pass through graphql\_controller’s execute method and return JSON responses.

## Context

The tutorial is the second part of a beginner series and uses a prepared Ruby on Rails repository with Food and Nutrition models, seeded database data, and the GraphQL gems needed to follow along. It focuses on understanding the GraphQL file structure, distinguishing root and object fields, querying food data, and exposing the association between food and nutrition.

## Approach / What changed

It creates GraphQL object types from the existing Rails models, defines root fields in query\_type.rb, and tests them in the GraphiQL playground. The examples add all\_food, nutrition, and an id-based food query, select specific response fields, and add a nullable nutrition field to FoodType so food queries can include serving size and calorie data.

## Takeaways

- Root fields are entry points to a GraphQL server and define response structure, while object fields represent an object's attributes.
- The Food type can expose its associated Nutrition record by adding field :nutrition, Types::NutritionType, null: true.
- GraphiQL documents schema queries and executes requests; graphql\_controller’s execute method processes them and returns a JSON response.

**Tags:** [Architecture](https://yomu.fyi/topic/architecture), [GraphQL](https://yomu.fyi/topic/graphql)

- Source: [Shopify](https://shopify.engineering/understanding-graphql-beginner-part-two)
- Source URL: https://shopify.engineering/understanding-graphql-beginner-part-two
- Ingested by Yomu: 2026-08-30T15:29:57.145Z

[Read original post](https://shopify.engineering/understanding-graphql-beginner-part-two)
