本文整理汇总了Golang中github.com/housinganywhere/graphql.NewList函数的典型用法代码示例。如果您正苦于以下问题:Golang NewList函数的具体用法?Golang NewList怎么用?Golang NewList使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewList函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: PluralIdentifyingRootField
func PluralIdentifyingRootField(config PluralIdentifyingRootFieldConfig) *graphql.Field {
inputArgs := graphql.FieldConfigArgument{}
if config.ArgName != "" {
inputArgs[config.ArgName] = &graphql.ArgumentConfig{
Type: graphql.NewNonNull(graphql.NewList(graphql.NewNonNull(config.InputType))),
}
}
return &graphql.Field{
Description: config.Description,
Type: graphql.NewList(config.OutputType),
Args: inputArgs,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
inputs, ok := p.Args[config.ArgName]
if !ok {
return nil, nil
}
if config.ResolveSingleInput == nil {
return nil, nil
}
switch inputs := inputs.(type) {
case []interface{}:
res := []interface{}{}
for _, input := range inputs {
r := config.ResolveSingleInput(input)
res = append(res, r)
}
return res, nil
}
return nil, nil
},
}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:34,代码来源:plural.go
示例2: TestTypeSystem_DefinitionExample_StringifiesSimpleTypes
func TestTypeSystem_DefinitionExample_StringifiesSimpleTypes(t *testing.T) {
type Test struct {
ttype graphql.Type
expected string
}
tests := []Test{
{graphql.Int, "Int"},
{blogArticle, "Article"},
{interfaceType, "Interface"},
{unionType, "Union"},
{enumType, "Enum"},
{inputObjectType, "InputObject"},
{graphql.NewNonNull(graphql.Int), "Int!"},
{graphql.NewList(graphql.Int), "[Int]"},
{graphql.NewNonNull(graphql.NewList(graphql.Int)), "[Int]!"},
{graphql.NewList(graphql.NewNonNull(graphql.Int)), "[Int!]"},
{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:housinganywhere,项目名称:graphql,代码行数:26,代码来源:definition_test.go
示例3:
func TestTypeSystem_ObjectsMustAdhereToInterfaceTheyImplement_AcceptsAnObjectWithAnEquivalentlyModifiedInterfaceField(t *testing.T) {
anotherInterface := graphql.NewInterface(graphql.InterfaceConfig{
Name: "AnotherInterface",
ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object {
return nil
},
Fields: graphql.Fields{
"field": &graphql.Field{
Type: graphql.NewNonNull(graphql.NewList(graphql.String)),
},
},
})
anotherObject := graphql.NewObject(graphql.ObjectConfig{
Name: "AnotherObject",
Interfaces: []*graphql.Interface{anotherInterface},
Fields: graphql.Fields{
"field": &graphql.Field{
Type: graphql.NewNonNull(graphql.NewList(graphql.String)),
},
},
})
_, err := schemaWithObjectFieldOfType(anotherObject)
if err != nil {
t.Fatalf(`unexpected error: %v for type "%v"`, err, anotherObject)
}
}
开发者ID:housinganywhere,项目名称:graphql,代码行数:26,代码来源:validation_test.go
示例4: 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:housinganywhere,项目名称:graphql,代码行数:13,代码来源:validation_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.Error() == nil || result.Error().Error() != expectedError {
t.Fatalf("Expected error: %v, got %v", expectedError, result.Error())
}
}
开发者ID:housinganywhere,项目名称:graphql,代码行数:7,代码来源:validation_test.go
示例6: TestTypeSystem_DefinitionExample_IdentifiesOutputTypes
func TestTypeSystem_DefinitionExample_IdentifiesOutputTypes(t *testing.T) {
type Test struct {
ttype graphql.Type
expected bool
}
tests := []Test{
{graphql.Int, true},
{objectType, true},
{interfaceType, true},
{unionType, true},
{enumType, true},
{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:housinganywhere,项目名称:graphql,代码行数:26,代码来源:definition_test.go
示例7: 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:housinganywhere,项目名称:graphql,代码行数:27,代码来源:lists_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{
{
Message: "Cannot return null for non-nullable field DataType.test.",
Locations: []location.SourceLocation{
{
Line: 1,
Column: 10,
},
},
},
},
}
checkList(t, ttype, data, expected)
}
开发者ID:housinganywhere,项目名称:graphql,代码行数:26,代码来源:lists_test.go
示例9: 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{
{
Message: "Cannot return null for non-nullable field DataType.test.",
Locations: []location.SourceLocation{
{
Line: 1,
Column: 10,
},
},
},
},
}
checkList(t, ttype, data, expected)
}
开发者ID:housinganywhere,项目名称:graphql,代码行数:25,代码来源:lists_test.go
示例10: 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.Error() != nil {
t.Fatalf(`unexpected error: %v for type "%v"`, result.Error(), ttype)
}
}
}
开发者ID:housinganywhere,项目名称:graphql,代码行数:19,代码来源:validation_test.go
示例11: 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:housinganywhere,项目名称:graphql,代码行数:11,代码来源:lists_test.go
示例12: 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.Error() != nil {
t.Fatalf(`unexpected error: %v for type "%v"`, result.Error(), ttype)
}
}
}
开发者ID:housinganywhere,项目名称:graphql,代码行数:16,代码来源:validation_test.go
示例13: 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:housinganywhere,项目名称:graphql,代码行数:16,代码来源:lists_test.go
示例14: 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:housinganywhere,项目名称:graphql,代码行数:17,代码来源:lists_test.go
示例15: 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:housinganywhere,项目名称:graphql,代码行数:17,代码来源:lists_test.go
示例16: TestLists_UserErrorExpectIterableButDidNotGetOne
func TestLists_UserErrorExpectIterableButDidNotGetOne(t *testing.T) {
ttype := graphql.NewList(graphql.Int)
data := "Not an iterable"
expected := &graphql.Result{
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": nil,
},
},
Errors: []gqlerrors.FormattedError{
{
Message: "User Error: expected iterable, but did not find one for field DataType.test.",
Locations: []location.SourceLocation{},
},
},
}
checkList(t, ttype, data, expected)
}
开发者ID:housinganywhere,项目名称:graphql,代码行数:18,代码来源:lists_test.go
示例17: ConnectionDefinitions
func ConnectionDefinitions(config ConnectionConfig) *GraphQLConnectionDefinitions {
edgeType := graphql.NewObject(graphql.ObjectConfig{
Name: config.Name + "Edge",
Description: "An edge in a connection",
Fields: graphql.Fields{
"node": &graphql.Field{
Type: config.NodeType,
Description: "The item at the end of the edge",
},
"cursor": &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
Description: " cursor for use in pagination",
},
},
})
for fieldName, fieldConfig := range config.EdgeFields {
edgeType.AddFieldConfig(fieldName, fieldConfig)
}
connectionType := graphql.NewObject(graphql.ObjectConfig{
Name: config.Name + "Connection",
Description: "A connection to a list of items.",
Fields: graphql.Fields{
"pageInfo": &graphql.Field{
Type: graphql.NewNonNull(pageInfoType),
Description: "Information to aid in pagination.",
},
"edges": &graphql.Field{
Type: graphql.NewList(edgeType),
Description: "Information to aid in pagination.",
},
},
})
for fieldName, fieldConfig := range config.ConnectionFields {
connectionType.AddFieldConfig(fieldName, fieldConfig)
}
return &GraphQLConnectionDefinitions{
EdgeType: edgeType,
ConnectionType: connectionType,
}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:44,代码来源:connection.go
示例18: 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:housinganywhere,项目名称:graphql,代码行数:22,代码来源:lists_test.go
示例19: 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.Fields{
"url": &graphql.Field{
Type: graphql.String,
},
"width": &graphql.Field{
Type: graphql.Int,
},
"height": &graphql.Field{
Type: graphql.Int,
},
},
})
blogAuthor := graphql.NewObject(graphql.ObjectConfig{
Name: "Author",
Fields: graphql.Fields{
"id": &graphql.Field{
Type: graphql.String,
},
"name": &graphql.Field{
Type: graphql.String,
},
"pic": &graphql.Field{
Type: blogImage,
Args: graphql.FieldConfigArgument{
"width": &graphql.ArgumentConfig{
Type: graphql.Int,
},
"height": &graphql.ArgumentConfig{
Type: graphql.Int,
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
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), nil
}
return nil, nil
},
},
"recentArticle": &graphql.Field{},
},
})
blogArticle := graphql.NewObject(graphql.ObjectConfig{
Name: "Article",
Fields: graphql.Fields{
"id": &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
},
"isPublished": &graphql.Field{
Type: graphql.Boolean,
},
"author": &graphql.Field{
Type: blogAuthor,
},
"title": &graphql.Field{
Type: graphql.String,
},
"body": &graphql.Field{
Type: graphql.String,
},
"keywords": &graphql.Field{
Type: graphql.NewList(graphql.String),
},
},
})
blogAuthor.AddFieldConfig("recentArticle", &graphql.Field{
Type: blogArticle,
})
blogQuery := graphql.NewObject(graphql.ObjectConfig{
Name: "Query",
Fields: graphql.Fields{
"article": &graphql.Field{
Type: blogArticle,
Args: graphql.FieldConfigArgument{
"id": &graphql.ArgumentConfig{
Type: graphql.ID,
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
id := p.Args["id"]
return article(id), nil
},
},
"feed": &graphql.Field{
//.........这里部分代码省略.........
开发者ID:housinganywhere,项目名称:graphql,代码行数:101,代码来源:executor_schema_test.go
示例20: init
func init() {
someBoxInterface = graphql.NewInterface(graphql.InterfaceConfig{
Name: "SomeBox",
ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object {
return stringBoxObject
},
Fields: graphql.FieldsThunk(func() graphql.Fields {
return graphql.Fields{
"deepBox": &graphql.Field{
Type: someBoxInterface,
},
"unrelatedField": &graphql.Field{
Type: graphql.String,
},
}
}),
})
stringBoxObject = graphql.NewObject(graphql.ObjectConfig{
Name: "StringBox",
Interfaces: (graphql.InterfacesThunk)(func() []*graphql.Interface {
return []*graphql.Interface{someBoxInterface}
}),
Fields: graphql.FieldsThunk(func() graphql.Fields {
return graphql.Fields{
"scalar": &graphql.Field{
Type: graphql.String,
},
"deepBox": &graphql.Field{
Type: stringBoxObject,
},
"unrelatedField": &graphql.Field{
Type: graphql.String,
},
"listStringBox": &graphql.Field{
Type: graphql.NewList(stringBoxObject),
},
"stringBox": &graphql.Field{
Type: stringBoxObject,
},
"intBox": &graphql.Field{
Type: intBoxObject,
},
}
}),
})
intBoxObject = graphql.NewObject(graphql.ObjectConfig{
Name: "IntBox",
Interfaces: (graphql.InterfacesThunk)(func() []*graphql.Interface {
return []*graphql.Interface{someBoxInterface}
}),
Fields: graphql.FieldsThunk(func() graphql.Fields {
return graphql.Fields{
"scalar": &graphql.Field{
Type: graphql.Int,
},
"deepBox": &graphql.Field{
Type: someBoxInterface,
},
"unrelatedField": &graphql.Field{
Type: graphql.String,
},
"listStringBox": &graphql.Field{
Type: graphql.NewList(stringBoxObject),
},
"stringBox": &graphql.Field{
Type: stringBoxObject,
},
"intBox": &graphql.Field{
Type: intBoxObject,
},
}
}),
})
var nonNullStringBox1Interface = graphql.NewInterface(graphql.InterfaceConfig{
Name: "NonNullStringBox1",
ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object {
return stringBoxObject
},
Fields: graphql.Fields{
"scalar": &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
},
},
})
NonNullStringBox1Impl := graphql.NewObject(graphql.ObjectConfig{
Name: "NonNullStringBox1Impl",
Interfaces: (graphql.InterfacesThunk)(func() []*graphql.Interface {
return []*graphql.Interface{someBoxInterface, nonNullStringBox1Interface}
}),
Fields: graphql.Fields{
"scalar": &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
},
"unrelatedField": &graphql.Field{
Type: graphql.String,
},
"deepBox": &graphql.Field{
Type: someBoxInterface,
},
},
//.........这里部分代码省略.........
开发者ID:housinganywhere,项目名称:graphql,代码行数:101,代码来源:rules_overlapping_fields_can_be_merged_test.go
注:本文中的github.com/housinganywhere/graphql.NewList函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论