Understanding GraphQL for Beginners–Part Three
GraphQL 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.
Related posts
- Understanding GraphQL for Beginners–Part Two
Shopify Engineering mediumAdeptA 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.
- 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.
- Rewriting the CLI in Rust: Was It Worth It?
Railway mediumAdeptRailway rewrote its Go/Cobra CLI in Rust for v3 because the old codebase had untyped, string-defined GraphQL queries, dynamically registered flags that forced ~120 error guards, and assumptions predating multi-service projects. The Rust version uses clap derive structs with one file per command, a commands_enum! macro to generate the subcommand enum, and schema-validated GraphQL types against the new Public API. User-facing gains include tables, fuzzy-select menus via inquire, a global --json flag and automatic non-interactive mode in CI. The hardest part turned out to be cross-platform release CI and install scripts, and the rewrite broke some users' CI along the way.
- 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.
- 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.