本文整理汇总了Golang中github.com/graphql-go/graphql.NewUnion函数的典型用法代码示例。如果您正苦于以下问题:Golang NewUnion函数的具体用法?Golang NewUnion怎么用?Golang NewUnion使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewUnion函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestTypeSystem_UnionTypesMustBeResolvable_AcceptsAUnionOfObjectTypesDefiningIsTypeOf
func TestTypeSystem_UnionTypesMustBeResolvable_AcceptsAUnionOfObjectTypesDefiningIsTypeOf(t *testing.T) {
_, err := schemaWithFieldType(graphql.NewUnion(graphql.UnionConfig{
Name: "SomeUnion",
Types: []*graphql.Object{objectWithIsTypeOf},
}))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
}
开发者ID:bbuck,项目名称:graphql,代码行数:10,代码来源:validation_test.go
示例2: TestTypeSystem_DefinitionExample_ProhibitsNilTypeInUnions
func TestTypeSystem_DefinitionExample_ProhibitsNilTypeInUnions(t *testing.T) {
ttype := graphql.NewUnion(graphql.UnionConfig{
Name: "BadUnion",
Types: []*graphql.Object{nil},
})
expected := `BadUnion may only contain Object types, it cannot contain: <nil>.`
if ttype.Error().Error() != expected {
t.Fatalf(`expected %v , got: %v`, expected, ttype.Error())
}
}
开发者ID:trythings,项目名称:trythings,代码行数:10,代码来源:definition_test.go
示例3: TestTypeSystem_UnionTypesMustBeArray_RejectsAUnionTypeWithoutTypes
func TestTypeSystem_UnionTypesMustBeArray_RejectsAUnionTypeWithoutTypes(t *testing.T) {
_, err := schemaWithFieldType(graphql.NewUnion(graphql.UnionConfig{
Name: "SomeUnion",
ResolveType: func(value interface{}, info graphql.ResolveInfo) *graphql.Object {
return nil
},
}))
expectedError := "Must provide Array of types for Union SomeUnion."
if err == nil || err.Error() != expectedError {
t.Fatalf("Expected error: %v, got %v", expectedError, err)
}
}
开发者ID:bbuck,项目名称:graphql,代码行数:12,代码来源:validation_test.go
示例4: TestTypeSystem_UnionTypesMustBeResolvable_AcceptsAUnionTypeDefiningResolveType
func TestTypeSystem_UnionTypesMustBeResolvable_AcceptsAUnionTypeDefiningResolveType(t *testing.T) {
_, err := schemaWithFieldType(graphql.NewUnion(graphql.UnionConfig{
Name: "SomeUnion",
Types: []*graphql.Object{someObjectType},
ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object {
return nil
},
}))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
}
开发者ID:trythings,项目名称:trythings,代码行数:13,代码来源:validation_test.go
示例5:
func TestTypeSystem_UnionTypesMustBeResolvable_AcceptsAUnionTypeDefiningResolveTypeOfObjectTypesDefiningIsTypeOf(t *testing.T) {
_, err := schemaWithFieldType(graphql.NewUnion(graphql.UnionConfig{
Name: "SomeUnion",
Types: []*graphql.Object{objectWithIsTypeOf},
ResolveType: func(value interface{}, info graphql.ResolveInfo) *graphql.Object {
return nil
},
}))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
}
开发者ID:bbuck,项目名称:graphql,代码行数:13,代码来源:validation_test.go
示例6: TestTypeSystem_UnionTypesMustBeArray_AcceptsAUnionTypeWithArrayTypes
func TestTypeSystem_UnionTypesMustBeArray_AcceptsAUnionTypeWithArrayTypes(t *testing.T) {
_, err := schemaWithFieldType(graphql.NewUnion(graphql.UnionConfig{
Name: "SomeUnion",
ResolveType: func(value interface{}, info graphql.ResolveInfo) *graphql.Object {
return nil
},
Types: []*graphql.Object{
someObjectType,
},
}))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
}
开发者ID:bbuck,项目名称:graphql,代码行数:14,代码来源:validation_test.go
示例7: schemaWithUnionOfType
func schemaWithUnionOfType(ttype *graphql.Object) (graphql.Schema, error) {
badObjectType := graphql.NewUnion(graphql.UnionConfig{
Name: "BadUnion",
ResolveType: func(value interface{}, info graphql.ResolveInfo) *graphql.Object {
return nil
},
Types: []*graphql.Object{ttype},
})
return graphql.NewSchema(graphql.SchemaConfig{
Query: graphql.NewObject(graphql.ObjectConfig{
Name: "Query",
Fields: graphql.FieldConfigMap{
"f": &graphql.FieldConfig{
Type: badObjectType,
},
},
}),
})
}
开发者ID:bbuck,项目名称:graphql,代码行数:20,代码来源:validation_test.go
示例8: schemaWithUnionOfType
func schemaWithUnionOfType(ttype *graphql.Object) (graphql.Schema, error) {
badObjectType := graphql.NewUnion(graphql.UnionConfig{
Name: "BadUnion",
ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object {
return nil
},
Types: []*graphql.Object{ttype},
})
return graphql.NewSchema(graphql.SchemaConfig{
Query: graphql.NewObject(graphql.ObjectConfig{
Name: "Query",
Fields: graphql.Fields{
"f": &graphql.Field{
Type: badObjectType,
},
},
}),
})
}
开发者ID:trythings,项目名称:trythings,代码行数:20,代码来源:validation_test.go
示例9: TestResolveTypeOnUnionYieldsUsefulError
func TestResolveTypeOnUnionYieldsUsefulError(t *testing.T) {
humanType := graphql.NewObject(graphql.ObjectConfig{
Name: "Human",
Fields: graphql.FieldConfigMap{
"name": &graphql.FieldConfig{
Type: graphql.String,
Resolve: func(p graphql.GQLFRParams) interface{} {
if human, ok := p.Source.(*testHuman); ok {
return human.Name
}
return nil
},
},
},
})
dogType := graphql.NewObject(graphql.ObjectConfig{
Name: "Dog",
IsTypeOf: func(value interface{}, info graphql.ResolveInfo) bool {
_, ok := value.(*testDog)
return ok
},
Fields: graphql.FieldConfigMap{
"name": &graphql.FieldConfig{
Type: graphql.String,
Resolve: func(p graphql.GQLFRParams) interface{} {
if dog, ok := p.Source.(*testDog); ok {
return dog.Name
}
return nil
},
},
"woofs": &graphql.FieldConfig{
Type: graphql.Boolean,
Resolve: func(p graphql.GQLFRParams) interface{} {
if dog, ok := p.Source.(*testDog); ok {
return dog.Woofs
}
return nil
},
},
},
})
catType := graphql.NewObject(graphql.ObjectConfig{
Name: "Cat",
IsTypeOf: func(value interface{}, info graphql.ResolveInfo) bool {
_, ok := value.(*testCat)
return ok
},
Fields: graphql.FieldConfigMap{
"name": &graphql.FieldConfig{
Type: graphql.String,
Resolve: func(p graphql.GQLFRParams) interface{} {
if cat, ok := p.Source.(*testCat); ok {
return cat.Name
}
return nil
},
},
"meows": &graphql.FieldConfig{
Type: graphql.Boolean,
Resolve: func(p graphql.GQLFRParams) interface{} {
if cat, ok := p.Source.(*testCat); ok {
return cat.Meows
}
return nil
},
},
},
})
petType := graphql.NewUnion(graphql.UnionConfig{
Name: "Pet",
Types: []*graphql.Object{
dogType, catType,
},
ResolveType: func(value interface{}, info graphql.ResolveInfo) *graphql.Object {
if _, ok := value.(*testCat); ok {
return catType
}
if _, ok := value.(*testDog); ok {
return dogType
}
if _, ok := value.(*testHuman); ok {
return humanType
}
return nil
},
})
schema, err := graphql.NewSchema(graphql.SchemaConfig{
Query: graphql.NewObject(graphql.ObjectConfig{
Name: "Query",
Fields: graphql.FieldConfigMap{
"pets": &graphql.FieldConfig{
Type: graphql.NewList(petType),
Resolve: func(p graphql.GQLFRParams) interface{} {
return []interface{}{
&testDog{"Odie", true},
&testCat{"Garfield", false},
&testHuman{"Jon"},
}
//.........这里部分代码省略.........
开发者ID:bbuck,项目名称:graphql,代码行数:101,代码来源:abstract_test.go
示例10: init
//.........这里部分代码省略.........
var catType = graphql.NewObject(graphql.ObjectConfig{
Name: "Cat",
IsTypeOf: func(value interface{}, info graphql.ResolveInfo) bool {
return true
},
Fields: graphql.Fields{
"name": &graphql.Field{
Type: graphql.String,
Args: graphql.FieldConfigArgument{
"surname": &graphql.ArgumentConfig{
Type: graphql.Boolean,
},
},
},
"nickname": &graphql.Field{
Type: graphql.String,
},
"meowVolume": &graphql.Field{
Type: graphql.Int,
},
"meows": &graphql.Field{
Type: graphql.Boolean,
},
"furColor": &graphql.Field{
Type: furColorEnum,
},
},
Interfaces: []*graphql.Interface{
beingInterface,
petInterface,
},
})
var catOrDogUnion = graphql.NewUnion(graphql.UnionConfig{
Name: "CatOrDog",
Types: []*graphql.Object{
dogType,
catType,
},
ResolveType: func(value interface{}, info graphql.ResolveInfo) *graphql.Object {
// not used for validation
return nil
},
})
var intelligentInterface = graphql.NewInterface(graphql.InterfaceConfig{
Name: "Intelligent",
Fields: graphql.Fields{
"iq": &graphql.Field{
Type: graphql.Int,
},
},
})
var humanType = graphql.NewObject(graphql.ObjectConfig{
Name: "Human",
IsTypeOf: func(value interface{}, info graphql.ResolveInfo) bool {
return true
},
Interfaces: []*graphql.Interface{
beingInterface,
intelligentInterface,
},
Fields: graphql.Fields{
"name": &graphql.Field{
Type: graphql.String,
Args: graphql.FieldConfigArgument{
开发者ID:cerisier,项目名称:graphql,代码行数:67,代码来源:rules_test_harness.go
示例11: init
},
},
})
var objectType = graphql.NewObject(graphql.ObjectConfig{
Name: "Object",
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
return true
},
})
var interfaceType = graphql.NewInterface(graphql.InterfaceConfig{
Name: "Interface",
})
var unionType = graphql.NewUnion(graphql.UnionConfig{
Name: "Union",
Types: []*graphql.Object{
objectType,
},
})
var enumType = graphql.NewEnum(graphql.EnumConfig{
Name: "Enum",
Values: graphql.EnumValueConfigMap{
"foo": &graphql.EnumValueConfig{},
},
})
var inputObjectType = graphql.NewInputObject(graphql.InputObjectConfig{
Name: "InputObject",
})
func init() {
blogAuthor.AddFieldConfig("recentArticle", &graphql.Field{
Type: blogArticle,
开发者ID:trythings,项目名称:trythings,代码行数:32,代码来源:definition_test.go
示例12:
Type: graphql.Boolean,
},
},
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
_, ok := p.Value.(*testCat2)
return ok
},
})
var petType = graphql.NewUnion(graphql.UnionConfig{
Name: "Pet",
Types: []*graphql.Object{
dogType, catType,
},
ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object {
if _, ok := p.Value.(*testCat2); ok {
return catType
}
if _, ok := p.Value.(*testDog2); ok {
return dogType
}
return nil
},
})
var personType = graphql.NewObject(graphql.ObjectConfig{
Name: "Person",
Interfaces: []*graphql.Interface{
namedType,
},
Fields: graphql.Fields{
"name": &graphql.Field{
Type: graphql.String,
开发者ID:trythings,项目名称:trythings,代码行数:31,代码来源:union_interface_test.go
示例13:
Type: graphql.Boolean,
},
},
IsTypeOf: func(value interface{}, info graphql.ResolveInfo) bool {
_, ok := value.(*testCat2)
return ok
},
})
var petType = graphql.NewUnion(graphql.UnionConfig{
Name: "Pet",
Types: []*graphql.Object{
dogType, catType,
},
ResolveType: func(value interface{}, info graphql.ResolveInfo) *graphql.Object {
if _, ok := value.(*testCat2); ok {
return catType
}
if _, ok := value.(*testDog2); ok {
return dogType
}
return nil
},
})
var personType = graphql.NewObject(graphql.ObjectConfig{
Name: "Person",
Interfaces: []*graphql.Interface{
namedType,
},
Fields: graphql.FieldConfigMap{
"name": &graphql.FieldConfig{
Type: graphql.String,
开发者ID:bbuck,项目名称:graphql,代码行数:31,代码来源:union_interface_test.go
示例14:
var objectWithIsTypeOf = graphql.NewObject(graphql.ObjectConfig{
Name: "ObjectWithIsTypeOf",
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
return true
},
Fields: graphql.Fields{
"f": &graphql.Field{
Type: graphql.String,
},
},
})
var someUnionType = graphql.NewUnion(graphql.UnionConfig{
Name: "SomeUnion",
ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object {
return nil
},
Types: []*graphql.Object{
someObjectType,
},
})
var someInterfaceType = graphql.NewInterface(graphql.InterfaceConfig{
Name: "SomeInterface",
ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object {
return nil
},
Fields: graphql.Fields{
"f": &graphql.Field{
Type: graphql.String,
},
},
})
开发者ID:trythings,项目名称:trythings,代码行数:31,代码来源:validation_test.go
示例15: TestIsTypeOfUsedToResolveRuntimeTypeForUnion
func TestIsTypeOfUsedToResolveRuntimeTypeForUnion(t *testing.T) {
dogType := graphql.NewObject(graphql.ObjectConfig{
Name: "Dog",
IsTypeOf: func(value interface{}, info graphql.ResolveInfo) bool {
_, ok := value.(*testDog)
return ok
},
Fields: graphql.FieldConfigMap{
"name": &graphql.FieldConfig{
Type: graphql.String,
Resolve: func(p graphql.GQLFRParams) interface{} {
if dog, ok := p.Source.(*testDog); ok {
return dog.Name
}
return nil
},
},
"woofs": &graphql.FieldConfig{
Type: graphql.Boolean,
Resolve: func(p graphql.GQLFRParams) interface{} {
if dog, ok := p.Source.(*testDog); ok {
return dog.Woofs
}
return nil
},
},
},
})
catType := graphql.NewObject(graphql.ObjectConfig{
Name: "Cat",
IsTypeOf: func(value interface{}, info graphql.ResolveInfo) bool {
_, ok := value.(*testCat)
return ok
},
Fields: graphql.FieldConfigMap{
"name": &graphql.FieldConfig{
Type: graphql.String,
Resolve: func(p graphql.GQLFRParams) interface{} {
if cat, ok := p.Source.(*testCat); ok {
return cat.Name
}
return nil
},
},
"meows": &graphql.FieldConfig{
Type: graphql.Boolean,
Resolve: func(p graphql.GQLFRParams) interface{} {
if cat, ok := p.Source.(*testCat); ok {
return cat.Meows
}
return nil
},
},
},
})
// ie declare Pet has Dot and Cat object types
petType := graphql.NewUnion(graphql.UnionConfig{
Name: "Pet",
Types: []*graphql.Object{
dogType, catType,
},
ResolveType: func(value interface{}, info graphql.ResolveInfo) *graphql.Object {
if _, ok := value.(*testCat); ok {
return catType
}
if _, ok := value.(*testDog); ok {
return dogType
}
return nil
},
})
schema, err := graphql.NewSchema(graphql.SchemaConfig{
Query: graphql.NewObject(graphql.ObjectConfig{
Name: "Query",
Fields: graphql.FieldConfigMap{
"pets": &graphql.FieldConfig{
Type: graphql.NewList(petType),
Resolve: func(p graphql.GQLFRParams) interface{} {
return []interface{}{
&testDog{"Odie", true},
&testCat{"Garfield", false},
}
},
},
},
}),
})
if err != nil {
t.Fatalf("Error in schema %v", err.Error())
}
query := `{
pets {
name
... on Dog {
woofs
}
... on Cat {
meows
//.........这里部分代码省略.........
开发者ID:bbuck,项目名称:graphql,代码行数:101,代码来源:abstract_test.go
示例16:
},
})
var nonNullStringBox2Object = graphql.NewObject(graphql.ObjectConfig{
Name: "NonNullStringBox2",
Fields: graphql.Fields{
"scalar": &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
},
},
})
var boxUnionObject = graphql.NewUnion(graphql.UnionConfig{
Name: "BoxUnion",
ResolveType: func(value interface{}, info graphql.ResolveInfo) *graphql.Object {
return stringBoxObject
},
Types: []*graphql.Object{
stringBoxObject,
intBoxObject,
nonNullStringBox1Object,
nonNullStringBox2Object,
},
})
var connectionObject = graphql.NewObject(graphql.ObjectConfig{
Name: "Connection",
Fields: graphql.Fields{
"edges": &graphql.Field{
Type: graphql.NewList(graphql.NewObject(graphql.ObjectConfig{
Name: "Edge",
Fields: graphql.Fields{
"node": &graphql.Field{
Type: graphql.NewObject(graphql.ObjectConfig{
开发者ID:cerisier,项目名称:graphql,代码行数:32,代码来源:rules_overlapping_fields_can_be_merged_test.go
注:本文中的github.com/graphql-go/graphql.NewUnion函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论