Support custom C++ types for GraphQL scalars via @cppType directive - #365
Draft
Bill Avery (wravery) with Copilot wants to merge 147 commits into
Draft
Bill Avery (wravery) with Copilot wants to merge 147 commits into
Bill Avery (wravery) with Copilot wants to merge 147 commits into
Conversation
Groundwork in CMake, build workflows, and header include cleanup
Add enum value validation
chore: regenerate samples with enum validation
Co-authored-by: wravery <6502881+wravery@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add custom BigInt scalar implementation
Support custom C++ types for GraphQL scalars via @cppType directive
Sep 15, 2026
…ve approach with a pure runtime extension (see follow-up commit)
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.
Custom scalars (e.g.
BigInt) that can't be represented byresponse::Valuewere previously unsupported — schemagen always generated resolver and argument accessors typed asresponse::Value, giving no way to plug in custom storage, serialization, or deserialization.Schema-level opt-in
@cppType(name: String! header: String), applied to ascalardeclaration, maps it onto a custom C++ type instead ofresponse::Value:nameis used wherever the scalar appears in generated resolver/argument signatures;headeris added as an#includein the generated schema header.@cppTypecontinue to generate identical code (response::Value), so this is fully backward compatible.Generator changes
SchemaLoader: parses@cppTypeand resolves the associated C++ type/header for a given scalar.SchemaGenerator: emits the custom-scalar header include and substitutes the custom type into argument/result accessor signatures.Runtime changes
GraphQLService.h: added aCustomScalarArgument<T>trait — specializing it asstd::true_typetells the runtime to treatTas a scalar argument (nullable →std::optional<T>) rather than a generated input object (std::unique_ptr<T>).service::Argument<T>::convert,service::Result<T>::convert, andservice::Result<T>::validateScalar— the runtime'sAwaitableScalar<T>/ModifiedResult<T>/ModifiedArgument<T>were already generic overT, so no changes were needed there.Example
Added
samples/scalar, demonstrating aBigIntscalar backed bystd::int64_t(which doesn't fit in the 32-bitresponse::IntType), serialized on the wire as a JSON string, plus corresponding tests intest/ScalarTests.cpp.Docs updated in
doc/scalars.mdanddoc/directives.mdto describe the new directive and conversion hooks.