Skip to content

Support custom scalar types #232

Closed
Closed
@weiznich

Description

@weiznich

I've toyed a bit around to support custom scalar values in juniper.
The following is some sort of brain dump of the current state.

Adding support for new scalar types that are mapping to existing types seems to be quite easily possible, by reusing existing enum variants in Value and InputValue. Using this approach it is for example possible to add support for a 16 bit integer type, because we could simply map that to the existing 32 bit integer. On the other hand adding support for types that are not representable by the existing enum variants is not possible. (An Example here would be adding support for 64 bit integers. They would potentially cause overflows in the 32 bit integer enum variant)

I see several ways to "solve" this: (I've not tried any of this so it may work or it may not work)

  • Add more variants to both enums. So that there is a own variant for each supported type.
    This approach has several downsides:

    • Only a limited set of types could be supported, so if someone want's to introduce a fancy type doing crazy things he will hit the same limit as today
    • We need to teach the parser when to use which integer type (I think this information should already exist somewhere in the schema)
  • Use other types in the existing enum variants
    Again there are downsides:

    • What's the correct type to uses? For integers: should we use i64, but what when someone want's to represent a i128 and so on
    • Again, this is not extensible by some crazy new user defined type
  • Try to make the schema generic about the exact Value/InputValue type, provide a default Value type (maybe the existing one) and allow users to override this type
    Downsides:

    • Again we need to use more knowledge from the schema in the parser
    • I would guess this involves at least rewriting bigger parts of the schema and the parser

I would love to here some other opinions on this before trying further to make this work in a nice way.

(This is basically the only remaining open point for wundergraph)

cc @theduke @LegNeato

Related: #198

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionenhancementImprovement of existing features or bugfix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions