graphql / graphql/graphql-spec

Enum as scalar type

Open
#496 7 comments 6 reactions 0 assignees View on GitHub
💭 Strawman (RFC 0)
Dominant language
JavaScript
Stars
14.6k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

Sometimes, it's useful for declaring an interface that expect to receive an Enum, but you don't want to specify it on interface level, but in the implementation level.

Consider the example:

```graphql
enum TemperatureUnit {
C
F
}

enum WeightUnit {
G
OZ
}

interface MeasurableValue {
value: Float
unit: Enum
}

type WeightValue implements MeasurableValue {
value: Float
unit: WeightUnit
}

type TemperatureValue implements MeasurableValue {
value: Float
unit: TemperatureUnit
}

type TemperatureTask {
type: TaskType!
value: TemperatureValue
}
```

I tried to replicate this example as minimum as possible, if needed I can provide a more complex one.

But in this case, today if we want to achieve a behavior like this, we need to keep unit out of our interface, because we can't specify a generic type and override it in the implementation of the interface.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.