本文整理汇总了Golang中github.com/chris-ramon/graphql.NewList函数的典型用法代码示例。如果您正苦于以下问题:Golang NewList函数的具体用法?Golang NewList怎么用?Golang NewList使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewList函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestTypeSystem_DefinitionExample_StringifiesSimpleTypes
func TestTypeSystem_DefinitionExample_StringifiesSimpleTypes(t *testing.T) {
type Test struct {
ttype graphql.Type
expected string
}
tests := []Test{
Test{graphql.Int, "Int"},
Test{blogArticle, "Article"},
Test{interfaceType, "Interface"},
Test{unionType, "Union"},
Test{enumType, "Enum"},
Test{inputObjectType, "InputObject"},
Test{graphql.NewNonNull(graphql.Int), "Int!"},
Test{graphql.NewList(graphql.Int), "[Int]"},
Test{graphql.NewNonNull(graphql.NewList(graphql.Int)), "[Int]!"},
Test{graphql.NewList(graphql.NewNonNull(graphql.Int)), "[Int!]"},
Test{graphql.NewList(graphql.NewList(graphql.Int)), "[[Int]]"},
}
for _, test := range tests {
ttypeStr := fmt.Sprintf("%v", test.ttype)
if ttypeStr != test.expected {
t.Fatalf(`expected %v , got: %v`, test.expected, ttypeStr)
}
}
}
开发者ID:Fugiman,项目名称:graphql,代码行数:26,代码来源:definition_test.go
示例2:
func TestTypeSystem_ObjectsMustAdhereToInterfaceTheyImplement_AcceptsAnObjectWithAnEquivalentlyModifiedInterfaceField(t *testing.T) {
anotherInterface := graphql.NewInterface(graphql.InterfaceConfig{
Name: "AnotherInterface",
ResolveType: func(value interface{}, info graphql.ResolveInfo) *graphql.Object {
return nil
},
Fields: graphql.FieldConfigMap{
"field": &graphql.FieldConfig{
Type: graphql.NewNonNull(graphql.NewList(graphql.String)),
},
},
})
anotherObject := graphql.NewObject(graphql.ObjectConfig{
Name: "AnotherObject",
Interfaces: []*graphql.Interface{anotherInterface},
Fields: graphql.FieldConfigMap{
"field": &graphql.FieldConfig{
Type: graphql.NewNonNull(graphql.NewList(graphql.String)),
},
},
})
_, err := schemaWithObjectFieldOfType(anotherObject)
if err != nil {
t.Fatalf(`unexpected error: %v for type "%v"`, err, anotherObject)
}
}
开发者ID:Fugiman,项目名称:graphql,代码行数:26,代码来源:validation_test.go
示例3: withModifiers
func withModifiers(ttypes []graphql.Type) []graphql.Type {
res := ttypes
for _, ttype := range ttypes {
res = append(res, graphql.NewList(ttype))
}
for _, ttype := range ttypes {
res = append(res, graphql.NewNonNull(ttype))
}
for _, ttype := range ttypes {
res = append(res, graphql.NewNonNull(graphql.NewList(ttype)))
}
return res
}
开发者ID:Fugiman,项目名称:graphql,代码行数:13,代码来源:validation_test.go
示例4: TestLists_NullableListOfNonNullObjects_ContainsNull
func TestLists_NullableListOfNonNullObjects_ContainsNull(t *testing.T) {
ttype := graphql.NewList(graphql.NewNonNull(graphql.Int))
data := []interface{}{
1, nil, 2,
}
expected := &graphql.Result{
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": nil,
},
},
Errors: []gqlerrors.FormattedError{
gqlerrors.FormattedError{
Message: "Cannot return null for non-nullable field DataType.test.",
Locations: []location.SourceLocation{
location.SourceLocation{
Line: 1,
Column: 10,
},
},
},
},
}
checkList(t, ttype, data, expected)
}
开发者ID:Fugiman,项目名称:graphql,代码行数:25,代码来源:lists_test.go
示例5: TestTypeSystem_ListMustAcceptGraphQLTypes_RejectsANilTypeAsItemTypeOfList
func TestTypeSystem_ListMustAcceptGraphQLTypes_RejectsANilTypeAsItemTypeOfList(t *testing.T) {
result := graphql.NewList(nil)
expectedError := `Can only create List of a Type but got: <nil>.`
if result.GetError() == nil || result.GetError().Error() != expectedError {
t.Fatalf("Expected error: %v, got %v", expectedError, result.GetError())
}
}
开发者ID:Fugiman,项目名称:graphql,代码行数:7,代码来源:validation_test.go
示例6: TestLists_NonNullListOfNonNullArrayOfFunc_ContainsNulls
func TestLists_NonNullListOfNonNullArrayOfFunc_ContainsNulls(t *testing.T) {
ttype := graphql.NewNonNull(graphql.NewList(graphql.NewNonNull(graphql.Int)))
// `data` is a slice of functions that return values
// Note that its uses the expected signature `func() interface{} {...}`
data := []interface{}{
func() interface{} {
return 1
},
func() interface{} {
return nil
},
func() interface{} {
return 2
},
}
expected := &graphql.Result{
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, nil, 2,
},
},
},
}
checkList(t, ttype, data, expected)
}
开发者ID:Fugiman,项目名称:graphql,代码行数:27,代码来源:lists_test.go
示例7: TestTypeSystem_DefinitionExample_IdentifiesOutputTypes
func TestTypeSystem_DefinitionExample_IdentifiesOutputTypes(t *testing.T) {
type Test struct {
ttype graphql.Type
expected bool
}
tests := []Test{
Test{graphql.Int, true},
Test{objectType, true},
Test{interfaceType, true},
Test{unionType, true},
Test{enumType, true},
Test{inputObjectType, false},
}
for _, test := range tests {
ttypeStr := fmt.Sprintf("%v", test.ttype)
if graphql.IsOutputType(test.ttype) != test.expected {
t.Fatalf(`expected %v , got: %v`, test.expected, ttypeStr)
}
if graphql.IsOutputType(graphql.NewList(test.ttype)) != test.expected {
t.Fatalf(`expected %v , got: %v`, test.expected, ttypeStr)
}
if graphql.IsOutputType(graphql.NewNonNull(test.ttype)) != test.expected {
t.Fatalf(`expected %v , got: %v`, test.expected, ttypeStr)
}
}
}
开发者ID:Fugiman,项目名称:graphql,代码行数:26,代码来源:definition_test.go
示例8: TestLists_NonNullListOfNonNullFunc_ReturnsNull
func TestLists_NonNullListOfNonNullFunc_ReturnsNull(t *testing.T) {
ttype := graphql.NewNonNull(graphql.NewList(graphql.NewNonNull(graphql.Int)))
// `data` is a function that return values
// Note that its uses the expected signature `func() interface{} {...}`
data := func() interface{} {
return nil
}
expected := &graphql.Result{
Data: map[string]interface{}{
"nest": nil,
},
Errors: []gqlerrors.FormattedError{
gqlerrors.FormattedError{
Message: "Cannot return null for non-nullable field DataType.test.",
Locations: []location.SourceLocation{
location.SourceLocation{
Line: 1,
Column: 10,
},
},
},
},
}
checkList(t, ttype, data, expected)
}
开发者ID:Fugiman,项目名称:graphql,代码行数:26,代码来源:lists_test.go
示例9: TestTypeSystem_NonNullMustAcceptGraphQLTypes_AcceptsAnTypeAsNullableTypeOfNonNull
func TestTypeSystem_NonNullMustAcceptGraphQLTypes_AcceptsAnTypeAsNullableTypeOfNonNull(t *testing.T) {
nullableTypes := []graphql.Type{
graphql.String,
someScalarType,
someObjectType,
someUnionType,
someInterfaceType,
someEnumType,
someInputObject,
graphql.NewList(graphql.String),
graphql.NewList(graphql.NewNonNull(graphql.String)),
}
for _, ttype := range nullableTypes {
result := graphql.NewNonNull(ttype)
if result.GetError() != nil {
t.Fatalf(`unexpected error: %v for type "%v"`, result.GetError(), ttype)
}
}
}
开发者ID:Fugiman,项目名称:graphql,代码行数:19,代码来源:validation_test.go
示例10: TestLists_ListOfNullableObjects_ReturnsNull
func TestLists_ListOfNullableObjects_ReturnsNull(t *testing.T) {
ttype := graphql.NewList(graphql.Int)
expected := &graphql.Result{
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": nil,
},
},
}
checkList(t, ttype, nil, expected)
}
开发者ID:Fugiman,项目名称:graphql,代码行数:11,代码来源:lists_test.go
示例11: TestTypeSystem_ListMustAcceptGraphQLTypes_AcceptsAnTypeAsItemTypeOfList
func TestTypeSystem_ListMustAcceptGraphQLTypes_AcceptsAnTypeAsItemTypeOfList(t *testing.T) {
testTypes := withModifiers([]graphql.Type{
graphql.String,
someScalarType,
someEnumType,
someObjectType,
someUnionType,
someInterfaceType,
})
for _, ttype := range testTypes {
result := graphql.NewList(ttype)
if result.GetError() != nil {
t.Fatalf(`unexpected error: %v for type "%v"`, result.GetError(), ttype)
}
}
}
开发者ID:Fugiman,项目名称:graphql,代码行数:16,代码来源:validation_test.go
示例12: TestLists_ListOfNullableObjects_ContainsNull
func TestLists_ListOfNullableObjects_ContainsNull(t *testing.T) {
ttype := graphql.NewList(graphql.Int)
data := []interface{}{
1, nil, 2,
}
expected := &graphql.Result{
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, nil, 2,
},
},
},
}
checkList(t, ttype, data, expected)
}
开发者ID:Fugiman,项目名称:graphql,代码行数:16,代码来源:lists_test.go
示例13: TestLists_NonNullListOfNonNullObjects_ContainsValues
// Describe [T!]! Array<T>
func TestLists_NonNullListOfNonNullObjects_ContainsValues(t *testing.T) {
ttype := graphql.NewNonNull(graphql.NewList(graphql.NewNonNull(graphql.Int)))
data := []interface{}{
1, 2,
}
expected := &graphql.Result{
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, 2,
},
},
},
}
checkList(t, ttype, data, expected)
}
开发者ID:Fugiman,项目名称:graphql,代码行数:17,代码来源:lists_test.go
示例14: TestLists_NullableListOfNonNullFunc_ReturnsNull
func TestLists_NullableListOfNonNullFunc_ReturnsNull(t *testing.T) {
ttype := graphql.NewList(graphql.NewNonNull(graphql.Int))
// `data` is a function that return values
// Note that its uses the expected signature `func() interface{} {...}`
data := func() interface{} {
return nil
}
expected := &graphql.Result{
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": nil,
},
},
}
checkList(t, ttype, data, expected)
}
开发者ID:Fugiman,项目名称:graphql,代码行数:17,代码来源:lists_test.go
示例15: TestLists_ListOfNullableFunc_ContainsValues
// Describe [T] Func()Array<T> // equivalent to Promise<Array<T>>
func TestLists_ListOfNullableFunc_ContainsValues(t *testing.T) {
ttype := graphql.NewList(graphql.Int)
// `data` is a function that return values
// Note that its uses the expected signature `func() interface{} {...}`
data := func() interface{} {
return []interface{}{
1, 2,
}
}
expected := &graphql.Result{
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, 2,
},
},
},
}
checkList(t, ttype, data, expected)
}
开发者ID:Fugiman,项目名称:graphql,代码行数:22,代码来源:lists_test.go
示例16: TestUnionIntersectionTypes_GetsExecutionInfoInResolver
func TestUnionIntersectionTypes_GetsExecutionInfoInResolver(t *testing.T) {
var encounteredSchema *graphql.Schema
var encounteredRootValue interface{}
var personType2 *graphql.Object
namedType2 := graphql.NewInterface(graphql.InterfaceConfig{
Name: "Named",
Fields: graphql.FieldConfigMap{
"name": &graphql.FieldConfig{
Type: graphql.String,
},
},
ResolveType: func(value interface{}, info graphql.ResolveInfo) *graphql.Object {
encounteredSchema = &info.Schema
encounteredRootValue = info.RootValue
return personType2
},
})
personType2 = graphql.NewObject(graphql.ObjectConfig{
Name: "Person",
Interfaces: []*graphql.Interface{
namedType2,
},
Fields: graphql.FieldConfigMap{
"name": &graphql.FieldConfig{
Type: graphql.String,
},
"friends": &graphql.FieldConfig{
Type: graphql.NewList(namedType2),
},
},
})
schema2, _ := graphql.NewSchema(graphql.SchemaConfig{
Query: personType2,
})
john2 := &testPerson{
Name: "John",
Friends: []testNamedType{
liz,
},
}
doc := `{ name, friends { name } }`
expected := &graphql.Result{
Data: map[string]interface{}{
"name": "John",
"friends": []interface{}{
map[string]interface{}{
"name": "Liz",
},
},
},
}
// parse query
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: schema2,
AST: ast,
Root: john2,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) != len(expected.Errors) {
t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:Fugiman,项目名称:graphql,代码行数:75,代码来源:union_interface_test.go
示例17:
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,
},
"pets": &graphql.FieldConfig{
Type: graphql.NewList(petType),
},
"friends": &graphql.FieldConfig{
Type: graphql.NewList(namedType),
},
},
IsTypeOf: func(value interface{}, info graphql.ResolveInfo) bool {
_, ok := value.(*testPerson)
return ok
},
})
var unionInterfaceTestSchema, _ = graphql.NewSchema(graphql.SchemaConfig{
Query: personType,
})
开发者ID:Fugiman,项目名称:graphql,代码行数:30,代码来源:union_interface_test.go
示例18: TestIntrospection_ExecutesAnInputObject
func TestIntrospection_ExecutesAnInputObject(t *testing.T) {
testInputObject := graphql.NewInputObject(graphql.InputObjectConfig{
Name: "TestInputObject",
Fields: graphql.InputObjectConfigFieldMap{
"a": &graphql.InputObjectFieldConfig{
Type: graphql.String,
DefaultValue: "foo",
},
"b": &graphql.InputObjectFieldConfig{
Type: graphql.NewList(graphql.String),
},
},
})
testType := graphql.NewObject(graphql.ObjectConfig{
Name: "TestType",
Fields: graphql.FieldConfigMap{
"field": &graphql.FieldConfig{
Type: graphql.String,
Args: graphql.FieldConfigArgument{
"complex": &graphql.ArgumentConfig{
Type: testInputObject,
},
},
Resolve: func(p graphql.GQLFRParams) interface{} {
return p.Args["complex"]
},
},
},
})
schema, err := graphql.NewSchema(graphql.SchemaConfig{
Query: testType,
})
if err != nil {
t.Fatalf("Error creating Schema: %v", err.Error())
}
query := `
{
__schema {
types {
kind
name
inputFields {
name
type { ...TypeRef }
defaultValue
}
}
}
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
`
expectedDataSubSet := map[string]interface{}{
"__schema": map[string]interface{}{
"types": []interface{}{
map[string]interface{}{
"kind": "INPUT_OBJECT",
"name": "TestInputObject",
"inputFields": []interface{}{
map[string]interface{}{
"name": "a",
"type": map[string]interface{}{
"kind": "SCALAR",
"name": "String",
"ofType": nil,
},
"defaultValue": `"foo"`,
},
map[string]interface{}{
"name": "b",
"type": map[string]interface{}{
"kind": "LIST",
"name": nil,
"ofType": map[string]interface{}{
"kind": "SCALAR",
"name": "String",
"ofType": nil,
},
},
"defaultValue": nil,
},
},
},
},
//.........这里部分代码省略.........
开发者ID:Fugiman,项目名称:graphql,代码行数:101,代码来源:introspection_test.go
示例19: 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:Fugiman,项目名称:graphql,代码行数:101,代码来源:abstract_test.go
示例20: TestExecutesUsingAComplexSchema
func TestExecutesUsingAComplexSchema(t *testing.T) {
johnSmith = &testAuthor{
Id: 123,
Name: "John Smith",
Pic: func(width string, height string) *testPic {
return getPic(123, width, height)
},
RecentArticle: article("1"),
}
blogImage := graphql.NewObject(graphql.ObjectConfig{
Name: "Image",
Fields: graphql.FieldConfigMap{
"url": &graphql.FieldConfig{
Type: graphql.String,
},
"width": &graphql.FieldConfig{
Type: graphql.Int,
},
"height": &graphql.FieldConfig{
Type: graphql.Int,
},
},
})
blogAuthor := graphql.NewObject(graphql.ObjectConfig{
Name: "Author",
Fields: graphql.FieldConfigMap{
"id": &graphql.FieldConfig{
Type: graphql.String,
},
"name": &graphql.FieldConfig{
Type: graphql.String,
},
"pic": &graphql.FieldConfig{
Type: blogImage,
Args: graphql.FieldConfigArgument{
"width": &graphql.ArgumentConfig{
Type: graphql.Int,
},
"height": &graphql.ArgumentConfig{
Type: graphql.Int,
},
},
Resolve: func(p graphql.GQLFRParams) interface{} {
if author, ok := p.Source.(*testAuthor); ok {
width := fmt.Sprintf("%v", p.Args["width"])
height := fmt.Sprintf("%v", p.Args["height"])
return author.Pic(width, height)
}
return nil
},
},
"recentArticle": &graphql.FieldConfig{},
},
})
blogArticle := graphql.NewObject(graphql.ObjectConfig{
Name: "Article",
Fields: graphql.FieldConfigMap{
"id": &graphql.FieldConfig{
Type: graphql.NewNonNull(graphql.String),
},
"isPublished": &graphql.FieldConfig{
Type: graphql.Boolean,
},
"author": &graphql.FieldConfig{
Type: blogAuthor,
},
"title": &graphql.FieldConfig{
Type: graphql.String,
},
"body": &graphql.FieldConfig{
Type: graphql.String,
},
"keywords": &graphql.FieldConfig{
Type: graphql.NewList(graphql.String),
},
},
})
blogAuthor.AddFieldConfig("recentArticle", &graphql.FieldConfig{
Type: blogArticle,
})
blogQuery := graphql.NewObject(graphql.ObjectConfig{
Name: "Query",
Fields: graphql.FieldConfigMap{
"article": &graphql.FieldConfig{
Type: blogArticle,
Args: graphql.FieldConfigArgument{
"id": &graphql.ArgumentConfig{
Type: graphql.ID,
},
},
Resolve: func(p graphql.GQLFRParams) interface{} {
id := p.Args["id"]
return article(id)
},
},
"feed": &graphql.FieldConfig{
//.........这里部分代码省略.........
开发者ID:Fugiman,项目名称:graphql,代码行数:101,代码来源:executor_schema_test.go
注:本文中的github.com/chris-ramon/graphql.NewList函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论