Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create a Mutation with a List of (something) as argument #6

Closed
mrbarletta opened this issue Jun 13, 2016 · 2 comments
Closed

Comments

@mrbarletta
Copy link
Contributor

Lets say I have a mutation like this

mutation
{createPost(
  title: 'Copa America', 
  description: ' Latest results ',
  authors: [  
     {name: 'Maradona', email: 'maradona@gmail.com' } ,
     {name: 'Messi', email: 'messi@gmail.com' } ]  
)}

How Do I handle this scenario? -

I tried the author ListType( new AuthorType()) ?

ListType is not iterating each AuthorType sent on the request so its failing with Not valid Type....

ResolveValidator line

if (!$argumentType->isValidValue($argumentType->parseValue($argument->getValue()->getValue()))) {

Is receiving the entire array sent and not a single iteration..

I guess we need a InputListType ? or I am missing something

@viniychuk
Copy link
Member

Ok, so the thing here is that your AuthorType should also be an InputType e.g. extended from AbstractInputObjectType. Details in Gitter :)

@viniychuk
Copy link
Member

And example for future references.

$config->getMutation()->addFields([
            'createProperty' => [
                'type' => new PropertyType(),
                'args' => [
                    'title' => new StringType(),
                    'tenants' => new ListType(new InputTenantType()),
                ],
                'resolve' => function($value, $args, $info) {
                    // do your insert
                    return [];
                }
            ]
        ]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants