Skip to content

Configuration of AnyType #1303

@stalniy

Description

@stalniy

Is your feature request related to a problem? Please describe.
Currently AnyType accepts any JSON value, for some cases I need to restrict AnyType to accept only specific shape of the JSON. For example, GeoJSON specification says that a geo point is a JSON object with 2 properties type and coordinates

This is atomic thing, so I don't want to define it as a separate GraphQL type and instead I see it as a ScalarType (I can't display information on map having only coordinates or only type it just doesn't make sense for me).

Describe the solution you'd like
I see 2 ways to achieve this.

  1. Allow to extend AnyType and restrict it but then it breaks Liskov substitution principle and it's not good
  2. Allow to conifgure AnyType. In this case, it'd be good to have a factory function for AnyType:
class GeoJSONPoint {
   public string Type;
   public double[] Coordinates;
}

AnyType.Create<GeoJSONPoint>()

// or 
AnyType.create(json => isValidGeoJSONPoint(json))

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions