Understanding GraphQL for Beginners–Part Two
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.
Related posts
- Understanding GraphQL for Beginners–Part Three
Shopify Engineering mediumAdeptGraphQL mutations are the write side of the API, the counterpart to POST, PUT and DELETE in REST. They are sent to the same endpoint as queries, take their arguments under input, and run a single resolve method per schema field. Using the graphql-ruby generator (`rails g graphql:mutation`), the tutorial builds foodCreate, foodUpdate and foodDelete mutations for a Rails app. It shows how to declare snake_case input arguments, which are auto-converted to camelCase, use a double splat to pass arguments into resolve, and create, update or destroy ActiveRecord objects, then test each mutation in GraphiQL. Exercises repeat the pattern for a Nutrition model.
- How pg_graphql works
Supabase mediumAdeptpg_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. A request is tokenized and parsed into an AST with the graphql-parser crate, then validated against the GraphQL spec using a reflected schema built from system catalogs. That schema is memoized and reloaded only when the search path, role or schema version changes. Validated queries become builder objects that emit SQL, with quote_ident/quote_literal guarding against injection, and the SQL returns jsonb that is passed back to the client as JSON.
- What's New in pg_graphql v1.2
Supabase mediumAdeptpg_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. Simple views also support inserts and updates, which can keep older API shapes working while the underlying tables are migrated. Filtering gains `is: NULL/NOT_NULL` on every scalar filter plus `like`, `ilike` and `startsWith` on strings; `startsWith` is preferred because it can use plain B-tree indexes. The release also implements the spec's `@skip`/`@include` directives and lets users set table and column descriptions through comment directives, and requires Postgres 15.1.0.63 or later.
- How to Build a GraphQL Server with Deno
Deno mediumAdeptA GraphQL API server can be built in Deno with the std HTTP Server, the gql middleware, graphql_tools' makeExecutableSchema and graphql_tag. The walkthrough starts with a "Hello, World!" query served at /graphql with GraphiQL enabled, then refactors into separate type definition and resolver files. The expanded version adds Postgres-backed queries (allDinosaurs, oneDinosaur) and an addDinosaur mutation using deno-postgres connection pools and tagged-template SQL. It runs with the --allow-net and --allow-env permission flags.
- pg_graphql: Postgres functions now supported
Supabase mediumAdeptpg_graphql 1.4+ reflects Postgres user-defined functions into the GraphQL schema, giving custom SQL logic a GraphQL entry point. Argument nullability follows from defaults, and function volatility decides placement: immutable and stable functions become Query fields, while volatile functions become Mutations. Functions returning setof a table type get Relay-style pagination, filtering, sorting and foreign-key relationships automatically. Overloaded, variadic, void-returning, nameless-argument, array-argument and tuple-argument functions are not yet supported.