本文整理汇总了Golang中github.com/chris-ramon/graphql-go/types.NewGraphQLList函数的典型用法代码示例。如果您正苦于以下问题:Golang NewGraphQLList函数的具体用法?Golang NewGraphQLList怎么用?Golang NewGraphQLList使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewGraphQLList函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1:
func TestTypeSystem_ObjectsMustAdhereToInterfaceTheyImplement_AcceptsAnObjectWithAnEquivalentlyModifiedInterfaceField(t *testing.T) {
anotherInterface := types.NewGraphQLInterfaceType(types.GraphQLInterfaceTypeConfig{
Name: "AnotherInterface",
ResolveType: func(value interface{}, info types.GraphQLResolveInfo) *types.GraphQLObjectType {
return nil
},
Fields: types.GraphQLFieldConfigMap{
"field": &types.GraphQLFieldConfig{
Type: types.NewGraphQLNonNull(types.NewGraphQLList(types.GraphQLString)),
},
},
})
anotherObject := types.NewGraphQLObjectType(types.GraphQLObjectTypeConfig{
Name: "AnotherObject",
Interfaces: []*types.GraphQLInterfaceType{anotherInterface},
Fields: types.GraphQLFieldConfigMap{
"field": &types.GraphQLFieldConfig{
Type: types.NewGraphQLNonNull(types.NewGraphQLList(types.GraphQLString)),
},
},
})
_, err := schemaWithObjectFieldOfType(anotherObject)
if err != nil {
t.Fatalf(`unexpected error: %v for type "%v"`, err, anotherObject)
}
}
开发者ID:EmergentBehavior,项目名称:graphql-go,代码行数:26,代码来源:validation_test.go
示例2: TestTypeSystem_DefinitionExample_StringifiesSimpleTypes
func TestTypeSystem_DefinitionExample_StringifiesSimpleTypes(t *testing.T) {
type Test struct {
ttype types.GraphQLType
expected string
}
tests := []Test{
Test{types.GraphQLInt, "Int"},
Test{blogArticle, "Article"},
Test{interfaceType, "Interface"},
Test{unionType, "Union"},
Test{enumType, "Enum"},
Test{inputObjectType, "InputObject"},
Test{types.NewGraphQLNonNull(types.GraphQLInt), "Int!"},
Test{types.NewGraphQLList(types.GraphQLInt), "[Int]"},
Test{types.NewGraphQLNonNull(types.NewGraphQLList(types.GraphQLInt)), "[Int]!"},
Test{types.NewGraphQLList(types.NewGraphQLNonNull(types.GraphQLInt)), "[Int!]"},
Test{types.NewGraphQLList(types.NewGraphQLList(types.GraphQLInt)), "[[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:EmergentBehavior,项目名称:graphql-go,代码行数:26,代码来源:definition_test.go
示例3: PluralIdentifyingRootField
func PluralIdentifyingRootField(config PluralIdentifyingRootFieldConfig) *types.GraphQLFieldConfig {
inputArgs := types.GraphQLFieldConfigArgumentMap{}
if config.ArgName != "" {
inputArgs[config.ArgName] = &types.GraphQLArgumentConfig{
Type: types.NewGraphQLNonNull(types.NewGraphQLList(types.NewGraphQLNonNull(config.InputType))),
}
}
return &types.GraphQLFieldConfig{
Description: config.Description,
Type: types.NewGraphQLList(config.OutputType),
Args: inputArgs,
Resolve: func(p types.GQLFRParams) interface{} {
inputs, ok := p.Args[config.ArgName]
if !ok {
return nil
}
if config.ResolveSingleInput == nil {
return nil
}
switch inputs := inputs.(type) {
case []interface{}:
res := []interface{}{}
for _, input := range inputs {
r := config.ResolveSingleInput(input)
res = append(res, r)
}
return res
}
return nil
},
}
}
开发者ID:TribeMedia,项目名称:graphql-relay-go,代码行数:34,代码来源:plural.go
示例4: withModifiers
func withModifiers(ttypes []types.GraphQLType) []types.GraphQLType {
res := ttypes
for _, ttype := range ttypes {
res = append(res, types.NewGraphQLList(ttype))
}
for _, ttype := range ttypes {
res = append(res, types.NewGraphQLNonNull(ttype))
}
for _, ttype := range ttypes {
res = append(res, types.NewGraphQLNonNull(types.NewGraphQLList(ttype)))
}
return res
}
开发者ID:EmergentBehavior,项目名称:graphql-go,代码行数:13,代码来源:validation_test.go
示例5: TestTypeSystem_ListMustAcceptGraphQLTypes_RejectsANilTypeAsItemTypeOfList
func TestTypeSystem_ListMustAcceptGraphQLTypes_RejectsANilTypeAsItemTypeOfList(t *testing.T) {
result := types.NewGraphQLList(nil)
expectedError := `Can only create List of a GraphQLType but got: <nil>.`
if result.GetError() == nil || result.GetError().Error() != expectedError {
t.Fatalf("Expected error: %v, got %v", expectedError, result.GetError())
}
}
开发者ID:EmergentBehavior,项目名称:graphql-go,代码行数:7,代码来源:validation_test.go
示例6: TestTypeSystem_DefinitionExample_IdentifiesOutputTypes
func TestTypeSystem_DefinitionExample_IdentifiesOutputTypes(t *testing.T) {
type Test struct {
ttype types.GraphQLType
expected bool
}
tests := []Test{
Test{types.GraphQLInt, 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 types.IsOutputType(test.ttype) != test.expected {
t.Fatalf(`expected %v , got: %v`, test.expected, ttypeStr)
}
if types.IsOutputType(types.NewGraphQLList(test.ttype)) != test.expected {
t.Fatalf(`expected %v , got: %v`, test.expected, ttypeStr)
}
if types.IsOutputType(types.NewGraphQLNonNull(test.ttype)) != test.expected {
t.Fatalf(`expected %v , got: %v`, test.expected, ttypeStr)
}
}
}
开发者ID:EmergentBehavior,项目名称:graphql-go,代码行数:26,代码来源:definition_test.go
示例7: TestLists_NonNullListOfNonNullFunc_ReturnsNull
func TestLists_NonNullListOfNonNullFunc_ReturnsNull(t *testing.T) {
ttype := types.NewGraphQLNonNull(types.NewGraphQLList(types.NewGraphQLNonNull(types.GraphQLInt)))
// `data` is a function that return values
// Note that its uses the expected signature `func() interface{} {...}`
data := func() interface{} {
return nil
}
expected := &types.GraphQLResult{
Data: map[string]interface{}{
"nest": nil,
},
Errors: []graphqlerrors.GraphQLFormattedError{
graphqlerrors.GraphQLFormattedError{
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:tallstreet,项目名称:graphql-go,代码行数:26,代码来源:lists_test.go
示例8: TestLists_NullableListOfNonNullObjects_ContainsNull
func TestLists_NullableListOfNonNullObjects_ContainsNull(t *testing.T) {
ttype := types.NewGraphQLList(types.NewGraphQLNonNull(types.GraphQLInt))
data := []interface{}{
1, nil, 2,
}
expected := &types.GraphQLResult{
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": nil,
},
},
Errors: []graphqlerrors.GraphQLFormattedError{
graphqlerrors.GraphQLFormattedError{
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:tallstreet,项目名称:graphql-go,代码行数:25,代码来源:lists_test.go
示例9: TestLists_NonNullListOfNonNullArrayOfFunc_ContainsNulls
func TestLists_NonNullListOfNonNullArrayOfFunc_ContainsNulls(t *testing.T) {
ttype := types.NewGraphQLNonNull(types.NewGraphQLList(types.NewGraphQLNonNull(types.GraphQLInt)))
// `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 := &types.GraphQLResult{
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, nil, 2,
},
},
},
}
checkList(t, ttype, data, expected)
}
开发者ID:tallstreet,项目名称:graphql-go,代码行数:27,代码来源:lists_test.go
示例10: TestTypeSystem_NonNullMustAcceptGraphQLTypes_AcceptsAnTypeAsNullableTypeOfNonNull
func TestTypeSystem_NonNullMustAcceptGraphQLTypes_AcceptsAnTypeAsNullableTypeOfNonNull(t *testing.T) {
nullableTypes := []types.GraphQLType{
types.GraphQLString,
someScalarType,
someObjectType,
someUnionType,
someInterfaceType,
someEnumType,
someInputObject,
types.NewGraphQLList(types.GraphQLString),
types.NewGraphQLList(types.NewGraphQLNonNull(types.GraphQLString)),
}
for _, ttype := range nullableTypes {
result := types.NewGraphQLNonNull(ttype)
if result.GetError() != nil {
t.Fatalf(`unexpected error: %v for type "%v"`, result.GetError(), ttype)
}
}
}
开发者ID:EmergentBehavior,项目名称:graphql-go,代码行数:19,代码来源:validation_test.go
示例11: TestLists_ListOfNullableObjects_ReturnsNull
func TestLists_ListOfNullableObjects_ReturnsNull(t *testing.T) {
ttype := types.NewGraphQLList(types.GraphQLInt)
expected := &types.GraphQLResult{
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": nil,
},
},
}
checkList(t, ttype, nil, expected)
}
开发者ID:tallstreet,项目名称:graphql-go,代码行数:11,代码来源:lists_test.go
示例12: TestLists_ListOfNullableObjects_ContainsNull
func TestLists_ListOfNullableObjects_ContainsNull(t *testing.T) {
ttype := types.NewGraphQLList(types.GraphQLInt)
data := []interface{}{
1, nil, 2,
}
expected := &types.GraphQLResult{
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, nil, 2,
},
},
},
}
checkList(t, ttype, data, expected)
}
开发者ID:tallstreet,项目名称:graphql-go,代码行数:16,代码来源:lists_test.go
示例13: TestTypeSystem_ListMustAcceptGraphQLTypes_AcceptsAnTypeAsItemTypeOfList
func TestTypeSystem_ListMustAcceptGraphQLTypes_AcceptsAnTypeAsItemTypeOfList(t *testing.T) {
testTypes := withModifiers([]types.GraphQLType{
types.GraphQLString,
someScalarType,
someEnumType,
someObjectType,
someUnionType,
someInterfaceType,
})
for _, ttype := range testTypes {
result := types.NewGraphQLList(ttype)
if result.GetError() != nil {
t.Fatalf(`unexpected error: %v for type "%v"`, result.GetError(), ttype)
}
}
}
开发者ID:EmergentBehavior,项目名称:graphql-go,代码行数:16,代码来源:validation_test.go
示例14: TestLists_NonNullListOfNonNullObjects_ContainsValues
// Describe [T!]! Array<T>
func TestLists_NonNullListOfNonNullObjects_ContainsValues(t *testing.T) {
ttype := types.NewGraphQLNonNull(types.NewGraphQLList(types.NewGraphQLNonNull(types.GraphQLInt)))
data := []interface{}{
1, 2,
}
expected := &types.GraphQLResult{
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, 2,
},
},
},
}
checkList(t, ttype, data, expected)
}
开发者ID:tallstreet,项目名称:graphql-go,代码行数:17,代码来源:lists_test.go
示例15: TestLists_NullableListOfNonNullFunc_ReturnsNull
func TestLists_NullableListOfNonNullFunc_ReturnsNull(t *testing.T) {
ttype := types.NewGraphQLList(types.NewGraphQLNonNull(types.GraphQLInt))
// `data` is a function that return values
// Note that its uses the expected signature `func() interface{} {...}`
data := func() interface{} {
return nil
}
expected := &types.GraphQLResult{
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": nil,
},
},
}
checkList(t, ttype, data, expected)
}
开发者ID:tallstreet,项目名称:graphql-go,代码行数:17,代码来源:lists_test.go
示例16: ConnectionDefinitions
func ConnectionDefinitions(config ConnectionConfig) *GraphQLConnectionDefinitions {
edgeType := types.NewGraphQLObjectType(types.GraphQLObjectTypeConfig{
Name: config.Name + "Edge",
Description: "An edge in a connection",
Fields: types.GraphQLFieldConfigMap{
"node": &types.GraphQLFieldConfig{
Type: config.NodeType,
Description: "The item at the end of the edge",
},
"cursor": &types.GraphQLFieldConfig{
Type: types.NewGraphQLNonNull(types.GraphQLString),
Description: " cursor for use in pagination",
},
},
})
for fieldName, fieldConfig := range config.EdgeFields {
edgeType.AddFieldConfig(fieldName, fieldConfig)
}
connectionType := types.NewGraphQLObjectType(types.GraphQLObjectTypeConfig{
Name: config.Name + "Connection",
Description: "A connection to a list of items.",
Fields: types.GraphQLFieldConfigMap{
"pageInfo": &types.GraphQLFieldConfig{
Type: types.NewGraphQLNonNull(pageInfoType),
Description: "Information to aid in pagination.",
},
"edges": &types.GraphQLFieldConfig{
Type: types.NewGraphQLList(edgeType),
Description: "Information to aid in pagination.",
},
},
})
for fieldName, fieldConfig := range config.ConnectionFields {
connectionType.AddFieldConfig(fieldName, fieldConfig)
}
return &GraphQLConnectionDefinitions{
EdgeType: edgeType,
ConnectionType: connectionType,
}
}
开发者ID:TribeMedia,项目名称:graphql-relay-go,代码行数:44,代码来源:connection.go
示例17: TestLists_ListOfNullableFunc_ContainsValues
// Describe [T] Func()Array<T> // equivalent to Promise<Array<T>>
func TestLists_ListOfNullableFunc_ContainsValues(t *testing.T) {
ttype := types.NewGraphQLList(types.GraphQLInt)
// `data` is a function that return values
// Note that its uses the expected signature `func() interface{} {...}`
data := func() interface{} {
return []interface{}{
1, 2,
}
}
expected := &types.GraphQLResult{
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, 2,
},
},
},
}
checkList(t, ttype, data, expected)
}
开发者ID:tallstreet,项目名称:graphql-go,代码行数:22,代码来源:lists_test.go
示例18: TestFailsWhenAnIsTypeOfCheckIsNotMet
func TestFailsWhenAnIsTypeOfCheckIsNotMet(t *testing.T) {
query := `{ specials { value } }`
data := map[string]interface{}{
"specials": []interface{}{
testSpecialType{"foo"},
testNotSpecialType{"bar"},
},
}
expected := &types.GraphQLResult{
Data: map[string]interface{}{
"specials": []interface{}{
map[string]interface{}{
"value": "foo",
},
nil,
},
},
Errors: []graphqlerrors.GraphQLFormattedError{
graphqlerrors.GraphQLFormattedError{
Message: `Expected value of type "SpecialType" but got: executor_test.testNotSpecialType.`,
Locations: []location.SourceLocation{},
},
},
}
specialType := types.NewGraphQLObjectType(types.GraphQLObjectTypeConfig{
Name: "SpecialType",
IsTypeOf: func(value interface{}, info types.GraphQLResolveInfo) bool {
if _, ok := value.(testSpecialType); ok {
return true
}
return false
},
Fields: types.GraphQLFieldConfigMap{
"value": &types.GraphQLFieldConfig{
Type: types.GraphQLString,
Resolve: func(ctx context.Context, p types.GQLFRParams) interface{} {
return p.Source.(testSpecialType).Value
},
},
},
})
schema, err := types.NewGraphQLSchema(types.GraphQLSchemaConfig{
Query: types.NewGraphQLObjectType(types.GraphQLObjectTypeConfig{
Name: "Query",
Fields: types.GraphQLFieldConfigMap{
"specials": &types.GraphQLFieldConfig{
Type: types.NewGraphQLList(specialType),
Resolve: func(ctx context.Context, p types.GQLFRParams) interface{} {
return p.Source.(map[string]interface{})["specials"]
},
},
},
}),
})
if err != nil {
t.Fatalf("Error in schema %v", err.Error())
}
// parse query
ast := testutil.Parse(t, query)
// execute
ep := executor.ExecuteParams{
Schema: schema,
AST: ast,
Root: data,
}
result := testutil.Execute(t, ep)
if len(result.Errors) == 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:tallstreet,项目名称:graphql-go,代码行数:79,代码来源:executor_test.go
示例19: TestExecutesArbitraryCode
//.........这里部分代码省略.........
if !ok {
return nil
}
// get and type assert argument
sizeArg, ok := p.Args["size"].(int)
if !ok {
return nil
}
return picResolver(sizeArg)
}
dataType := types.NewGraphQLObjectType(types.GraphQLObjectTypeConfig{
Name: "DataType",
Fields: types.GraphQLFieldConfigMap{
"a": &types.GraphQLFieldConfig{
Type: types.GraphQLString,
},
"b": &types.GraphQLFieldConfig{
Type: types.GraphQLString,
},
"c": &types.GraphQLFieldConfig{
Type: types.GraphQLString,
},
"d": &types.GraphQLFieldConfig{
Type: types.GraphQLString,
},
"e": &types.GraphQLFieldConfig{
Type: types.GraphQLString,
},
"f": &types.GraphQLFieldConfig{
Type: types.GraphQLString,
},
"pic": &types.GraphQLFieldConfig{
Args: types.GraphQLFieldConfigArgumentMap{
"size": &types.GraphQLArgumentConfig{
Type: types.GraphQLInt,
},
},
Type: types.GraphQLString,
Resolve: picResolverFn,
},
},
})
deepDataType := types.NewGraphQLObjectType(types.GraphQLObjectTypeConfig{
Name: "DeepDataType",
Fields: types.GraphQLFieldConfigMap{
"a": &types.GraphQLFieldConfig{
Type: types.GraphQLString,
},
"b": &types.GraphQLFieldConfig{
Type: types.GraphQLString,
},
"c": &types.GraphQLFieldConfig{
Type: types.NewGraphQLList(types.GraphQLString),
},
"deeper": &types.GraphQLFieldConfig{
Type: types.NewGraphQLList(dataType),
},
},
})
// Exploring a way to have a GraphQLObjectType within itself
// in this case DataType has DeepDataType has DataType
dataType.AddFieldConfig("deep", &types.GraphQLFieldConfig{
Type: deepDataType,
})
// in this case DataType has DataType
dataType.AddFieldConfig("promise", &types.GraphQLFieldConfig{
Type: dataType,
})
schema, err := types.NewGraphQLSchema(types.GraphQLSchemaConfig{
Query: dataType,
})
if err != nil {
t.Fatalf("Error in schema %v", err.Error())
}
// parse query
astDoc := testutil.Parse(t, query)
// execute
args := map[string]interface{}{
"size": 100,
}
operationName := "Example"
ep := executor.ExecuteParams{
Schema: schema,
Root: data,
AST: astDoc,
OperationName: operationName,
Args: args,
}
result := testutil.Execute(t, ep)
if len(result.Errors) > 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:tallstreet,项目名称:graphql-go,代码行数:101,代码来源:executor_test.go
示例20: TestUnionIntersectionTypes_GetsExecutionInfoInResolver
func TestUnionIntersectionTypes_GetsExecutionInfoInResolver(t *testing.T) {
var encounteredSchema *types.GraphQLSchema
var encounteredRootValue interface{}
var personType2 *types.GraphQLObjectType
namedType2 := types.NewGraphQLInterfaceType(types.GraphQLInterfaceTypeConfig{
Name: "Named",
Fields: types.GraphQLFieldConfigMap{
"name": &types.GraphQLFieldConfig{
Type: types.GraphQLString,
},
},
ResolveType: func(value interface{}, info types.GraphQLResolveInfo) *types.GraphQLObjectType {
encounteredSchema = &info.Schema
encounteredRootValue = info.RootValue
return personType2
},
})
personType2 = types.NewGraphQLObjectType(types.GraphQLObjectTypeConfig{
Name: "Person",
Interfaces: []*types.GraphQLInterfaceType{
namedType2,
},
Fields: types.GraphQLFieldConfigMap{
"name": &types.GraphQLFieldConfig{
Type: types.GraphQLString,
},
"friends": &types.GraphQLFieldConfig{
Type: types.NewGraphQLList(namedType2),
},
},
})
schema2, _ := types.NewGraphQLSchema(types.GraphQLSchemaConfig{
Query: personType2,
})
john2 := &testPerson{
Name: "John",
Friends: []testNamedType{
liz,
},
}
doc := `{ name, friends { name } }`
expected := &types.GraphQLResult{
Data: map[string]interface{}{
"name": "John",
"friends": []interface{}{
map[string]interface{}{
"name": "Liz",
},
},
},
}
// parse query
ast := testutil.Parse(t, doc)
// execute
ep := executor.ExecuteParams{
Schema: schema2,
AST: ast,
Root: john2,
}
result := testutil.Execute(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:EmergentBehavior,项目名称:graphql-go,代码行数:75,代码来源:union_interface_test.go
注:本文中的github.com/chris-ramon/graphql-go/types.NewGraphQLList函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论