• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang types.NewGraphQLNonNull函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/chris-ramon/graphql-go/types.NewGraphQLNonNull函数的典型用法代码示例。如果您正苦于以下问题:Golang NewGraphQLNonNull函数的具体用法?Golang NewGraphQLNonNull怎么用?Golang NewGraphQLNonNull使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewGraphQLNonNull函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: init

func init() {
	nodeTestUserType = types.NewGraphQLObjectType(types.GraphQLObjectTypeConfig{
		Name: "User",
		Fields: types.GraphQLFieldConfigMap{
			"id": &types.GraphQLFieldConfig{
				Type: types.NewGraphQLNonNull(types.GraphQLID),
			},
			"name": &types.GraphQLFieldConfig{
				Type: types.GraphQLString,
			},
		},
		Interfaces: []*types.GraphQLInterfaceType{nodeTestDef.NodeInterface},
	})
	nodeTestPhotoType = types.NewGraphQLObjectType(types.GraphQLObjectTypeConfig{
		Name: "Photo",
		Fields: types.GraphQLFieldConfigMap{
			"id": &types.GraphQLFieldConfig{
				Type: types.NewGraphQLNonNull(types.GraphQLID),
			},
			"width": &types.GraphQLFieldConfig{
				Type: types.GraphQLInt,
			},
		},
		Interfaces: []*types.GraphQLInterfaceType{nodeTestDef.NodeInterface},
	})

	nodeTestSchema, _ = types.NewGraphQLSchema(types.GraphQLSchemaConfig{
		Query: nodeTestQueryType,
	})
}
开发者ID:TribeMedia,项目名称:graphql-relay-go,代码行数:30,代码来源:node_test.go


示例2: 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


示例3: 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


示例4: 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


示例5: TestTypeSystem_DefinitionExample_ProhibitsNestingNonNullInsideNonNull

func TestTypeSystem_DefinitionExample_ProhibitsNestingNonNullInsideNonNull(t *testing.T) {
	ttype := types.NewGraphQLNonNull(types.NewGraphQLNonNull(types.GraphQLInt))
	expected := `Can only create NonNull of a Nullable GraphQLType but got: Int!.`
	if ttype.GetError().Error() != expected {
		t.Fatalf(`expected %v , got: %v`, expected, ttype.GetError())
	}
}
开发者ID:EmergentBehavior,项目名称:graphql-go,代码行数:7,代码来源:definition_test.go


示例6: 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


示例7:

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


示例8: 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


示例9: MutationWithClientMutationId

func MutationWithClientMutationId(config MutationConfig) *types.GraphQLFieldConfig {

	augmentedInputFields := config.InputFields
	if augmentedInputFields == nil {
		augmentedInputFields = types.InputObjectConfigFieldMap{}
	}
	augmentedInputFields["clientMutationId"] = &types.InputObjectFieldConfig{
		Type: types.NewGraphQLNonNull(types.GraphQLString),
	}
	augmentedOutputFields := config.OutputFields
	if augmentedOutputFields == nil {
		augmentedOutputFields = types.GraphQLFieldConfigMap{}
	}
	augmentedOutputFields["clientMutationId"] = &types.GraphQLFieldConfig{
		Type: types.NewGraphQLNonNull(types.GraphQLString),
	}

	inputType := types.NewGraphQLInputObjectType(types.InputObjectConfig{
		Name:   config.Name + "Input",
		Fields: augmentedInputFields,
	})
	outputType := types.NewGraphQLObjectType(types.GraphQLObjectTypeConfig{
		Name:   config.Name + "Payload",
		Fields: augmentedOutputFields,
	})
	return &types.GraphQLFieldConfig{
		Type: outputType,
		Args: types.GraphQLFieldConfigArgumentMap{
			"input": &types.GraphQLArgumentConfig{
				Type: types.NewGraphQLNonNull(inputType),
			},
		},
		Resolve: func(p types.GQLFRParams) interface{} {
			if config.MutateAndGetPayload == nil {
				return nil
			}
			input := map[string]interface{}{}
			if inputVal, ok := p.Args["input"]; ok {
				if inputVal, ok := inputVal.(map[string]interface{}); ok {
					input = inputVal
				}
			}
			payload := config.MutateAndGetPayload(input, p.Info)
			if clientMutationId, ok := input["clientMutationId"]; ok {
				payload["clientMutationId"] = clientMutationId
			}
			return payload
		},
	}
}
开发者ID:TribeMedia,项目名称:graphql-relay-go,代码行数:50,代码来源:mutation.go


示例10: GlobalIdField

/*
Creates the configuration for an id field on a node, using `toGlobalId` to
construct the ID from the provided typename. The type-specific ID is fetcher
by calling idFetcher on the object, or if not provided, by accessing the `id`
property on the object.
*/
func GlobalIdField(typeName string, idFetcher GlobalIdFetcherFn) *types.GraphQLFieldConfig {
	return &types.GraphQLFieldConfig{
		Name:        "id",
		Description: "The ID of an object",
		Type:        types.NewGraphQLNonNull(types.GraphQLID),
		Resolve: func(p types.GQLFRParams) interface{} {
			id := ""
			if idFetcher != nil {
				fetched := idFetcher(p.Source, p.Info)
				id = fmt.Sprintf("%v", fetched)
			} else {
				// try to get from p.Source (data)
				var objMap interface{}
				b, _ := json.Marshal(p.Source)
				_ = json.Unmarshal(b, &objMap)
				switch obj := objMap.(type) {
				case map[string]interface{}:
					if iid, ok := obj["id"]; ok {
						id = fmt.Sprintf("%v", iid)
					}
				}
			}
			globalId := ToGlobalId(typeName, id)
			return globalId
		},
	}
}
开发者ID:TribeMedia,项目名称:graphql-relay-go,代码行数:33,代码来源:node.go


