Movatterモバイル変換


[0]ホーム

URL:


Unions

Unions are a composition of two or more different types. To create such union type,you need to inherit fromUnionGraphType and call theType<TType> method onthe all types that you want to include in this union.

publicclassCatOrDog:UnionGraphType{publicCatOrDog(){Type<Cat>();Type<Dog>();}}publicclassCat:ObjectGraphType<CatModel>{publicCat(){Field<StringGraphType>("name");Field<BooleanGraphType>("meows");}}publicclassDog:ObjectGraphType<DogModel>{publicDog(){Field<StringGraphType>("name");Field<BooleanGraphType>("barks");}}

In this exampleCatOrDog type should implementResolveType or bothCat andDog types should implementIsTypeOf. Note thatIsTypeOf is already implementedforObjectGraphType<TSourceType> so in this exampleResolveType is not used.For details aboutIsTypeOf andResolveType seeInterfaces.

Edit this page on GitHub

[8]ページ先頭

©2009-2026 Movatter.jp