This is a Noob question, is it possible to have a list or array as an argument?
{
somfunc(value : ["a","b","c"]) {
value
}
}
I've tried the above, and if it's possible the syntax is clearly wrong (and the schema). What I really want is a tokenized string as the argument and then process it to eventually return the result. I don't want to do the tokenization in the resolver since it's already been done.
Hi, @jloveric. I do it this way:
class Query(ObjectType):
some_func = Field(SomeObjectType, args={'value': graphene.List(graphene.String)})
This is real-world example of how to use lists/arrays as input values: Basically the same behavior of the node field, but get a list of Relay nodes for a list of Relay IDs:
import graphene
from graphene import relay
class Query(graphene.ObjectType):
node = relay.Node.Field(required=True)
nodes = graphene.List(relay.Node, required=True, ids=graphene.List(graphene.ID))
def resolve_nodes(self, info, ids=None):
if ids:
return [
relay.Node.get_node_from_global_id(info, node_id)
for node_id in ids
]
return []
I just did something very similar, but with a list of global IDs
If you need make a filter with multiples choices, you can use GlobalIDMultipleChoiceFilter class..
This filter receive a list of GlobalIds
@jloveric looks like your question has been answered so I'm going to close this issue. Thanks for the help everyone!
Most helpful comment
Hi, @jloveric. I do it this way: