Skip to content

Support custom C++ types for GraphQL scalars via @cppType directive - #365

Draft
Bill Avery (wravery) with Copilot wants to merge 147 commits into
mainfrom
copilot/next-implement-bigint-scalar
Draft

Bill Avery (wravery) with Copilot wants to merge 147 commits into
mainfrom
copilot/next-implement-bigint-scalar

Conversation

Copilot AI commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Custom scalars (e.g. BigInt) that can't be represented by response::Value were previously unsupported — schemagen always generated resolver and argument accessors typed as response::Value, giving no way to plug in custom storage, serialization, or deserialization.

Schema-level opt-in

  • New schemagen-only directive @cppType(name: String! header: String), applied to a scalar declaration, maps it onto a custom C++ type instead of response::Value:
    scalar BigInt @cppType(name: "bigint::BigInt" header: "BigIntScalar.h")
  • name is used wherever the scalar appears in generated resolver/argument signatures; header is added as an #include in the generated schema header.
  • Scalars without @cppType continue to generate identical code (response::Value), so this is fully backward compatible.

Generator changes

  • SchemaLoader: parses @cppType and 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 a CustomScalarArgument<T> trait — specializing it as std::true_type tells the runtime to treat T as a scalar argument (nullable → std::optional<T>) rather than a generated input object (std::unique_ptr<T>).
  • Users bridge the custom type to/from the wire format by specializing service::Argument<T>::convert, service::Result<T>::convert, and service::Result<T>::validateScalar — the runtime's AwaitableScalar<T>/ModifiedResult<T>/ModifiedArgument<T> were already generic over T, so no changes were needed there.

Example

Added samples/scalar, demonstrating a BigInt scalar backed by std::int64_t (which doesn't fit in the 32-bit response::IntType), serialized on the wire as a JSON string, plus corresponding tests in test/ScalarTests.cpp.

Docs updated in doc/scalars.md and doc/directives.md to describe the new directive and conversion hooks.

Bill Avery (wravery) and others added 30 commits September 10, 2024 13:29
Groundwork in CMake, build workflows, and header include cleanup
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to create BigInt scalar

3 participants