markhuot / craftql

A drop-in GraphQL server for Craft CMS
Other
319 stars 53 forks source link

testCategoriesMutation fails with error #287

Open ashtonlance opened 5 years ago

ashtonlance commented 5 years ago

Been banging my head trying to figure this one out. Ended up running the test and it failed with the same error I was getting in IDE.

"error": "A non well formed numeric value encountered"

PHP 7.3 Craft CMS 3.1.32.1

dstrunk commented 5 years ago

@ashtonlance can you verify that the variable being passed is an integer instead of a string? what exactly is being passed … also what are you trying to do?

ashtonlance commented 5 years ago

@dstrunk Thanks for getting back to me. Basically I'm trying to add a category to a Categories relationship field on an entry type called Projects.

Per MutationTest.php -- an object should be passed to the mutation

public function testMultiSelectMutation(): void
    {
        $input = 'mutation { story: upsertStories(title:"Multi Select Test'.date('U').'", socialLinksTwo:[fb, tw]) { id, socialLinksTwo } }';

        $result = $this->execute($input);

        $this->assertEquals('["fb","tw"]', json_encode(@$result['data']['story']['socialLinksTwo']));
    }

My code reads as:

mutation addProject($title: String!, $totalHours: Int!, $selectedCat: [CategoryCategoryInput]!)
    {
        upsertProjects(
            title: $title
            projectName: $title
            totalHours: $totalHours
            category: $selectedCat

        ) {
        id
        title
        totalHours
    }
}

With $selectedCat being an object looking like this [{id: 48}] -- 48 is the id of the category I want to assign to the entry.

ashtonlance commented 5 years ago

@markhuot @dstrunk Any ideas here?

ashtonlance commented 5 years ago

Fixed in #301

svale commented 4 years ago

Thanks @ashtonlance, #301 saved my morning!