lionixevolve/GraphQLSuiteCRM

How to pass custom arguments in custom module queries?

Closed this issue · 3 comments

Hello,

I have create custom module queries and and mutations and its working fine. now i need to filter query based on different arguments. As per your documentations LitsType file is used for query.

I have make custom TaskListType.php file for query list of tasks and its working fine.

// namespace SuiteCRM\Schema;

use Youshido\GraphQL\Type\NonNullType;
use Youshido\GraphQL\Type\ListType\AbstractListType;
use Youshido\GraphQL\Type\TypeMap ;
use Youshido\GraphQL\Execution\ResolveInfo;

require_once 'NoteType.php';

if (!defined('sugarEntry')) {
    define('sugarEntry', true);
}

class TasksListType extends AbstractListType
{
    public function getItemType()
    {
        return new TaskType();
    }

    public function build($config)
    {
        foreach (argsHelper::entityArgsHelper('Tasks', true) as $field => $type) {
            $config->addField($field, $type);
        
    }
    public function resolve($value = null, $args = [], $info = null)
    {
        require_once 'ListHelper.php';
        $list=ListHelper('Tasks',$value  , $args , $info );
        $resultArray = [];

        if (is_array($list['list']) && !empty($list['list'])) {
            if ($list['list'][0]->ACLAccess('list')) {
                foreach ($list['list'] as $item) {
                    $resultArray[] = TaskType::resolve(null, ['id' => $item->id], $info);
                }
            } else {
                //no access
                error_log('no access');
            }
            return empty($resultArray)? null :$resultArray;
        } else {
            return null;
        }
    }
}

Now I want to used same method for tasklist query but add different arguments like tasklist based on start date,end date, developer wise tasks etc,

Would you please provide proper documentations or example how to add custom arguments in query.

Thanks

If you created the fields using Studio then nothing else should be done.

This section

public function build($config)
    {
        foreach (argsHelper::entityArgsHelper('Tasks', true) as $field => $type) {
            $config->addField($field, $type);
      }   
    }

Will go through the module available fields and add them to the valid arguments.

So if you added a field named mycustomfield_c you can query the tasks module using

tasks( mycustomfield_c: "123"){
name
}

it will just work no need for anything else

In the case where you need a range, there are 2 automatically created arguments, start_range_NAMEOFTHE FIELD and end_rage_NAMEOFTHEFIELD.
For this example start_range_mycustomfield_c and end_range_mycustomfield_c will be valid arguments to query.

Hello,
Thanks for quick response. I have create custom module using module builder(I have not used studio to create custom modules)

So would you please provide example for custom module using module builder.

also I need custom module multiple mutations example. I have create custom module mutations and its working fine (Crud operations) but I want to add more mutations based on conditions, Would you please provide us example of how to define multiple mutations for same modules.

Thanks