-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Add GraphQL to C++ code generation for ESP32 firmware #647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Implements a lightweight code generator that parses the GraphQL schema and generates C++ header files with ArduinoJson-compatible structs for the ESP32 firmware. Key components: - generate-graphql-types.mjs: Node.js script that parses schema.ts and generates graphql_types.h with structs, operations, and JSON helpers - prebuild.py: PlatformIO pre-build hook that automatically regenerates types when the schema changes (hash-based change detection) - graphql-types library: New PlatformIO library containing generated types Generated types include: - LedCommand, LedCommandInput (with uint8_t for RGB values) - LedUpdate, ControllerPing, ClimbMatchResult - DeviceLogEntry, SendDeviceLogsResponse - GraphQL operation string constants - JSON parsing/serialization helper functions This provides type safety between the GraphQL backend and ESP32 firmware without heavy dependencies like cppgraphqlgen. https://claude.ai/code/session_01CkAwoY8k1wbNeCMJ14Xfzv
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Claude Review✅ Ready to merge - Minor issues noted below, but nothing blocking. Issues
|
Adds comprehensive test suites for the code generation system: Node.js tests (21 tests): - Schema parsing for types, inputs, unions, arrays - GraphQL to C++ type mapping - C++ struct generation with field overrides - Integration tests with real schema files - Edge cases (empty schema, missing types) Python tests (9 tests): - Hash calculation for file change detection - Combined hash for multiple files - Hash storage and retrieval - Integration with real schema files Run all tests with: npm run controller:codegen:test https://claude.ai/code/session_01CkAwoY8k1wbNeCMJ14Xfzv
Claude Review✅ Ready to merge - Minor issues noted below, but nothing blocking. Issues
|
Fixes several issues identified in code review: 1. Memory leak prevention: Added freeLedUpdate() helper function to properly deallocate the commands array allocated by parseLedUpdate() 2. Dangling pointer documentation: Added clear documentation about string pointer lifetime - const char* fields point into JsonDocument memory and become invalid when the document is destroyed 3. Removed timestamp from generated header to avoid noisy diffs on every regeneration - the file can now be committed without changes unless the schema actually changed 4. Fixed sentinel value comparison: Added ROLE_NOT_SET constant (-1) and updated serializeLedCommandInput() to use explicit sentinel comparison instead of >= 0 5. Removed leftover console.log from test file 6. Added new tests verifying: - freeLedUpdate helper is generated - ROLE_NOT_SET constant and usage - Pointer lifetime documentation - No timestamp in generated output https://claude.ai/code/session_01CkAwoY8k1wbNeCMJ14Xfzv
Addresses additional review feedback:
1. Fix native test build failure:
- Added LEDCOMMAND_DEFINED include guard to both led_controller.h
and generated graphql_types.h
- This allows native tests to work without Arduino.h dependency
- led_controller.h defines LedCommand for native tests
- graphql_types.h skips definition if already defined
2. Handle memory allocation failure:
- Changed new[] to new (std::nothrow) in parseLedUpdate()
- Returns false if allocation fails instead of crashing
- Added #include <new> for std::nothrow
3. Document nullable angle behavior:
- Added note that angle defaults to 0 if not present
- Since 0 is valid, callers must use containsKey() if they
need to distinguish "no angle" from "angle=0"
4. Added tests verifying:
- LEDCOMMAND_DEFINED include guard is generated
- std::nothrow is used for allocation
- Allocation failure handling
- Angle nullable documentation
https://claude.ai/code/session_01CkAwoY8k1wbNeCMJ14Xfzv
Claude Review✅ Ready to merge - Minor issues noted below, but nothing blocking. Issues
Notes
|
1. Switch from MD5 to SHA256 for hash-based change detection
- More consistent with modern practices
- Updated both prebuild.py and test_prebuild.py
- Updated test assertions for 64-char SHA256 hex length
2. Add generated files to .gitignore
- graphql_types.h is now generated during build only
- .schema_hash cache file also ignored
- Prevents merge conflicts when multiple PRs modify schema
3. Document angle nullable ambiguity in GraphQL schema
- Added doc comment to LedUpdate.angle explaining that
null means "no angle" vs 0 being a valid angle value
- Source documentation prevents ambiguity at the source
https://claude.ai/code/session_01CkAwoY8k1wbNeCMJ14Xfzv
Claude Review✅ Ready to merge - Well-structured code generation implementation with comprehensive tests. Minor issues noted below. Issues
|
- Check return value of parseLedCommand in generated parseLedUpdate loop - Free allocated memory and return false if command parsing fails - Simplify hash computation to hash file contents directly in one pass - Remove obsolete get_file_hash tests from test_prebuild.py https://claude.ai/code/session_01CkAwoY8k1wbNeCMJ14Xfzv
Claude Review✅ Ready to merge - Minor issues noted below, but nothing blocking. Issues
Test CoverageTests are comprehensive and cover schema parsing, type mapping, struct generation, and edge cases. The integration tests verify the generated output file structure and content. |
- Add ANGLE_NOT_SET sentinel (-32768) for nullable angle field - Prevent duplicate codegen runs during single build with flag - Add newline at end of prebuild.py - Document regex limitation for nested braces - Update test for new angle sentinel behavior https://claude.ai/code/session_01CkAwoY8k1wbNeCMJ14Xfzv
Claude Review✅ Ready to merge - Minor issues noted below, but nothing blocking. Issues
|
Implements a lightweight code generator that parses the GraphQL schema and
generates C++ header files with ArduinoJson-compatible structs for the
ESP32 firmware.
Key components:
generates graphql_types.h with structs, operations, and JSON helpers
types when the schema changes (hash-based change detection)
Generated types include:
This provides type safety between the GraphQL backend and ESP32 firmware
without heavy dependencies like cppgraphqlgen.
https://claude.ai/code/session_01CkAwoY8k1wbNeCMJ14Xfzv