本文整理汇总了Golang中github.com/graphql-go/graphql.NewNonNull函数的典型用法代码示例。如果您正苦于以下问题:Golang NewNonNull函数的具体用法?Golang NewNonNull怎么用?Golang NewNonNull使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewNonNull函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: PluralIdentifyingRootField
func PluralIdentifyingRootField(config PluralIdentifyingRootFieldConfig) *graphql.FieldConfig {
inputArgs := graphql.FieldConfigArgument{}
if config.ArgName != "" {
inputArgs[config.ArgName] = &graphql.ArgumentConfig{
Type: graphql.NewNonNull(graphql.NewList(graphql.NewNonNull(config.InputType))),
}
}
return &graphql.FieldConfig{
Description: config.Description,
Type: graphql.NewList(config.OutputType),
Args: inputArgs,
Resolve: func(p graphql.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:evenco,项目名称:go-graphql-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:trythings,项目名称:trythings,代码行数:26,代码来源:definition_test.go
示例3: init
func init() {
nodeTestUserType = graphql.NewObject(graphql.ObjectConfig{
Name: "User",
Fields: graphql.FieldConfigMap{
"id": &graphql.FieldConfig{
Type: graphql.NewNonNull(graphql.ID),
},
"name": &graphql.FieldConfig{
Type: graphql.String,
},
},
Interfaces: []*graphql.Interface{nodeTestDef.NodeInterface},
})
nodeTestPhotoType = graphql.NewObject(graphql.ObjectConfig{
Name: "Photo",
Fields: graphql.FieldConfigMap{
"id": &graphql.FieldConfig{
Type: graphql.NewNonNull(graphql.ID),
},
"width": &graphql.FieldConfig{
Type: graphql.Int,
},
},
Interfaces: []*graphql.Interface{nodeTestDef.NodeInterface},
})
nodeTestSchema, _ = graphql.NewSchema(graphql.SchemaConfig{
Query: nodeTestQueryType,
})
}
开发者ID:evenco,项目名称:go-graphql-relay,代码行数:30,代码来源:node_test.go
示例4: TestTypeSystem_DefinitionExample_ProhibitsNestingNonNullInsideNonNull
func TestTypeSystem_DefinitionExample_ProhibitsNestingNonNullInsideNonNull(t *testing.T) {
ttype := graphql.NewNonNull(graphql.NewNonNull(graphql.Int))
expected := `Can only create NonNull of a Nullable Type but got: Int!.`
if ttype.Error().Error() != expected {
t.Fatalf(`expected %v , got: %v`, expected, ttype.Error())
}
}
开发者ID:trythings,项目名称:trythings,代码行数:7,代码来源:definition_test.go
示例5: 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, fmt.Errorf("Missing arg %q", config.ArgName)
}
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, fmt.Errorf("Can't handle %T", inputs)
},
}
}
开发者ID:augustoroman,项目名称:relay,代码行数:34,代码来源:plural.go
示例6: 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:rtbustamantec,项目名称:graphql,代码行数:26,代码来源:lists_test.go
示例7:
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:bbuck,项目名称:graphql,代码行数:26,代码来源:validation_test.go
示例8: 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:rtbustamantec,项目名称:graphql,代码行数:27,代码来源:lists_test.go
示例9: MutationWithClientMutationID
func MutationWithClientMutationID(config MutationConfig) *graphql.Field {
augmentedInputFields := config.InputFields
if augmentedInputFields == nil {
augmentedInputFields = graphql.InputObjectConfigFieldMap{}
}
augmentedInputFields["clientMutationId"] = &graphql.InputObjectFieldConfig{
Type: graphql.NewNonNull(graphql.String),
}
augmentedOutputFields := config.OutputFields
if augmentedOutputFields == nil {
augmentedOutputFields = graphql.Fields{}
}
augmentedOutputFields["clientMutationId"] = &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
}
inputType := graphql.NewInputObject(graphql.InputObjectConfig{
Name: config.Name + "Input",
Fields: augmentedInputFields,
})
outputType := graphql.NewObject(graphql.ObjectConfig{
Name: config.Name + "Payload",
Fields: augmentedOutputFields,
})
return &graphql.Field{
Name: config.Name,
Type: outputType,
Args: graphql.FieldConfigArgument{
"input": &graphql.ArgumentConfig{
Type: graphql.NewNonNull(inputType),
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if config.MutateAndGetPayload == nil {
return nil, nil
}
input := map[string]interface{}{}
if inputVal, ok := p.Args["input"]; ok {
if inputVal, ok := inputVal.(map[string]interface{}); ok {
input = inputVal
}
}
payload, err := config.MutateAndGetPayload(input, p.Info, p.Context)
if err != nil {
return nil, err
}
if clientMutationID, ok := input["clientMutationId"]; ok {
payload["clientMutationId"] = clientMutationID
}
return payload, nil
},
}
}
开发者ID:N0hbdy,项目名称:relay,代码行数:54,代码来源:mutation.go
示例10: 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:bbuck,项目名称:graphql,代码行数:13,代码来源:validation_test.go
示例11: 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:trythings,项目名称:trythings,代码行数:26,代码来源:definition_test.go
示例12:
func TestTypeSystem_ObjectsMustAdhereToInterfaceTheyImplement_AcceptsAnObjectWithSubsetNonNullInterfaceFieldType(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.String,
},
},
})
anotherObject := graphql.NewObject(graphql.ObjectConfig{
Name: "AnotherObject",
Interfaces: []*graphql.Interface{anotherInterface},
Fields: graphql.Fields{
"field": &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
},
},
})
_, err := schemaWithFieldType(anotherObject)
if err != nil {
t.Fatalf(`unexpected error: %v for type "%v"`, err, anotherObject)
}
}
开发者ID:trythings,项目名称:trythings,代码行数:26,代码来源:validation_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:rtbustamantec,项目名称:graphql,代码行数:17,代码来源:lists_test.go
示例14: 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:rtbustamantec,项目名称:graphql,代码行数:25,代码来源:lists_test.go
示例15: TestTypeSystem_NonNullMustAcceptGraphQLTypes_RejectsNilAsNonNullableType
func TestTypeSystem_NonNullMustAcceptGraphQLTypes_RejectsNilAsNonNullableType(t *testing.T) {
result := graphql.NewNonNull(nil)
expectedError := `Can only create NonNull of a Nullable Type but got: <nil>.`
if result.GetError() == nil || result.GetError().Error() != expectedError {
t.Fatalf("Expected error: %v, got %v", expectedError, result.GetError())
}
}
开发者ID:bbuck,项目名称:graphql,代码行数:7,代码来源:validation_test.go
示例16: 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) *graphql.Field {
return &graphql.Field{
Name: "id",
Description: "The ID of an object",
Type: graphql.NewNonNull(graphql.ID),
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
id := ""
if idFetcher != nil {
fetched, err := idFetcher(p.Source, p.Info, p.Context)
id = fmt.Sprintf("%v", fetched)
if err != nil {
return id, err
}
} 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, nil
},
}
}
开发者ID:trythings,项目名称:trythings,代码行数:36,代码来源:node.go
示例17: TestTypeSystem_DefinitionExample_ProhibitsNilInNonNull
func TestTypeSystem_DefinitionExample_ProhibitsNilInNonNull(t *testing.T) {
ttype := graphql.NewNonNull(nil)
expected := `Can only create NonNull of a Nullable Type but got: <nil>.`
if ttype.GetError().Error() != expected {
t.Fatalf(`expected %v , got: %v`, expected, ttype.GetError())
}
}
开发者ID:bbuck,项目名称:graphql,代码行数:7,代码来源:definition_test.go
示例18: 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:N0hbdy,项目名称:relay,代码行数:44,代码来源:connection.go
示例19: 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:bbuck,项目名称:graphql,代码行数:19,代码来源:validation_test.go
示例20: TestLists_NonNullListOfNonNullFunc_ContainsValues
// Describe [T!]! Func()Array<T> // equivalent to Promise<Array<T>>
func TestLists_NonNullListOfNonNullFunc_ContainsValues(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 []interface{}{
1, 2,
}
}
expected := &graphql.Result{
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, 2,
},
},
},
}
checkList(t, ttype, data, expected)
}
开发者ID:rtbustamantec,项目名称:graphql,代码行数:22,代码来源:lists_test.go
注:本文中的github.com/graphql-go/graphql.NewNonNull函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论