示例11: 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


示例12: TestTypeSystem_NonNullMustAcceptGraphQLTypes_RejectsNilAsNonNullableType

func TestTypeSystem_NonNullMustAcceptGraphQLTypes_RejectsNilAsNonNullableType(t *testing.T) {
	result := types.NewGraphQLNonNull(nil)
	expectedError := `Can only create NonNull of a Nullable 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


示例13: 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


示例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: 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


示例16: 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


示例17: TestLists_NullableListOfNonNullObjects_ReturnsNull

func TestLists_NullableListOfNonNullObjects_ReturnsNull(t *testing.T) {
	ttype := types.NewGraphQLList(types.NewGraphQLNonNull(types.GraphQLInt))

	expected := &types.GraphQLResult{
		Data: map[string]interface{}{
			"nest": map[string]interface{}{
				"test": nil,
			},
		},
	}
	checkList(t, ttype, nil, expected)
}
开发者ID:tallstreet,项目名称:graphql-go,代码行数:12,代码来源:lists_test.go


示例18: TestLists_NonNullListOfNonNullFunc_ContainsValues

// Describe [T!]! Func()Array<T> // equivalent to Promise<Array<T>>
func TestLists_NonNullListOfNonNullFunc_ContainsValues(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 []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


示例19: init

func init() {
	throwingData["nest"] = func() interface{} {
		return throwingData
	}
	throwingData["nonNullNest"] = func() interface{} {
		return throwingData
	}
	throwingData["promiseNest"] = func() interface{} {
		return throwingData
	}
	throwingData["nonNullPromiseNest"] = func() interface{} {
		return throwingData
	}

	nullingData["nest"] = func() interface{} {
		return nullingData
	}
	nullingData["nonNullNest"] = func() interface{} {
		return nullingData
	}
	nullingData["promiseNest"] = func() interface{} {
		return nullingData
	}
	nullingData["nonNullPromiseNest"] = func() interface{} {
		return nullingData
	}

	dataType.AddFieldConfig("nest", &types.GraphQLFieldConfig{
		Type: dataType,
	})
	dataType.AddFieldConfig("nonNullNest", &types.GraphQLFieldConfig{
		Type: types.NewGraphQLNonNull(dataType),
	})
	dataType.AddFieldConfig("promiseNest", &types.GraphQLFieldConfig{
		Type: dataType,
	})
	dataType.AddFieldConfig("nonNullPromiseNest", &types.GraphQLFieldConfig{
		Type: types.NewGraphQLNonNull(dataType),
	})
}
开发者ID:EmergentBehavior,项目名称:graphql-go,代码行数:40,代码来源:nonnull_test.go


示例20: NewNodeDefinitions

/*
 Given a function to map from an ID to an underlying object, and a function
 to map from an underlying object to the concrete GraphQLObjectType it
 corresponds to, constructs a `Node` interface that objects can implement,
 and a field config for a `node` root field.

 If the typeResolver is omitted, object resolution on the interface will be
 handled with the `isTypeOf` method on object types, as with any GraphQL
interface without a provided `resolveType` method.
*/
func NewNodeDefinitions(config NodeDefinitionsConfig) *NodeDefinitions {
	nodeInterface := types.NewGraphQLInterfaceType(types.GraphQLInterfaceTypeConfig{
		Name:        "Node",
		Description: "An object with an ID",
		Fields: types.GraphQLFieldConfigMap{
			"id": &types.GraphQLFieldConfig{
				Type:        types.NewGraphQLNonNull(types.GraphQLID),
				Description: "The id of the object",
			},
		},
		ResolveType: config.TypeResolve,
	})

	nodeField := &types.GraphQLFieldConfig{
		Name:        "Node",
		Description: "Fetches an object given its ID",
		Type:        nodeInterface,
		Args: types.GraphQLFieldConfigArgumentMap{
			"id": &types.GraphQLArgumentConfig{
				Type:        types.NewGraphQLNonNull(types.GraphQLID),
				Description: "The ID of an object",
			},
		},
		Resolve: func(p types.GQLFRParams) interface{} {
			if config.IdFetcher == nil {
				return nil
			}
			id := ""
			if iid, ok := p.Args["id"]; ok {
				id = fmt.Sprintf("%v", iid)
			}
			fetchedId := config.IdFetcher(id, p.Info)
			return fetchedId
		},
	}
	return &NodeDefinitions{
		NodeInterface: nodeInterface,
		NodeField:     nodeField,
	}
}
开发者ID:TribeMedia,项目名称:graphql-relay-go,代码行数:50,代码来源:node.go



注:本文中的github.com/chris-ramon/graphql-go/types.NewGraphQLNonNull函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang types.NewGraphQLObjectType函数代码示例发布时间:2022-05-23
下一篇:
Golang types.NewGraphQLList函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap