graphql icon indicating copy to clipboard operation
graphql copied to clipboard

Array of Input / Mutation

Open ibadaboom opened this issue 1 year ago • 1 comments

Hello,

I got a question. I tried since hours to achieve to following:

Let's assume, we got an Object called User.

input User {
    id       int
    name string
}

What I want to get is the possibility. to bind "User" to an array like [User] as an input and also have User available as Object, Comming from node.js that was possible. But how this will work with your lib? Is this even possible? I Can only add 1 Input-Type of this name, resolving either as list or as object, but not both, because the name "UserInput" was already registered.

Like this: (This is just how I would do it in node.js)

mutation saveUser has inputObject of type User returning Bool
saveUser(input: User): Boolean
and mutation saveUsers has inputObject of type []User returning Bool
saveUsers(input: [User]): Boolean

Some go-code:

var UserIdInput = graphql.NewInputObject(graphql.InputObjectConfig{
	Name: "UserInput",
	Fields: graphql.InputObjectConfigFieldMap{
		"id": &graphql.InputObjectFieldConfig{
			Type: graphql.NewNonNull(graphql.Int),
		},
		"name": &graphql.InputObjectFieldConfig{
			Type: graphql.NewNonNull(graphql.String),
		},
	},
})

var USERINPUT = map[string]graphql.Input{
	"UserInput": UserInput,
	// I know I can do: graphql.newList(UserInput), but I want both be possible for that inputtype
}

ibadaboom avatar Jul 26 '22 22:07 ibadaboom

I think the only way you can achieve this with this package is to use a custom scalar type for UserInput and use the serialize/parsevalue methods to perform the appropriate validation

bhoriuchi avatar Jul 29 '22 14:07 bhoriuchi