當前位置: 首頁>>代碼示例>>Golang>>正文


Golang types.NewGraphQLList函數代碼示例

本文整理匯總了Golang中github.com/chris-ramon/graphql-go/types.NewGraphQLList函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewGraphQLList函數的具體用法?Golang NewGraphQLList怎麽用?Golang NewGraphQLList使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewGraphQLList函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/chris-ramon/graphql-go/types.NewGraphQLList函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。