当前位置: 首页>>代码示例>>Golang>>正文


Golang relay.NewConnectionArguments函数代码示例

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


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

示例1: TestConnectionFromArray_HandlesPagination_RespectsLastAndAfterAndBefore_TooFew

func TestConnectionFromArray_HandlesPagination_RespectsLastAndAfterAndBefore_TooFew(t *testing.T) {
	filter := map[string]interface{}{
		"last":   2,
		"after":  "YXJyYXljb25uZWN0aW9uOjA=",
		"before": "YXJyYXljb25uZWN0aW9uOjQ=",
	}
	args := relay.NewConnectionArguments(filter)

	expected := &relay.Connection{
		Edges: []*relay.Edge{
			&relay.Edge{
				Node:   "C",
				Cursor: "YXJyYXljb25uZWN0aW9uOjI=",
			},
			&relay.Edge{
				Node:   "D",
				Cursor: "YXJyYXljb25uZWN0aW9uOjM=",
			},
		},
		PageInfo: relay.PageInfo{
			StartCursor:     "YXJyYXljb25uZWN0aW9uOjI=",
			EndCursor:       "YXJyYXljb25uZWN0aW9uOjM=",
			HasPreviousPage: true,
			HasNextPage:     false,
		},
	}

	result := relay.ConnectionFromArray(arrayConnectionTestLetters, args)
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, connection result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:32,代码来源:array_connection_test.go

示例2: TestConnectionFromArraySlice_UndersizedSliceBoth

func TestConnectionFromArraySlice_UndersizedSliceBoth(t *testing.T) {
	filter := map[string]interface{}{
		"first": 3,
		"after": "YXJyYXljb25uZWN0aW9uOjE=",
	}
	args := relay.NewConnectionArguments(filter)

	expected := &relay.Connection{
		Edges: []*relay.Edge{
			&relay.Edge{
				Node:   "D",
				Cursor: "YXJyYXljb25uZWN0aW9uOjM=",
			},
		},
		PageInfo: relay.PageInfo{
			StartCursor:     "YXJyYXljb25uZWN0aW9uOjM=",
			EndCursor:       "YXJyYXljb25uZWN0aW9uOjM=",
			HasPreviousPage: false,
			HasNextPage:     true,
		},
	}

	result := relay.ConnectionFromArraySlice(
		arrayConnectionTestLetters[3:4],
		args,
		relay.ArraySliceMetaInfo{
			SliceStart:  3,
			ArrayLength: 5,
		},
	)
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, connection result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:34,代码来源:array_connection_test.go

示例3: TestConnectionFromArray_HandlesCursorEdgeCases_ReturnsNoElementsIfCursorsCross

func TestConnectionFromArray_HandlesCursorEdgeCases_ReturnsNoElementsIfCursorsCross(t *testing.T) {
	filter := map[string]interface{}{
		"before": "YXJyYXljb25uZWN0aW9uOjI=", // ==> offset: int(2)
		"after":  "YXJyYXljb25uZWN0aW9uOjQ=", // ==> offset: int(4)
	}
	args := relay.NewConnectionArguments(filter)

	expected := &relay.Connection{
		Edges:    []*relay.Edge{},
		PageInfo: relay.PageInfo{},
	}

	result := relay.ConnectionFromArray(arrayConnectionTestLetters, args)
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, connection result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:17,代码来源:array_connection_test.go

示例4: TestConnectionFromArray_HandlesBasicSlicing_RespectsAnOverlyLargeFirst

func TestConnectionFromArray_HandlesBasicSlicing_RespectsAnOverlyLargeFirst(t *testing.T) {

	filter := map[string]interface{}{
		"first": 10,
	}
	args := relay.NewConnectionArguments(filter)

	expected := &relay.Connection{
		Edges: []*relay.Edge{
			&relay.Edge{
				Node:   "A",
				Cursor: "YXJyYXljb25uZWN0aW9uOjA=",
			},
			&relay.Edge{
				Node:   "B",
				Cursor: "YXJyYXljb25uZWN0aW9uOjE=",
			},
			&relay.Edge{
				Node:   "C",
				Cursor: "YXJyYXljb25uZWN0aW9uOjI=",
			},
			&relay.Edge{
				Node:   "D",
				Cursor: "YXJyYXljb25uZWN0aW9uOjM=",
			},
			&relay.Edge{
				Node:   "E",
				Cursor: "YXJyYXljb25uZWN0aW9uOjQ=",
			},
		},
		PageInfo: relay.PageInfo{
			StartCursor:     "YXJyYXljb25uZWN0aW9uOjA=",
			EndCursor:       "YXJyYXljb25uZWN0aW9uOjQ=",
			HasPreviousPage: false,
			HasNextPage:     false,
		},
	}

	result := relay.ConnectionFromArray(arrayConnectionTestLetters, args)
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, connection result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:43,代码来源:array_connection_test.go

示例5: TestConnectionFromArray_HandlesCursorEdgeCases_ReturnsAllElementsIfCursorsAreOnTheOutside

func TestConnectionFromArray_HandlesCursorEdgeCases_ReturnsAllElementsIfCursorsAreOnTheOutside(t *testing.T) {
	filter := map[string]interface{}{
		"before": "YXJyYXljb25uZWN0aW9uOjYK",     // ==> offset: int(6)
		"after":  "YXJyYXljb25uZWN0aW9uOi0xCg==", // ==> offset: int(-1)
	}
	args := relay.NewConnectionArguments(filter)

	expected := &relay.Connection{
		Edges: []*relay.Edge{
			&relay.Edge{
				Node:   "A",
				Cursor: "YXJyYXljb25uZWN0aW9uOjA=",
			},
			&relay.Edge{
				Node:   "B",
				Cursor: "YXJyYXljb25uZWN0aW9uOjE=",
			},
			&relay.Edge{
				Node:   "C",
				Cursor: "YXJyYXljb25uZWN0aW9uOjI=",
			},
			&relay.Edge{
				Node:   "D",
				Cursor: "YXJyYXljb25uZWN0aW9uOjM=",
			},
			&relay.Edge{
				Node:   "E",
				Cursor: "YXJyYXljb25uZWN0aW9uOjQ=",
			},
		},
		PageInfo: relay.PageInfo{
			StartCursor:     "YXJyYXljb25uZWN0aW9uOjA=",
			EndCursor:       "YXJyYXljb25uZWN0aW9uOjQ=",
			HasPreviousPage: false,
			HasNextPage:     false,
		},
	}

	result := relay.ConnectionFromArray(arrayConnectionTestLetters, args)
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, connection result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:43,代码来源:array_connection_test.go

示例6: TestConnectionFromArray_HandlesCursorEdgeCases_ReturnsNoElementsIfFirstIsZero

func TestConnectionFromArray_HandlesCursorEdgeCases_ReturnsNoElementsIfFirstIsZero(t *testing.T) {
	filter := map[string]interface{}{
		"first": 0,
	}
	args := relay.NewConnectionArguments(filter)

	expected := &relay.Connection{
		Edges: []*relay.Edge{},
		PageInfo: relay.PageInfo{
			HasPreviousPage: false,
			HasNextPage:     true,
		},
	}

	result := relay.ConnectionFromArray(arrayConnectionTestLetters, args)
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, connection result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:19,代码来源:array_connection_test.go

示例7: TestConnectionFromArray_HandlesBasicSlicing_ReturnsAllElementsWithoutFilters

func TestConnectionFromArray_HandlesBasicSlicing_ReturnsAllElementsWithoutFilters(t *testing.T) {
	args := relay.NewConnectionArguments(nil)

	expected := &relay.Connection{
		Edges: []*relay.Edge{
			&relay.Edge{
				Node:   "A",
				Cursor: "YXJyYXljb25uZWN0aW9uOjA=",
			},
			&relay.Edge{
				Node:   "B",
				Cursor: "YXJyYXljb25uZWN0aW9uOjE=",
			},
			&relay.Edge{
				Node:   "C",
				Cursor: "YXJyYXljb25uZWN0aW9uOjI=",
			},
			&relay.Edge{
				Node:   "D",
				Cursor: "YXJyYXljb25uZWN0aW9uOjM=",
			},
			&relay.Edge{
				Node:   "E",
				Cursor: "YXJyYXljb25uZWN0aW9uOjQ=",
			},
		},
		PageInfo: relay.PageInfo{
			StartCursor:     "YXJyYXljb25uZWN0aW9uOjA=",
			EndCursor:       "YXJyYXljb25uZWN0aW9uOjQ=",
			HasPreviousPage: false,
			HasNextPage:     false,
		},
	}

	result := relay.ConnectionFromArray(arrayConnectionTestLetters, args)
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, connection result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:39,代码来源:array_connection_test.go

示例8: TestConnectionFromArray_HandlesBasicSlicing_RespectsASmallerFirst

func TestConnectionFromArray_HandlesBasicSlicing_RespectsASmallerFirst(t *testing.T) {
	// Create connection arguments from map[string]interface{},
	// which you usually get from types.GQLParams.Args
	filter := map[string]interface{}{
		"first": 2,
	}
	args := relay.NewConnectionArguments(filter)

	// Alternatively, you can create connection arg the following way.
	// args := relay.NewConnectionArguments(filter)
	// args.First = 2

	expected := &relay.Connection{
		Edges: []*relay.Edge{
			&relay.Edge{
				Node:   "A",
				Cursor: "YXJyYXljb25uZWN0aW9uOjA=",
			},
			&relay.Edge{
				Node:   "B",
				Cursor: "YXJyYXljb25uZWN0aW9uOjE=",
			},
		},
		PageInfo: relay.PageInfo{
			StartCursor:     "YXJyYXljb25uZWN0aW9uOjA=",
			EndCursor:       "YXJyYXljb25uZWN0aW9uOjE=",
			HasPreviousPage: false,
			HasNextPage:     true,
		},
	}

	result := relay.ConnectionFromArray(arrayConnectionTestLetters, args)
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, connection result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:36,代码来源:array_connection_test.go

示例9: init


//.........这里部分代码省略.........
	 *     cursor: String!
	 *     node: Ship
	 *   }
	 */
	shipConnectionDefinition := relay.ConnectionDefinitions(relay.ConnectionConfig{
		Name:     "Ship",
		NodeType: shipType,
	})

	/**
	 * We define our faction type, which implements the node interface.
	 *
	 * This implements the following type system shorthand:
	 *   type Faction : Node {
	 *     id: String!
	 *     name: String
	 *     ships: ShipConnection
	 *   }
	 */
	factionType = graphql.NewObject(graphql.ObjectConfig{
		Name:        "Faction",
		Description: "A faction in the Star Wars saga",
		Fields: graphql.Fields{
			"id": relay.GlobalIDField("Faction", nil),
			"name": &graphql.Field{
				Type:        graphql.String,
				Description: "The name of the faction.",
			},
			"ships": &graphql.Field{
				Type: shipConnectionDefinition.ConnectionType,
				Args: relay.ConnectionArgs,
				Resolve: func(p graphql.ResolveParams) (interface{}, error) {
					// convert args map[string]interface into ConnectionArguments
					args := relay.NewConnectionArguments(p.Args)

					// get ship objects from current faction
					ships := []interface{}{}
					if faction, ok := p.Source.(*Faction); ok {
						for _, shipId := range faction.Ships {
							ships = append(ships, GetShip(shipId))
						}
					}
					// let relay library figure out the result, given
					// - the list of ships for this faction
					// - and the filter arguments (i.e. first, last, after, before)
					return relay.ConnectionFromArray(ships, args), nil
				},
			},
		},
		Interfaces: []*graphql.Interface{
			nodeDefinitions.NodeInterface,
		},
	})

	/**
	 * This is the type that will be the root of our query, and the
	 * entry point into our schema.
	 *
	 * This implements the following type system shorthand:
	 *   type Query {
	 *     rebels: Faction
	 *     empire: Faction
	 *     node(id: String!): Node
	 *   }
	 */
	queryType := graphql.NewObject(graphql.ObjectConfig{
开发者ID:housinganywhere,项目名称:relay,代码行数:67,代码来源:schema.go

示例10: init

func init() {
	connectionTestUserType = graphql.NewObject(graphql.ObjectConfig{
		Name: "User",
		Fields: graphql.Fields{
			"name": &graphql.Field{
				Type: graphql.String,
			},
			// re-define `friends` field later because `connectionTestUserType` has `connectionTestConnectionDef` has `connectionTestUserType` (cyclic-reference)
			"friends": &graphql.Field{},
		},
	})

	connectionTestConnectionDef = relay.ConnectionDefinitions(relay.ConnectionConfig{
		Name:     "Friend",
		NodeType: connectionTestUserType,
		EdgeFields: graphql.Fields{
			"friendshipTime": &graphql.Field{
				Type: graphql.String,
				Resolve: func(p graphql.ResolveParams) (interface{}, error) {
					return "Yesterday", nil
				},
			},
		},
		ConnectionFields: graphql.Fields{
			"totalCount": &graphql.Field{
				Type: graphql.Int,
				Resolve: func(p graphql.ResolveParams) (interface{}, error) {
					return len(connectionTestAllUsers), nil
				},
			},
		},
	})

	// define `friends` field here after getting connection definition
	connectionTestUserType.AddFieldConfig("friends", &graphql.Field{
		Type: connectionTestConnectionDef.ConnectionType,
		Args: relay.ConnectionArgs,
		Resolve: func(p graphql.ResolveParams) (interface{}, error) {
			arg := relay.NewConnectionArguments(p.Args)
			res := relay.ConnectionFromArray(connectionTestAllUsers, arg)
			return res, nil
		},
	})

	connectionTestQueryType = graphql.NewObject(graphql.ObjectConfig{
		Name: "Query",
		Fields: graphql.Fields{
			"user": &graphql.Field{
				Type: connectionTestUserType,
				Resolve: func(p graphql.ResolveParams) (interface{}, error) {
					return connectionTestAllUsers[0], nil
				},
			},
		},
	})
	var err error
	connectionTestSchema, err = graphql.NewSchema(graphql.SchemaConfig{
		Query: connectionTestQueryType,
	})
	if err != nil {
		panic(err)
	}

}
开发者ID:housinganywhere,项目名称:relay,代码行数:64,代码来源:connection_test.go


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