Skip to content

union does not allow sub-union or covariance #711

Open
@VladimirAlexiev

Description

@VladimirAlexiev

In RDF it's quite common to use subclasses, and somewhat common to use union types (eg schema:rangeIncludes states a field can take values from several different classes; owl:unionOf does a similar thing).

RDF is based on formal logic, so it considers classes (types) as sets. In this interpretation, it's clear how to determine subtypes (especially useful for field covariance). Eg

interface A {}
interface B {}
interface C {}
type A1 implements A {}
type B1 implements B {}
type C1 implements C {}
union U1=A|B|C
union U2=A1|B1|C1   # subtype of U1 because it uses subclasses
union U3=A|B        # subtype of U1 because it uses fewer union members
union U4=A|A1|B|C   # equivalent to U1 because A subsumes A1
union U5=A1|B1      # subtype of U1, U2 and U3

But the spec says:

This means that U1, U3, U4 are not allowed, and neither of them can be used in an object type field.

This creates severe limitations on what polymorphic constructs (in particular RDF constructs) can be mapped to GraphQL.

(I searched here for "union but not 'input union'" and came up only with #518 as a possibly related issue. cc @derek-miller @mavilein)

Metadata

Metadata

Assignees

No one assigned

    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