Skip to content

Commit

Permalink
Added NewConnectionArgs()
Browse files Browse the repository at this point in the history
Example:
```go
userType = types.NewGraphQLObjectType(types.GraphQLObjectTypeConfig{
		Name: "User",
		Fields: types.GraphQLFieldConfigMap{
			"id": gqlrelay.GlobalIdField("User", nil),
			"todos": &types.GraphQLFieldConfig{
				Type: todosConnection.ConnectionType,
				// Injects input fields into Relay connection args
				Args: gqlrelay.NewConnectionArgs(types.GraphQLFieldConfigArgumentMap{
					"status": &types.GraphQLArgumentConfig{
						Type:         types.GraphQLString,
						DefaultValue: "any",
					},
				}),
				Resolve: func(p types.GQLFRParams) interface{} {
					....
				},
			},
			...
		},
		Interfaces: []*types.GraphQLInterfaceType{nodeDefinitions.NodeInterface},
	})
```
  • Loading branch information
sogko committed Oct 3, 2015
1 parent 71b4052 commit afc80af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
13 changes: 12 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gqlrelay
import "github.com/chris-ramon/graphql-go/types"

/*
Returns a GraphQLFieldConfigArgumentMap appropriate to include
Returns a GraphQLFieldConfigArgumentMap appropriate to include
on a field whose return type is a connection type.
*/
var ConnectionArgs = types.GraphQLFieldConfigArgumentMap{
Expand All @@ -21,13 +21,24 @@ var ConnectionArgs = types.GraphQLFieldConfigArgumentMap{
},
}

func NewConnectionArgs(configMap types.GraphQLFieldConfigArgumentMap) types.GraphQLFieldConfigArgumentMap {
for fieldName, argConfig := range ConnectionArgs {
configMap[fieldName] = argConfig
}
return configMap
}

type ConnectionConfig struct {
Name string `json:"name"`
NodeType *types.GraphQLObjectType `json:"nodeType"`
EdgeFields types.GraphQLFieldConfigMap `json:"edgeFields"`
ConnectionFields types.GraphQLFieldConfigMap `json:"connectionFields"`
}

type EdgeType struct {
Node interface{} `json:"node"`
Cursor ConnectionCursor `json:"cursor"`
}
type GraphQLConnectionDefinitions struct {
EdgeType *types.GraphQLObjectType `json:"edgeType"`
ConnectionType *types.GraphQLObjectType `json:"connectionType"`
Expand Down
6 changes: 6 additions & 0 deletions mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ provided MutationConfig.
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),
}
Expand Down

0 comments on commit afc80af

Please sign in to comment.