---
title: "Understanding GraphQL for Beginners–Part Two"
description: "A beginner walkthrough of adding GraphQL to a Ruby on Rails app using a food-and-nutrition example."
url: "https://swe.quest/articles/understanding-graphql-for-beginners-part-two-824dc64184274e82"
canonical: "https://shopify.engineering/understanding-graphql-beginner-part-two"
source: "Shopify Engineering"
published: "2021-07-02"
difficulty: "medium"
kind: "How-to"
reading_minutes: 8
tags: ["graphql","ruby","api-design"]
---

# Understanding GraphQL for Beginners–Part Two

A post on [Shopify Engineering](https://swe.quest/sources/shopify.md), published 2021-07-02, 8 min read, How-to. Original: [https://shopify.engineering/understanding-graphql-beginner-part-two](https://shopify.engineering/understanding-graphql-beginner-part-two)

## Summary

A beginner walkthrough of adding GraphQL to a Ruby on Rails app using a food-and-nutrition example. It covers the app/graphql directory layout (mutations, types, schema), the difference between root fields (entry points like endpoints) and object fields (object attributes), generating a FoodType with \`rails g graphql:object\`, defining root fields in query\_type.rb, and testing queries in GraphiQL. It also adds an association field from food to nutrition and a root field that takes an id argument, and explains that every request goes through the graphql\_controller's execute method and returns JSON.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [GraphQL](https://swe.quest/tags/graphql.md) (Backend & APIs)
- [Ruby](https://swe.quest/tags/ruby.md) (Languages)
- [API design](https://swe.quest/tags/api-design.md) (Backend & APIs)

## Prerequisites

- Ruby on Rails models ([easy posts on Ruby](https://swe.quest/tags/ruby.md?difficulty=easy))
- GraphQL basics ([easy posts on GraphQL](https://swe.quest/tags/graphql.md?difficulty=easy))

## Keywords

GraphQL, Ruby on Rails, GraphiQL, graphql-ruby, ActiveRecord

## Related posts

- [Understanding GraphQL for Beginners–Part Three](https://swe.quest/articles/understanding-graphql-for-beginners-part-three-fa434e0e0fd5a698.md): Shopify Engineering · 2021-08-06 · Medium · 6 min read · GraphQL, Ruby, API design
  GraphQL mutations are the write side of the API, the counterpart to POST, PUT and DELETE in REST.
- [How pg\_graphql works](https://swe.quest/articles/how-pg-graphql-works-70dff1dd9d5a0c27.md): Supabase · 2024-01-24 · Medium · 9 min read · GraphQL, PostgreSQL, Rust, Compilers
  pg\_graphql is a Rust-based Postgres extension that reflects the SQL schema as a GraphQL schema and serves queries through a \`graphql.resolve\` SQL function, with no separate server.
- [What's New in pg\_graphql v1.2](https://swe.quest/articles/what-s-new-in-pg-graphql-v1-2-8e0869fac360da26.md): Supabase · 2023-04-21 · Medium · 4 min read · GraphQL, PostgreSQL, API design
  pg\_graphql v1.1–1.2 now reflects views, materialized views and foreign tables into the GraphQL schema, with primary keys declared via a comment directive.
- [How to Build a GraphQL Server with Deno](https://swe.quest/articles/how-to-build-a-graphql-server-with-deno-b4bf15abf8edf07f.md): Deno · 2023-01-11 · Medium · 7 min read · GraphQL, TypeScript, PostgreSQL, API design
  A GraphQL API server can be built in Deno with the std HTTP Server, the gql middleware, graphql\_tools' makeExecutableSchema and graphql\_tag.
- [pg\_graphql: Postgres functions now supported](https://swe.quest/articles/pg-graphql-postgres-functions-now-supported-279553dc083ab4d8.md): Supabase · 2023-12-12 · Medium · 4 min read · GraphQL, PostgreSQL, API design
  pg\_graphql 1.4+ reflects Postgres user-defined functions into the GraphQL schema, giving custom SQL logic a GraphQL entry point.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
