Skip to content

Unable to create BigInt scalar #346

Description

@gitmodimo

Both main and next does not really allow to implement custom scalars that cannot be represented by Value type.
One example would be BigInt scalar. I should be possible to implement custom storage/serialize/deserialize for user defined scalars.

Activity

  1. wravery commented on Mar 8, 2025

    @wravery
    Contributor

    The GraphQL spec was a little vague about custom scalars, IIRC. I think it said something about how they always have to be able to serialize to a string, but things like JSON objects work too for examples like the geo-coordinates.

    In this case, wouldn't the BigInt scalar just need to use a string?

  2. gitmodimo commented on Mar 8, 2025

    @gitmodimo
    Author

    I did't find any info about required serialization to string.
    String is only one example of scalar. I think serializing any custom acalar to string is a walkaround and not real scalar implementation. One could define Positive scalar that would represent nonnegative integer and serializing it as string does not make sense.
    AFAIK JSON specification of integer is not limited to 32bit int. So BigInt should be serialized to JSON as numer not as string. I think scalar token should be of abstract type that allow defining custom serialization/deserialization.

    https://spec.graphql.org/October2021/#sec-Scalars.Custom-Scalars

  3. wravery commented on Mar 10, 2025

    @wravery
    Contributor

    Ah, right. The bit about serialization to strings was specific to ID.

    I think this could be done with a custom token/FieldResult type of std::any, perhaps carrying the scalar typename. Serialization would require plugging in a handler/callback somewhere. In the case of JSON variables, that would probably mean you'd have to parse the scalar type from a JSON fragment as a string.

    Does this match what you're suggesting?

  4. gitmodimo commented on Mar 10, 2025

    @gitmodimo
    Author

    Yes it does

  5. added a commit that references this issue on Sep 15, 2026
    6fb11bb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions