Skip to content

Array of Input / Mutation #640

@ibadaboom

Description

@ibadaboom

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions