feat: generate mochi resolver boilerplate from .gql operation files#1
Merged
feat: generate mochi resolver boilerplate from .gql operation files#1
Conversation
Reads GraphQL client operation files (.gql), cross-references the SDL
schema, and emits complete mochi field-builder boilerplate — decode
blocks, resolve stubs, encoder stubs, and a register() function.
Developer only fills in the resolve: lambda body.
New config keys:
operations_input: "src/graphql/**/*.gql"
output:
operations: "src/api/schema/"
Also removes the old SDL-based resolve_* stub generation which emitted
non-compiling stubs using undefined ExecutionContext types. Fixes
collect_types_in_def to not include mutation argument types in
cross-file imports (was causing unused-import errors in schema_types.gleam).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Owner
Author
Code reviewFound 3 issues:
mochi_codegen/src/mochi_codegen/operation_gen.gleam Lines 60 to 65 in ca52523
mochi_codegen/src/mochi_codegen/operation_gen.gleam Lines 265 to 295 in ca52523
mochi_codegen/src/mochi_codegen/operation_gen.gleam Lines 23 to 30 in ca52523 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
In generate_decode, the multi-variable branch was calling scalar_to_helper for all variables, causing input object types to be decoded via get_string instead of dict.get + decode.run. Added generate_multi_input_decode_line to handle input types correctly in the multi-var case. Also removes the unused ArgumentDef import from gleam.gleam (was left behind when collect_types_in_def stopped using argument types). Adds operation_gen_test.gleam covering scalar queries, single-input mutations, multi-scalar mutations, and the multi-var+input regression.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
operation_gen.gleam— reads.gqlclient operation files, cross-references the SDL schema, and emits complete mochi field-builder boilerplateoperations_inputandoutput.operationsconfig fields to wire up the new generatorresolve_*stub generation (generate_object_resolvers) which emitted non-compiling stubs using undefinedExecutionContexttypescollect_types_in_defto not include mutation argument types in cross-file imports (was causing unused-import errors inschema_types.gleam)Generated output
Given a
.gqlfile with queries/mutations/subscriptions, codegen produces per.gqlfile:Config
Write policy
Uses
MergeNewFunctions— re-running codegen only appends resolver functions not already present in the file. Existing resolve implementations are never overwritten.Test plan
gleam test— 45 tests pass.gqlfiles and confirm generated files compile🤖 Generated with Claude Code