├── .gitignore ├── graphql ├── GraphiQL │ ├── screenshot.png │ ├── index-js.html │ ├── index.html │ ├── cookiejar.js │ └── fetch.min.js ├── Schema │ ├── CallInputType.php │ ├── MeetingInputType.php │ ├── CaseupdatesInputType.php │ ├── RelatedBeanInputType.php │ ├── CaseInputType.php │ ├── NoteInputType.php │ ├── TaskInputType.php │ ├── CallsListType.php │ ├── CampaignInputType.php │ ├── AclRolesListType.php │ ├── QuotesListType.php │ ├── CampaignsListType.php │ ├── CasesListType.php │ ├── NotesListType.php │ ├── TasksListType.php │ ├── UsersListType.php │ ├── MeetingsListType.php │ ├── AccountsListType.php │ ├── ContactsListType.php │ ├── CaseupdatesListType.php │ ├── OpportunitiesListType.php │ ├── AccountInputType.php │ ├── ContactInputType.php │ ├── OpportunityInputType.php │ ├── AclRoleType.php │ ├── ListHelper.php │ ├── crmHelper.php │ ├── UserType.php │ ├── CaseupdatesType.php │ ├── QuoteType.php │ ├── TaskType.php │ ├── ContactType.php │ ├── MeetingType.php │ ├── CampaignType.php │ ├── CaseType.php │ ├── OpportunityType.php │ ├── argsHelper.php │ ├── CallType.php │ ├── NoteType.php │ └── AccountType.php └── schema-bootstrap.php ├── composer.json └── graphqlQueryTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/* 2 | -------------------------------------------------------------------------------- /graphql/GraphiQL/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lionixevolve/GraphQLSuiteCRM/HEAD/graphql/GraphiQL/screenshot.png -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lionixevolve/graphqlsuitecrm", 3 | "description": "GraphQL support for SuiteCRM / SugarCRM CE", 4 | "type": "library", 5 | "license": "AGPL-3.0-or-later", 6 | "authors": [{ 7 | "name": "Matías Barletta - Lionix Evolve", 8 | "email": "mrbarletta@lionix.com", 9 | "homepage": "https://www.lionix.com" 10 | }], 11 | "minimum-stability": "dev", 12 | "autoload": { 13 | 14 | }, 15 | "require": { 16 | "slim/slim": "~3.12", 17 | "gargron/fileupload": "~1.4.0", 18 | "youshido/graphql": "^v1.5", 19 | "monolog/monolog": "^1.23" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /graphql/Schema/CallInputType.php: -------------------------------------------------------------------------------- 1 | $type) { 13 | $config->addField($field, $type); 14 | } 15 | } 16 | 17 | public function resolve($value = null, $args = [], $type = null) // implementing resolve function 18 | { 19 | //We use the crm Helper to create/save the Bean 20 | return crmHelper::saveBean('Calls', 'Call', $args); 21 | } 22 | 23 | public function getName() 24 | { 25 | return 'Call'; // important to use the real name here, it will be used later in the Schema 26 | } 27 | public function getOutputType() 28 | { 29 | return 'Call'; // important to use the real name here, it will be used later in the Schema 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /graphql/Schema/MeetingInputType.php: -------------------------------------------------------------------------------- 1 | $type) { 13 | $config->addField($field, $type); 14 | } 15 | } 16 | 17 | public function resolve($value = null, $args = [], $type = null) // implementing resolve function 18 | { 19 | //We use the crm Helper to create/save the Bean 20 | return crmHelper::saveBean('Meetings', 'Meeting', $args); 21 | } 22 | 23 | public function getName() 24 | { 25 | return 'Meeting'; // important to use the real name here, it will be used later in the Schema 26 | } 27 | public function getOutputType() 28 | { 29 | return 'Meeting'; // important to use the real name here, it will be used later in the Schema 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /graphql/Schema/CaseupdatesInputType.php: -------------------------------------------------------------------------------- 1 | $type) { 13 | $config->addField($field, $type); 14 | } 15 | } 16 | 17 | public function resolve($value = null, $args = [], $type = null) // implementing resolve function 18 | { 19 | //We use the crm Helper to create/save the Bean 20 | return crmHelper::saveBean('AopCaseUpdates', 'AOP_Case_Updates', $args); 21 | } 22 | 23 | public function getName() 24 | { 25 | return 'AOP_Case_Updates'; // important to use the real name here, it will be used later in the Schema 26 | } 27 | public function getOutputType() 28 | { 29 | return 'AOP_Case_Updates'; // important to use the real name here, it will be used later in the Schema 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /graphql/Schema/RelatedBeanInputType.php: -------------------------------------------------------------------------------- 1 | addField('module', new StringType()); 13 | $config->addField('id', new StringType()); 14 | $config->addField('deleted', new StringType()); 15 | } 16 | public function resolve($value = null, $args = [], $type = null) // implementing resolve function 17 | { 18 | //We use the crm Helper to create/save the Bean 19 | // return crmHelper::saveBean('Calls', 'Call', $args); 20 | } 21 | public function getName() 22 | { 23 | return 'RelatedBeanInputType'; // important to use the real name here, it will be used later in the Schema 24 | } 25 | // public function getOutputType() 26 | // { 27 | // return new StringType(); // important to use the real name here, it will be used later in the Schema 28 | // } 29 | } 30 | -------------------------------------------------------------------------------- /graphql/Schema/CaseInputType.php: -------------------------------------------------------------------------------- 1 | $type) { 13 | $config->addField($field, $type); 14 | } 15 | $config->addField('related_beans', new ListType(new RelatedBeanInputType())); 16 | } 17 | 18 | public function resolve($value = null, $args = [], $type = null) // implementing resolve function 19 | { 20 | //We use the crm Helper to create/save the Bean 21 | return crmHelper::saveBean('Cases', 'aCase', $args); 22 | } 23 | 24 | public function getName() 25 | { 26 | return 'Case'; // important to use the real name here, it will be used later in the Schema 27 | } 28 | public function getOutputType() 29 | { 30 | return 'Case'; // important to use the real name here, it will be used later in the Schema 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /graphql/Schema/NoteInputType.php: -------------------------------------------------------------------------------- 1 | $type) { 13 | $config->addField($field, $type); 14 | } 15 | $config->addField('related_beans', new ListType(new RelatedBeanInputType())); 16 | } 17 | 18 | public function resolve($value = null, $args = [], $type = null) // implementing resolve function 19 | { 20 | //We use the crm Helper to create/save the Bean 21 | return crmHelper::saveBean('Notes', 'Note', $args); 22 | } 23 | 24 | public function getName() 25 | { 26 | return 'Note'; // important to use the real name here, it will be used later in the Schema 27 | } 28 | public function getOutputType() 29 | { 30 | return 'Note'; // important to use the real name here, it will be used later in the Schema 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /graphql/Schema/TaskInputType.php: -------------------------------------------------------------------------------- 1 | $type) { 13 | $config->addField($field, $type); 14 | } 15 | $config->addField('related_beans', new ListType(new RelatedBeanInputType())); 16 | } 17 | 18 | public function resolve($value = null, $args = [], $type = null) // implementing resolve function 19 | { 20 | //We use the crm Helper to create/save the Bean 21 | return crmHelper::saveBean('Tasks', 'Task', $args); 22 | } 23 | 24 | public function getName() 25 | { 26 | return 'Task'; // important to use the real name here, it will be used later in the Schema 27 | } 28 | public function getOutputType() 29 | { 30 | return 'Task'; // important to use the real name here, it will be used later in the Schema 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /graphql/Schema/CallsListType.php: -------------------------------------------------------------------------------- 1 | ACLAccess('list')) { 30 | foreach ($list['list'] as $item) { 31 | $resultArray[] = CallType::resolve(null, ['id' => $item->id], $info); 32 | } 33 | } else { 34 | error_log('no access'); 35 | } 36 | return empty($resultArray)? null :$resultArray; 37 | } else { 38 | return null; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /graphql/Schema/CampaignInputType.php: -------------------------------------------------------------------------------- 1 | $type) { 13 | $config->addField($field, $type); 14 | } 15 | $config->addField('related_beans', new ListType(new RelatedBeanInputType())); 16 | } 17 | 18 | public function resolve($value = null, $args = [], $type = null) // implementing resolve function 19 | { 20 | //We use the crm Helper to create/save the Bean 21 | return crmHelper::saveBean('Campaigns', 'Campaign', $args); 22 | } 23 | 24 | public function getName() 25 | { 26 | return 'Campaign'; // important to use the real name here, it will be used later in the Schema 27 | } 28 | public function getOutputType() 29 | { 30 | return 'Campaign'; // important to use the real name here, it will be used later in the Schema 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /graphql/Schema/AclRolesListType.php: -------------------------------------------------------------------------------- 1 | ACLAccess('list')) { 28 | foreach ($list['list'] as $item) { 29 | $resultArray[] = AclRoleType::resolve(null, ['id' => $item->id], $info); 30 | } 31 | } else { 32 | //no access 33 | error_log('no access'); 34 | } 35 | return empty($resultArray)? null :$resultArray; 36 | } else { 37 | return null; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /graphql/Schema/QuotesListType.php: -------------------------------------------------------------------------------- 1 | $type){ 23 | $config->addField($field, $type); 24 | } 25 | } 26 | 27 | public function resolve($value = null, $args = [], $info = null) 28 | { 29 | require_once 'ListHelper.php'; 30 | $list=ListHelper('AOS_Quotes',$value , $args , $info ); 31 | $resultArray = []; 32 | 33 | if (is_array($list['list']) && !empty($list['list'])) { 34 | if ($list['list'][0]->ACLAccess('list')) { 35 | foreach ($list['list'] as $item) { 36 | $resultArray[] = QuoteType::resolve(null, ['id' => $item->id], $info); 37 | } 38 | } else { 39 | //no access 40 | error_log('no access'); 41 | } 42 | return empty($resultArray)? null :$resultArray; 43 | } else { 44 | return null; 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /graphql/Schema/CampaignsListType.php: -------------------------------------------------------------------------------- 1 | $type) { 25 | $config->addField($field, $type); 26 | } 27 | } 28 | 29 | public function resolve($value = null, $args = [], $info = null) 30 | { 31 | require_once 'ListHelper.php'; 32 | $list=ListHelper('Campaigns', $value, $args, $info); 33 | $resultArray = []; 34 | 35 | if (is_array($list['list']) && !empty($list['list'])) { 36 | if ($list['list'][0]->ACLAccess('list')) { 37 | foreach ($list['list'] as $item) { 38 | $resultArray[] = CampaignType::resolve(null, ['id' => $item->id], $info); 39 | } 40 | } else { 41 | error_log('no access'); 42 | } 43 | return empty($resultArray)? null :$resultArray; 44 | } else { 45 | return null; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /graphql/Schema/CasesListType.php: -------------------------------------------------------------------------------- 1 | $type) { 25 | $config->addField($field, $type); 26 | } 27 | } 28 | public function resolve($value = null, $args = [], $info = null) 29 | { 30 | require_once 'ListHelper.php'; 31 | $list=ListHelper('Cases', $value, $args, $info); 32 | $resultArray = []; 33 | 34 | if (is_array($list['list']) && !empty($list['list'])) { 35 | if ($list['list'][0]->ACLAccess('list')) { 36 | foreach ($list['list'] as $item) { 37 | $resultArray[] = CaseType::resolve(null, ['id' => $item->id], $info); 38 | } 39 | } else { 40 | //no access 41 | error_log('no access'); 42 | } 43 | return empty($resultArray)? null :$resultArray; 44 | } else { 45 | return null; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /graphql/Schema/NotesListType.php: -------------------------------------------------------------------------------- 1 | $type) { 25 | $config->addField($field, $type); 26 | } 27 | } 28 | public function resolve($value = null, $args = [], $info = null) 29 | { 30 | require_once 'ListHelper.php'; 31 | $list=ListHelper('Notes', $value, $args, $info); 32 | $resultArray = []; 33 | 34 | if (is_array($list['list']) && !empty($list['list'])) { 35 | if ($list['list'][0]->ACLAccess('list')) { 36 | foreach ($list['list'] as $item) { 37 | $resultArray[] = NoteType::resolve(null, ['id' => $item->id], $info); 38 | } 39 | } else { 40 | //no access 41 | error_log('no access'); 42 | } 43 | return empty($resultArray)? null :$resultArray; 44 | } else { 45 | return null; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /graphql/Schema/TasksListType.php: -------------------------------------------------------------------------------- 1 | $type) { 25 | $config->addField($field, $type); 26 | } 27 | } 28 | public function resolve($value = null, $args = [], $info = null) 29 | { 30 | require_once 'ListHelper.php'; 31 | $list=ListHelper('Tasks',$value , $args , $info ); 32 | $resultArray = []; 33 | 34 | if (is_array($list['list']) && !empty($list['list'])) { 35 | if ($list['list'][0]->ACLAccess('list')) { 36 | foreach ($list['list'] as $item) { 37 | $resultArray[] = TaskType::resolve(null, ['id' => $item->id], $info); 38 | } 39 | } else { 40 | //no access 41 | error_log('no access'); 42 | } 43 | return empty($resultArray)? null :$resultArray; 44 | } else { 45 | return null; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /graphql/Schema/UsersListType.php: -------------------------------------------------------------------------------- 1 | $type) { 24 | $config->addField($field, $type); 25 | } 26 | } 27 | 28 | public function resolve($value = null, $args = [], $info = null) 29 | { 30 | require_once 'ListHelper.php'; 31 | $list=ListHelper('Users',$value , $args , $info ); 32 | $resultArray = []; 33 | 34 | if (is_array($list['list']) && !empty($list['list'])) { 35 | if ($list['list'][0]->ACLAccess('list')) { 36 | foreach ($list['list'] as $item) { 37 | $resultArray[] = UserType::resolve(null, ['id' => $item->id], $info); 38 | } 39 | } else { 40 | //no access 41 | error_log('no access'); 42 | } 43 | return empty($resultArray)? null :$resultArray; 44 | } else { 45 | return null; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /graphql/Schema/MeetingsListType.php: -------------------------------------------------------------------------------- 1 | $type) { 25 | $config->addField($field, $type); 26 | } 27 | } 28 | public function resolve($value = null, $args = [], $info = null) 29 | { 30 | require_once 'ListHelper.php'; 31 | $list=ListHelper('Meetings', $value, $args, $info); 32 | $resultArray = []; 33 | 34 | if (is_array($list['list']) && !empty($list['list'])) { 35 | if ($list['list'][0]->ACLAccess('list')) { 36 | foreach ($list['list'] as $item) { 37 | $resultArray[] = MeetingType::resolve(null, ['id' => $item->id], $info); 38 | } 39 | } else { 40 | //no access 41 | error_log('no access'); 42 | } 43 | return empty($resultArray)? null :$resultArray; 44 | } else { 45 | return null; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /graphql/Schema/AccountsListType.php: -------------------------------------------------------------------------------- 1 | $type) { 23 | $config->addField($field, $type); 24 | } 25 | } 26 | 27 | public function resolve($value = null, $args = [], Youshido\GraphQL\Execution\ResolveInfo $info = null) 28 | { 29 | require_once 'ListHelper.php'; 30 | $list=ListHelper('Accounts', $value, $args, $info); 31 | $resultArray = []; 32 | 33 | if (is_array($list['list']) && !empty($list['list'])) { 34 | if ($list['list'][0]->ACLAccess('list')) { 35 | foreach ($list['list'] as $item) { 36 | $resultArray[] = AccountType::resolve(null, ['id' => $item->id], $info); 37 | } 38 | } else { 39 | //no access 40 | error_log('no access'); 41 | } 42 | return empty($resultArray)? null :$resultArray; 43 | } else { 44 | return null; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /graphql/Schema/ContactsListType.php: -------------------------------------------------------------------------------- 1 | $type) { 25 | $config->addField($field, $type); 26 | } 27 | } 28 | 29 | public function resolve($value = null, $args = [], $info = null) 30 | { 31 | require_once 'ListHelper.php'; 32 | $list = ListHelper('Contacts', $value, $args, $info); 33 | $resultArray = []; 34 | 35 | if (is_array($list['list']) && !empty($list['list'])) { 36 | if ($list['list'][0]->ACLAccess('list')) { 37 | foreach ($list['list'] as $item) { 38 | $resultArray[] = ContactType::resolve(null, ['id' => $item->id], $info); 39 | } 40 | } else { 41 | //no access 42 | error_log('no access'); 43 | } 44 | return empty($resultArray) ? null : $resultArray; 45 | } else { 46 | return null; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /graphql/Schema/CaseupdatesListType.php: -------------------------------------------------------------------------------- 1 | $type) { 25 | $config->addField($field, $type); 26 | } 27 | } 28 | public function resolve($value = null, $args = [], $info = null) 29 | { 30 | require_once 'ListHelper.php'; 31 | $list=ListHelper('AOP_Case_Updates',$value , $args , $info ); 32 | $resultArray = []; 33 | 34 | if (is_array($list['list']) && !empty($list['list'])) { 35 | if ($list['list'][0]->ACLAccess('list')) { 36 | foreach ($list['list'] as $item) { 37 | $resultArray[] = CaseupdatesType::resolve(null, ['id' => $item->id], $info); 38 | } 39 | } else { 40 | //no access 41 | error_log('no access'); 42 | } 43 | return empty($resultArray)? null :$resultArray; 44 | } else { 45 | return null; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /graphql/Schema/OpportunitiesListType.php: -------------------------------------------------------------------------------- 1 | $type) { 25 | $config->addField($field, $type); 26 | } 27 | } 28 | 29 | public function resolve($value = null, $args = [], $info = null) 30 | { 31 | require_once 'ListHelper.php'; 32 | $list=ListHelper('Opportunities', $value, $args, $info); 33 | $resultArray = []; 34 | 35 | if (is_array($list['list']) && !empty($list['list'])) { 36 | if ($list['list'][0]->ACLAccess('list')) { 37 | foreach ($list['list'] as $item) { 38 | $resultArray[] = OpportunityType::resolve(null, ['id' => $item->id], $info); 39 | } 40 | } else { 41 | //no access 42 | error_log('no access'); 43 | } 44 | return empty($resultArray)? null :$resultArray; 45 | } else { 46 | return null; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /graphql/Schema/AccountInputType.php: -------------------------------------------------------------------------------- 1 | $type) { 10 | $config->addField($field, $type); 11 | } 12 | $config->addField('created_user_details', new UserType(), [ 13 | 'resolve' => function ($contact) { 14 | return UserType::resolve(null, ['id' => $contact['created_user_details']], null); 15 | }, 16 | ]); 17 | $config->addField('assigned_user_details', new UserType(), [ 18 | 'resolve' => function ($contact) { 19 | return UserType::resolve(null, ['id' => $contact['assigned_user_details']], null); 20 | }, 21 | ]); 22 | $config->addField('modified_user_details', new UserType(), [ 23 | 'resolve' => function ($contact) { 24 | return UserType::resolve(null, ['id' => $contact['modified_user_details']], null); 25 | }, 26 | ]); 27 | } 28 | 29 | public function resolve($value = null, $args = [], $type = null) // implementing resolve function 30 | { 31 | //We use the crm Helper to create/save the Bean 32 | return crmHelper::saveBean("Accounts","Account",$args); 33 | 34 | } 35 | public function getName() 36 | { 37 | return 'Account'; // important to use the real name here, it will be used later in the Schema 38 | } 39 | public function getOutputType() 40 | { 41 | return 'Account'; // important to use the real name here, it will be used later in the Schema 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /graphql/Schema/ContactInputType.php: -------------------------------------------------------------------------------- 1 | $type) { 13 | $config->addField($field, $type); 14 | } 15 | $config->addField('created_user_details', new UserType(), [ 16 | 'resolve' => function ($contact) { 17 | return UserType::resolve(null, ['id' => $contact['created_user_details']], null); 18 | }, 19 | ]); 20 | $config->addField('assigned_user_details', new UserType(), [ 21 | 'resolve' => function ($contact) { 22 | return UserType::resolve(null, ['id' => $contact['assigned_user_details']], null); 23 | }, 24 | ]); 25 | $config->addField('modified_user_details', new UserType(), [ 26 | 'resolve' => function ($contact) { 27 | return UserType::resolve(null, ['id' => $contact['modified_user_details']], null); 28 | }, 29 | ]); 30 | $config->addField('related_beans', new ListType(new RelatedBeanInputType())); 31 | } 32 | 33 | public function resolve($value = null, $args = [], $type = null) // implementing resolve function 34 | { 35 | //We use the crm Helper to create/save the Bean 36 | return crmHelper::saveBean("Contacts", "Contact", $args); 37 | } 38 | public function getName() 39 | { 40 | return 'Contact'; // important to use the real name here, it will be used later in the Schema 41 | } 42 | public function getOutputType() 43 | { 44 | return 'Contact'; // important to use the real name here, it will be used later in the Schema 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /graphql/Schema/OpportunityInputType.php: -------------------------------------------------------------------------------- 1 | $type) { 13 | $config->addField($field, $type); 14 | } 15 | $config->addField('created_user_details', new UserType(), [ 16 | 'resolve' => function ($contact) { 17 | return UserType::resolve(null, ['id' => $contact['created_user_details']], null); 18 | }, 19 | ]); 20 | $config->addField('assigned_user_details', new UserType(), [ 21 | 'resolve' => function ($contact) { 22 | return UserType::resolve(null, ['id' => $contact['assigned_user_details']], null); 23 | }, 24 | ]); 25 | $config->addField('modified_user_details', new UserType(), [ 26 | 'resolve' => function ($contact) { 27 | return UserType::resolve(null, ['id' => $contact['modified_user_details']], null); 28 | }, 29 | ]); 30 | $config->addField('related_beans', new ListType(new RelatedBeanInputType())); 31 | } 32 | 33 | public function resolve($value = null, $args = [], $type = null) // implementing resolve function 34 | { 35 | //We use the crm Helper to create/save the Bean 36 | return crmHelper::saveBean("Opportunities","Opportunity",$args); 37 | } 38 | public function getName() 39 | { 40 | return 'Opportunity'; // important to use the real name here, it will be used later in the Schema 41 | } 42 | public function getOutputType() 43 | { 44 | return 'Opportunity'; // important to use the real name here, it will be used later in the Schema 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /graphql/schema-bootstrap.php: -------------------------------------------------------------------------------- 1 | processPayload($payload); 85 | echo json_encode($processor->getResponseData())."\n"; 86 | -------------------------------------------------------------------------------- /graphql/GraphiQL/index-js.html: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | GraphQL Explorer JS 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | Loading... 21 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /graphql/Schema/AclRoleType.php: -------------------------------------------------------------------------------- 1 | $type){ 20 | $config->addField($field, $type); 21 | } 22 | $config->addField('users', [ 23 | 'type' => new UsersListType(), 24 | 'args' => argsHelper::entityArgsHelper('Users', true), 25 | 'resolve' => function ($value, array $args, Youshido\GraphQL\Execution\ResolveInfo $info) { 26 | if (!empty($value['users'])) { 27 | $args['id']=$value['users']; 28 | return UsersListType::resolve($value, $args, $info); 29 | } else { 30 | return null; 31 | } 32 | }, 33 | ]); 34 | } 35 | private function retrieveAclRole($id, $info){ 36 | global $sugar_config, $current_user, $beanList; 37 | $roleBean = BeanFactory::getBean('ACLRoles'); 38 | $role = $roleBean->retrieve($id); 39 | if($info!=null){ 40 | $getFieldASTList=$info->getFieldASTList(); 41 | $queryFields=[]; 42 | foreach ($getFieldASTList as $key => $value) { 43 | $queryFields[$value->getName()]=""; 44 | } 45 | } 46 | $module_arr = array(); 47 | if ($role->id && $role->ACLAccess('view')) { 48 | $all_fields = $role->column_fields; 49 | if(isset($queryFields) && array_key_exists('users',$queryFields)){ 50 | $module_arr['users'] = array(); 51 | foreach ($role->get_linked_beans('users', 'User') as $user) { 52 | $module_arr['users'][] = $user->id; 53 | } 54 | } 55 | foreach ($all_fields as $field) { 56 | if (isset($role->$field) && !is_object($role->$field)) { 57 | $role->$field = from_html($role->$field); 58 | $role->$field = preg_replace("/\r\n/", "
", $role->$field); 59 | $role->$field = preg_replace("/\n/", "
", $role->$field); 60 | $module_arr[$field] = $role->$field; 61 | } 62 | } 63 | // $roles = ACLRole::getAclRoleRoleNames($id); 64 | // if(!empty($roles)){ 65 | // //LX: TODO - create a RoleType to correctly return data 66 | // foreach ($roles as $key => $value) { 67 | // $module_arr['roles']=$value; 68 | // } 69 | // }else{ 70 | // $module_arr['roles']=""; 71 | // } 72 | 73 | return $module_arr; 74 | 75 | }else{ 76 | return null; 77 | } 78 | } 79 | 80 | public function resolve($value = null, $args = [], Youshido\GraphQL\Execution\ResolveInfo $info = null) // implementing resolve function 81 | { 82 | if (isset($args['id']) && is_array($args['id'])) { 83 | foreach ($args as $key => $roleId) { 84 | if (isset($roleId) && is_array($roleId)) { 85 | foreach ($roleId as $key => $roleIdItem) { 86 | $resultArray[] = self::retrieveAclRole($roleIdItem,$info); 87 | } 88 | } elseif (!empty($roleId)) { 89 | $resultArray[] = self::retrieveAclRole($roleId,$info); 90 | } 91 | } 92 | return $resultArray; 93 | } elseif (!empty($args['id'])) { 94 | return self::retrieveAclRole($args['id'],$info); 95 | } 96 | } 97 | 98 | 99 | public function getName() 100 | { 101 | return "AclRole"; // important to use the real name here, it will be used later in the Schema 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /graphql/GraphiQL/index.html: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 11 | 22 | 23 | 30 | 31 | 32 | 33 | 34 | 35 | 40 | 41 | 42 | 43 | 44 | 45 |
Loading...
46 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /graphql/Schema/ListHelper.php: -------------------------------------------------------------------------------- 1 | getFieldASTList(); 9 | $queryFields = []; 10 | $queryFieldsArray = []; 11 | foreach ($getFieldASTList as $key => $value) { 12 | $queryFields[$value->getName()] = ""; 13 | $queryFieldsArray[] = $value->getName(); 14 | } 15 | } 16 | $arrayKeys = array_keys($args); 17 | $moduleFields = $moduleBean->field_name_map; 18 | //we hardcode the IDS field as available to this modules 19 | $moduleFields['ids'] = "enabled"; 20 | $searchFields = array(); 21 | foreach ($moduleFields as $key => $params) { 22 | if (in_array($key, $arrayKeys)) { 23 | if (is_array($args[$key]) || substr_count($args[$key], ",") > 0) { 24 | $guessOperator = "in"; 25 | if (is_array($args[$key])) { 26 | $findValues = $args[$key]; 27 | //IDS doesn't exist in the database so we actually do a IN where to the ID field 28 | $key = 'id'; 29 | } else { 30 | $findValues = explode(",", $string = str_replace(' ', '', $args[$key])); 31 | } 32 | } else { 33 | if (substr_count($args[$key], '%') > 0) { 34 | $guessOperator = "like"; 35 | $findValues = $args[$key]; 36 | } else { 37 | $guessOperator = "="; 38 | $findValues = $args[$key]; 39 | } 40 | } 41 | $searchFields[$key] = array('query_type' => 'default', 'value' => $findValues, 'operator' => $guessOperator); 42 | } 43 | } 44 | foreach ($args as $key => $value) { 45 | if (!empty($key) && 0 === strpos($key, 'end_range_')) { 46 | $searchFields[$key] = array('query_type' => 'default', 'value' => $value, 'enable_range_search' => true, 'is_date_field' => true); 47 | } elseif (!empty($key) && 0 === strpos($key, 'start_range_')) { 48 | $searchFields[$key] = array('query_type' => 'default', 'value' => $value, 'enable_range_search' => true, 'is_date_field' => true); 49 | } 50 | } 51 | // Work around for email1 field, it cannot be used in the where clause as it an alias. 52 | if (!empty($searchFields["email1"]) && isset($moduleBean->field_defs['email1'])) { 53 | $searchFields["email_addresses.email_address"] = $searchFields["email1"]; 54 | unset($searchFields["email1"]); 55 | } 56 | $where = searchHelper::generateSearchWhere($moduleBean, $searchFields); 57 | $offset = 0; 58 | if (!empty($args['offset'])) { 59 | $offset = $args['offset']; 60 | } 61 | $list = []; 62 | $aggregateList = []; 63 | if ($moduleBean->bean_implements('ACL') && ACLController::requireOwner($moduleBean->module_dir, 'list')) { 64 | global $current_user; 65 | $owner_where = $moduleBean->getOwnerWhere($current_user->id); 66 | 67 | //rrs - because $this->getOwnerWhere() can return '' we need to be sure to check for it and 68 | //handle it properly else you could get into a situation where you are create a where stmt like 69 | //WHERE .. AND '' 70 | if (!empty($owner_where)) { 71 | if (empty($where)) { 72 | $where = $owner_where; 73 | } else { 74 | $where .= ' AND ' . $owner_where; 75 | } 76 | } 77 | } 78 | $params = array(); 79 | $params['include_custom_fields'] = true; 80 | if (!empty($args['distinct'])) { 81 | $orderBy = ""; 82 | } elseif (!empty($args['order'])) { 83 | $orderBy = $args['order']; 84 | } else { 85 | $orderBy = ""; 86 | } 87 | $query = $moduleBean->create_new_list_query($orderBy, implode(" AND ", $where), $queryFieldsArray, $params, $show_deleted = 0, '', false, null, $singleSelect = false); 88 | $resultArray = []; 89 | if (!empty($args['distinct'])) { 90 | $params["distinct"] = true; 91 | if (($key = array_search("__typename", $queryFieldsArray)) !== false) { 92 | unset($queryFieldsArray[$key]); 93 | } 94 | if (($key = array_search("id", $queryFieldsArray)) !== false) { 95 | unset($queryFieldsArray[$key]); 96 | } 97 | $query .= " GROUP BY " . implode(" , ", $queryFieldsArray); 98 | if (!empty($args['order'])) { 99 | $order_by = $moduleBean->process_order_by($args['order']); 100 | $query .= " ORDER BY " . $order_by; 101 | } else { 102 | $order_by = $moduleBean->process_order_by('name'); 103 | $query .= " ORDER BY " . $order_by; 104 | } 105 | } 106 | if (!empty($args['limit'])) { 107 | $max = $args['limit']; 108 | } else { 109 | $args['limit'] = ""; 110 | $max = -1; 111 | } 112 | if ($module == "ACLRoles") { 113 | //Otherwise fails when using a custom field in roles 114 | $GLOBALS['dictionary']['ACLRole']['custom_fields'] = false; 115 | } 116 | return $moduleBean->process_list_query($query, $offset, $args['limit'], $max, $where); 117 | } -------------------------------------------------------------------------------- /graphql/Schema/crmHelper.php: -------------------------------------------------------------------------------- 1 | id) { 12 | $current_user = new User(); 13 | $current_user->retrieve($_SESSION['user_id']); 14 | } 15 | $seed = new $class_name(); 16 | 17 | // $name_value_list=$args; 18 | foreach ($name_value_list as $name => $value) { 19 | if (is_array($value) && $value['name'] == 'id') { 20 | $seed->retrieve($value['value']); 21 | break; 22 | } elseif ($name === 'id') { 23 | $seed->retrieve($value); 24 | } 25 | } 26 | $seed->notifyonsave = false; 27 | foreach ($name_value_list as $name => $value) { 28 | if ($module_name == 'Users' && !empty($seed->id) && ($seed->id != $current_user->id) && $name == 'user_hash') { 29 | continue; 30 | } 31 | if (!empty($seed->field_name_map[$name]['sensitive'])) { 32 | continue; 33 | } 34 | if ($name == "related_bean") { 35 | $seed->new_rel_relname = $value; 36 | } 37 | if ($name == "related_beans") { 38 | $related_beans = $value; 39 | } 40 | if ($name == "related_id") { 41 | $seed->new_rel_id = $value; 42 | } 43 | if ($name == "relate_id") { 44 | $_REQUEST['relate_id'] = $value; 45 | } 46 | if ($name == "relate_to") { 47 | $_REQUEST['relate_to'] = $value; 48 | } 49 | if (!is_array($value)) { 50 | $seed->$name = $value; 51 | } elseif ($name != "related_beans") { 52 | $seed->$value['name'] = $value['value']; 53 | } 54 | } 55 | if ($seed->ACLAccess('Save')) { 56 | $seed->not_use_rel_in_req = true; 57 | 58 | if ($seed->deleted == 1) { 59 | $seed->mark_deleted($seed->id); 60 | } 61 | if (empty($seed->id)) { 62 | $seed->id = create_guid(); 63 | $seed->new_with_id = true; 64 | } 65 | if (isset($related_beans)) { 66 | foreach ($related_beans as $key => $value) { 67 | if ($class_name == "Call" && isset($value['module']) && strtolower($value['module']) == "notes") { 68 | $note = new Note(); 69 | $note->retrieve($value['id']); 70 | if (!empty($note->id)) { 71 | $note->load_relationship('calls'); 72 | if (isset($value['deleted'])) { 73 | $note->calls->delete($seed->id); 74 | } else { 75 | $note->calls->add($seed->id); 76 | } 77 | } 78 | } else { 79 | $relatedModule = strtolower($value['module']); 80 | $seed->load_relationship($relatedModule); 81 | if (isset($value['deleted'])) { 82 | $seed->$relatedModule->delete($value['id']); 83 | } else { 84 | $seed->$relatedModule->add($value['id']); 85 | } 86 | } 87 | } 88 | } 89 | $seed->save($seed->notifyonsave); 90 | return array('id' => $seed->id); 91 | } else { 92 | error_log(__METHOD__ . " ERROR SAVING - NO ACCESS"); 93 | return "ERROR SAVING"; 94 | } 95 | } 96 | 97 | public function getDefaultFieldsValues($moduleBean) 98 | { 99 | global $current_user; 100 | $all_fields = $moduleBean->column_fields; 101 | 102 | foreach ($all_fields as $field) { 103 | if (isset($moduleBean->$field) && !is_object($moduleBean->$field)) { 104 | if (($moduleBean->field_name_map[$field]['type'] == "datetime") || $moduleBean->field_name_map[$field]['type'] == "datetimecombo" || $moduleBean->field_name_map[$field]['type'] == "date") { 105 | $module_arr[$field] = $moduleBean->$field; 106 | date_default_timezone_set('UTC'); 107 | $dateField = new \DateTime($moduleBean->fetched_row[$field]); 108 | $dateFieldName = $field . "_atom"; 109 | if ($moduleBean->fetched_row[$field] == "") { 110 | $module_arr[$dateFieldName] = ""; 111 | } else { 112 | $module_arr[$dateFieldName] = $dateField->format(DATE_ATOM); 113 | } 114 | } else { 115 | //from_html is a SuiteCRM function 116 | $moduleBean->$field = from_html($moduleBean->$field); 117 | $moduleBean->$field = preg_replace("/\r\n/", '
', $moduleBean->$field); 118 | $moduleBean->$field = preg_replace("/\n/", '
', $moduleBean->$field); 119 | $module_arr[$field] = $moduleBean->$field; 120 | } 121 | } 122 | } 123 | return $module_arr; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /graphql/GraphiQL/cookiejar.js: -------------------------------------------------------------------------------- 1 | var urllib = require("url"); 2 | 3 | module.exports.CookieJar = CookieJar; 4 | 5 | function CookieJar(options) { 6 | this.options = options || {}; 7 | this.options.sessionTimeout = this.options.sessionTimeout || 1800; // 30min 8 | 9 | this.cookies = {}; 10 | } 11 | 12 | CookieJar.prototype.addCookie = function (cookie) { 13 | 14 | if (!cookie || !cookie.name) return; 15 | 16 | var lcookie; 17 | 18 | if (!this.cookies[cookie.name]) { 19 | this.cookies[cookie.name] = []; 20 | } 21 | 22 | // overwrite if has same params 23 | for (var i = 0, len = this.cookies[cookie.name].length; i < len; i++) { 24 | lcookie = this.cookies[cookie.name][i]; 25 | if ( 26 | lcookie.path == cookie.path && 27 | lcookie.domain == cookie.domain && 28 | lcookie.secure == cookie.secure && 29 | lcookie.httponly == cookie.httponly 30 | ) { 31 | this.cookies[cookie.name][i] = cookie; 32 | return; 33 | } 34 | } 35 | 36 | this.cookies[cookie.name].push(cookie); 37 | } 38 | 39 | CookieJar.prototype.getCookies = function (url) { 40 | var keys = Object.keys(this.cookies), 41 | cookie, cookies = []; 42 | 43 | for (var i = 0, len = keys.length; i < len; i++) { 44 | if (Array.isArray(this.cookies[keys[i]])) { 45 | for (var j = 0, lenj = this.cookies[keys[i]].length; j < lenj; j++) { 46 | cookie = this.cookies[keys[i]][j]; 47 | if (this.matchCookie(cookie, url)) { 48 | cookies.push(cookie.name + "=" + cookie.value); 49 | } 50 | } 51 | } 52 | } 53 | return cookies.join("; "); 54 | } 55 | 56 | CookieJar.prototype.matchCookie = function (cookie, url) { 57 | var urlparts = urllib.parse(url || "", false, true), 58 | path; 59 | 60 | // check expire 61 | if (cookie.expire) { 62 | if (cookie.expire.getTime() < Date.now()) { 63 | return; 64 | } 65 | } 66 | 67 | // check if hostname matches 68 | if (urlparts.hostname && cookie._domain) { 69 | if (!(urlparts.hostname == cookie._domain || urlparts.hostname.substr(-(cookie._domain.length + 1)) == "." + cookie._domain)) { 70 | return false; 71 | } 72 | } 73 | 74 | // check if path matches 75 | if (cookie.path && urlparts.pathname) { 76 | 77 | path = (urlparts.pathname || "/").split("/"); 78 | path.pop(); 79 | path = path.join("/").trim(); 80 | if (path.substr(0, 1) != "/") { 81 | path = "/" + path; 82 | } 83 | if (path.substr(-1) != "/") { 84 | path += "/"; 85 | } 86 | 87 | if (path.substr(0, cookie.path.length) != cookie.path) { 88 | return false; 89 | } 90 | } 91 | 92 | // check secure 93 | if (cookie.secure && urlparts.protocol) { 94 | if (urlparts.protocol != "https:") { 95 | return false; 96 | } 97 | } 98 | 99 | // check httponly 100 | if (cookie.httponly && urlparts.protocol) { 101 | if (urlparts.protocol != "http:") { 102 | return false; 103 | } 104 | } 105 | 106 | return true; 107 | } 108 | 109 | CookieJar.prototype.setCookie = function (cookie_str, url) { 110 | var parts = (cookie_str || "").split(";"), 111 | cookie = {}, 112 | urlparts = urllib.parse(url || "", false, true), 113 | path; 114 | 115 | parts.forEach((function (part) { 116 | var key, val; 117 | part = part.split("="); 118 | key = part.shift().trim(); 119 | val = part.join("=").trim(); 120 | 121 | if (!key)return; 122 | 123 | switch (key.toLowerCase()) { 124 | 125 | case "expires": 126 | 127 | cookie.expires = new Date(val); 128 | break; 129 | 130 | case "path": 131 | cookie.path = val.trim(); 132 | break; 133 | 134 | case "domain": 135 | cookie.domain = val.toLowerCase(); 136 | break; 137 | 138 | case "max-age": 139 | cookie.expires = new Date(Date.now() + (Number(val) || 0) * 1000); 140 | break; 141 | 142 | case "secure": 143 | cookie.secure = true; 144 | break; 145 | 146 | case "httponly": 147 | cookie.httponly = true; 148 | break; 149 | 150 | default: 151 | if (!cookie.name) { 152 | cookie.name = key; 153 | cookie.value = val; 154 | } 155 | } 156 | }).bind(this)); 157 | 158 | // use current path when path is not specified 159 | if (!cookie.path) { 160 | path = (urlparts.pathname || "/").split("/"); 161 | path.pop(); 162 | cookie.path = path.join("/").trim(); 163 | if (cookie.path.substr(0, 1) != "/") { 164 | cookie.path = "/" + cookie.path; 165 | } 166 | if (cookie.path.substr(-1) != "/") { 167 | cookie.path += "/"; 168 | } 169 | } 170 | 171 | // if no expire date, then use sessionTimeout value 172 | if (!cookie.expires) { 173 | cookie._expires = new Date(Date.now() + (Number(this.options.sessionTimeout) || 0) * 1000); 174 | } else { 175 | cookie._expires = cookie.expires; 176 | } 177 | 178 | if (!cookie.domain) { 179 | if (urlparts.hostname) { 180 | cookie._domain = urlparts.hostname; 181 | } 182 | } else { 183 | cookie._domain = cookie.domain; 184 | } 185 | 186 | this.addCookie(cookie); 187 | } 188 | -------------------------------------------------------------------------------- /graphql/Schema/UserType.php: -------------------------------------------------------------------------------- 1 | $type) { 15 | $config->addField($field, $type); 16 | } 17 | $config->addField('session_id', new StringType()); 18 | $config->addField('roles', new StringType()); 19 | $config->addField('related_roles', [ 20 | 'type' => new ListType(new AclRoleType()), 21 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 22 | if (!empty($value['related_roles'])) { 23 | $args['id'] = $value['related_roles']; 24 | return AclRoleType::resolve($value, $args, $info); 25 | } else { 26 | return null; 27 | } 28 | }, 29 | ]); 30 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customUserType.php')) { 31 | require_once __DIR__ . '/../../../../../graphql/Schema/customUserType.php'; 32 | if (method_exists('customUserType', 'getFields')) { 33 | $customFields = customUserType::getFields(); 34 | foreach ($customFields as $field => $type) { 35 | $config->addField($field, $type); 36 | } 37 | } 38 | } 39 | } 40 | private function retrieveUser($id, $info) 41 | { 42 | global $db, $sugar_config, $current_user; 43 | $moduleBean = BeanFactory::getBean('Users'); 44 | $moduleBean = $moduleBean->retrieve($id); 45 | 46 | $module_arr = array(); 47 | if ($moduleBean->id && $moduleBean->ACLAccess('view')) { 48 | $module_arr = \crmHelper::getDefaultFieldsValues($moduleBean); 49 | if ($info != null) { 50 | $getFieldASTList = $info->getFieldASTList(); 51 | $queryFields = []; 52 | foreach ($getFieldASTList as $key => $value) { 53 | $queryFields[$value->getName()] = ""; 54 | } 55 | } 56 | $roles = ACLRole::getUserRoleNames($id); 57 | if (!empty($roles)) { 58 | //LX: TODO - create a RoleType to correctly return data 59 | foreach ($roles as $key => $value) { 60 | $module_arr['roles'] = $value; 61 | } 62 | } 63 | 64 | $sql = " 65 | SELECT r.id 66 | FROM users u 67 | INNER JOIN acl_roles_users ur ON u.id = ur.user_id 68 | INNER JOIN acl_roles r ON ur.role_id = r.id 69 | WHERE u.deleted = 0 70 | AND ur.deleted = 0 71 | AND r.deleted = 0 72 | AND u.id = '{$id}'; 73 | "; 74 | $result = $db->query($sql); 75 | if (isset($queryFields) && array_key_exists('related_roles', $queryFields)) { 76 | $module_arr['related_roles'] = array(); 77 | while (($row = $db->fetchByAssoc($result)) != null) { 78 | $module_arr['related_roles'][] = $row['id']; 79 | } 80 | } 81 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customUserType.php')) { 82 | require_once __DIR__ . '/../../../../../graphql/Schema/customUserType.php'; 83 | if (method_exists('customUserType', 'processFields')) { 84 | $module_arr = customUserType::processFields($moduleBean, $queryFields, $module_arr); 85 | } 86 | } 87 | 88 | 89 | // $m1 = 'Users'; 90 | // $m2 = 'ACLRoles'; 91 | // lxlog(getRelationshipByModules($m1, $m2)); 92 | return $module_arr; 93 | } else { 94 | return null; 95 | } 96 | } 97 | 98 | public function resolve($value = null, $args = [], $info = null) // implementing resolve function 99 | { 100 | if (!empty($args['whoami'])) { 101 | global $current_user; 102 | if ($_SESSION['authenticated_user_id']) { 103 | $moduleBean = self::retrieveUser($_SESSION['authenticated_user_id'], $info); 104 | $moduleBean['session_id'] = session_id(); 105 | return $moduleBean; 106 | } else { 107 | return null; 108 | } 109 | } 110 | if (isset($args['id']) && is_array($args['id'])) { 111 | foreach ($args as $key => $moduleBeanId) { 112 | if (isset($moduleBeanId) && is_array($moduleBeanId)) { 113 | foreach ($moduleBeanId as $key => $moduleBeanIdItem) { 114 | $resultArray[] = self::retrieveUser($moduleBeanIdItem, $info); 115 | } 116 | } elseif (!empty($moduleBeanId)) { 117 | $resultArray[] = self::retrieveUser($moduleBeanId, $info); 118 | } 119 | } 120 | return $resultArray; 121 | } elseif (!empty($args['id'])) { 122 | return self::retrieveUser($args['id'], $info); 123 | } 124 | } 125 | 126 | public function getName() 127 | { 128 | return 'user'; // important to use the real name here, it will be used later in the Schema 129 | } 130 | public function getOutputType() 131 | { 132 | return 'user'; // important to use the real name here, it will be used later in the Schema 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /graphql/Schema/CaseupdatesType.php: -------------------------------------------------------------------------------- 1 | $type) { 15 | $config->addField($field, $type); 16 | } 17 | $config->addField('created_user_details', [ 18 | 'type' => new UserType(), 19 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 20 | if (!empty($value['created_user_details'])) { 21 | $args['id'] = $value['created_user_details']; 22 | return UserType::resolve($value, $args, $info); 23 | } else { 24 | return null; 25 | } 26 | }, 27 | ]); 28 | $config->addField('assigned_user_details', [ 29 | 'type' => new UserType(), 30 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 31 | if (!empty($value['assigned_user_details'])) { 32 | $args['id'] = $value['assigned_user_details']; 33 | return UserType::resolve($value, $args, $info); 34 | } else { 35 | return null; 36 | } 37 | }, 38 | ]); 39 | $config->addField('modified_user_details', [ 40 | 'type' => new UserType(), 41 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 42 | if (!empty($value['modified_user_details'])) { 43 | $args['id'] = $value['modified_user_details']; 44 | return UserType::resolve($value, $args, $info); 45 | } else { 46 | return null; 47 | } 48 | }, 49 | ]); 50 | $config->addField('contacts', [ 51 | 'type' => new ContactsListType(), 52 | 'args' => argsHelper::entityArgsHelper('Contacts'), 53 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 54 | if (!empty($value['contacts'])) { 55 | return ContactsListType::resolve($value, ['id' => $value['contacts']], $info); 56 | } else { 57 | return null; 58 | } 59 | }, 60 | ]); 61 | $config->addField('account_details', [ 62 | 'type' => new AccountType(), 63 | 'args' => argsHelper::entityArgsHelper('Accounts'), 64 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 65 | if (!empty($value['account_details'])) { 66 | return AccountType::resolve($value, ['id' => $value['account_details']], $info); 67 | } else { 68 | return null; 69 | } 70 | }, 71 | ]); 72 | } 73 | private function retrieveCaseupdates($id, $info) 74 | { 75 | global $sugar_config, $current_user; 76 | $moduleBean = \BeanFactory::getBean('AOP_Case_Updates'); 77 | $moduleBean = $moduleBean->retrieve($id); 78 | $module_arr = array(); 79 | if ($moduleBean->id && $moduleBean->ACLAccess('view')) { 80 | $module_arr = crmHelper::getDefaultFieldsValues($moduleBean); 81 | if ($info != null) { 82 | $getFieldASTList = $info->getFieldASTList(); 83 | $queryFields = []; 84 | foreach ($getFieldASTList as $key => $value) { 85 | $queryFields[$value->getName()] = ""; 86 | } 87 | } 88 | if (isset($queryFields) && array_key_exists('created_user_details', $queryFields)) { 89 | $module_arr['created_user_details'] = $module_arr['created_by']; 90 | } 91 | 92 | if (isset($queryFields) && array_key_exists('assigned_user_details', $queryFields)) { 93 | $module_arr['assigned_user_details'] = $module_arr['assigned_user_id']; 94 | } 95 | 96 | if (isset($queryFields) && array_key_exists('modified_user_details', $queryFields)) { 97 | $module_arr['modified_user_details'] = $module_arr['modified_user_id']; 98 | } 99 | 100 | 101 | if (isset($queryFields) && array_key_exists('contacts', $queryFields)) { 102 | $module_arr['contacts'] = array(); 103 | foreach ($moduleBean->get_linked_beans('contacts', 'Contact') as $contact) { 104 | $module_arr['contacts'][] = $contact->id; 105 | } 106 | } 107 | 108 | return $module_arr; 109 | } else { 110 | return null; 111 | } 112 | } 113 | 114 | public function resolve($value = null, $args = [], $info = null) // implementing resolve function 115 | { 116 | if (isset($args['id']) && is_array($args['id'])) { 117 | foreach ($args as $key => $moduleBeanId) { 118 | if (isset($moduleBeanId) && is_array($moduleBeanId)) { 119 | foreach ($moduleBeanId as $key => $moduleBeanIdItem) { 120 | $resultArray[] = self::retrieveCaseupdates($moduleBeanIdItem, $info); 121 | } 122 | } elseif (!empty($moduleBeanId)) { 123 | $resultArray[] = self::retrieveCaseupdates($moduleBeanId, $info); 124 | } 125 | } 126 | 127 | return $resultArray; 128 | } elseif (!empty($args['id'])) { 129 | return self::retrieveCaseupdates($args['id'], $info); 130 | } 131 | } 132 | 133 | public function getName() 134 | { 135 | return 'aop_case_updates'; // important to use the real name here, it will be used later in the Schema 136 | } 137 | } -------------------------------------------------------------------------------- /graphql/GraphiQL/fetch.min.js: -------------------------------------------------------------------------------- 1 | !function () { 2 | "use strict"; 3 | function a(a) { 4 | if ("string" != typeof a && (a = a.toString()), /[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(a))throw new TypeError("Invalid character in header field name"); 5 | return a.toLowerCase() 6 | } 7 | 8 | function b(a) { 9 | return "string" != typeof a && (a = a.toString()), a 10 | } 11 | 12 | function c(a) { 13 | this.map = {}, a instanceof c ? a.forEach(function (a, b) { 14 | this.append(b, a) 15 | }, this) : a && Object.getOwnPropertyNames(a).forEach(function (b) { 16 | this.append(b, a[b]) 17 | }, this) 18 | } 19 | 20 | function d(a) { 21 | return a.bodyUsed ? Promise.reject(new TypeError("Already read")) : (a.bodyUsed = !0, void 0) 22 | } 23 | 24 | function e(a) { 25 | return new Promise(function (b, c) { 26 | a.onload = function () { 27 | b(a.result) 28 | }, a.onerror = function () { 29 | c(a.error) 30 | } 31 | }) 32 | } 33 | 34 | function f(a) { 35 | var b = new FileReader; 36 | return b.readAsArrayBuffer(a), e(b) 37 | } 38 | 39 | function g(a) { 40 | var b = new FileReader; 41 | return b.readAsText(a), e(b) 42 | } 43 | 44 | function i() { 45 | return this.bodyUsed = !1, this._initBody = function (a) { 46 | if (this._bodyInit = a, "string" == typeof a)this._bodyText = a; else if (h.blob && Blob.prototype.isPrototypeOf(a))this._bodyBlob = a; else if (h.formData && FormData.prototype.isPrototypeOf(a))this._bodyFormData = a; else { 47 | if (a)throw new Error("unsupported BodyInit type"); 48 | this._bodyText = "" 49 | } 50 | }, h.blob ? (this.blob = function () { 51 | var a = d(this); 52 | if (a)return a; 53 | if (this._bodyBlob)return Promise.resolve(this._bodyBlob); 54 | if (this._bodyFormData)throw new Error("could not read FormData body as blob"); 55 | return Promise.resolve(new Blob([this._bodyText])) 56 | }, this.arrayBuffer = function () { 57 | return this.blob().then(f) 58 | }, this.text = function () { 59 | var a = d(this); 60 | if (a)return a; 61 | if (this._bodyBlob)return g(this._bodyBlob); 62 | if (this._bodyFormData)throw new Error("could not read FormData body as text"); 63 | return Promise.resolve(this._bodyText) 64 | }) : this.text = function () { 65 | var a = d(this); 66 | return a ? a : Promise.resolve(this._bodyText) 67 | }, h.formData && (this.formData = function () { 68 | return this.text().then(m) 69 | }), this.json = function () { 70 | return this.text().then(JSON.parse) 71 | }, this 72 | } 73 | 74 | function k(a) { 75 | var b = a.toUpperCase(); 76 | return j.indexOf(b) > -1 ? b : a 77 | } 78 | 79 | function l(a, b) { 80 | if (b = b || {}, this.url = a, this.credentials = b.credentials || "omit", this.headers = new c(b.headers), this.method = k(b.method || "GET"), this.mode = b.mode || null, this.referrer = null, ("GET" === this.method || "HEAD" === this.method) && b.body)throw new TypeError("Body not allowed for GET or HEAD requests"); 81 | this._initBody(b.body) 82 | } 83 | 84 | function m(a) { 85 | var b = new FormData; 86 | return a.trim().split("&").forEach(function (a) { 87 | if (a) { 88 | var c = a.split("="), d = c.shift().replace(/\+/g, " "), e = c.join("=").replace(/\+/g, " "); 89 | b.append(decodeURIComponent(d), decodeURIComponent(e)) 90 | } 91 | }), b 92 | } 93 | 94 | function n(a) { 95 | var b = new c, d = a.getAllResponseHeaders().trim().split("\n"); 96 | return d.forEach(function (a) { 97 | var c = a.trim().split(":"), d = c.shift().trim(), e = c.join(":").trim(); 98 | b.append(d, e) 99 | }), b 100 | } 101 | 102 | function o(a, b) { 103 | b || (b = {}), this._initBody(a), this.type = "default", this.url = null, this.status = b.status, this.ok = this.status >= 200 && this.status < 300, this.statusText = b.statusText, this.headers = b.headers instanceof c ? b.headers : new c(b.headers), this.url = b.url || "" 104 | } 105 | 106 | if (!self.fetch) { 107 | c.prototype.append = function (c, d) { 108 | c = a(c), d = b(d); 109 | var e = this.map[c]; 110 | e || (e = [], this.map[c] = e), e.push(d) 111 | }, c.prototype["delete"] = function (b) { 112 | delete this.map[a(b)] 113 | }, c.prototype.get = function (b) { 114 | var c = this.map[a(b)]; 115 | return c ? c[0] : null 116 | }, c.prototype.getAll = function (b) { 117 | return this.map[a(b)] || [] 118 | }, c.prototype.has = function (b) { 119 | return this.map.hasOwnProperty(a(b)) 120 | }, c.prototype.set = function (c, d) { 121 | this.map[a(c)] = [b(d)] 122 | }, c.prototype.forEach = function (a, b) { 123 | Object.getOwnPropertyNames(this.map).forEach(function (c) { 124 | this.map[c].forEach(function (d) { 125 | a.call(b, d, c, this) 126 | }, this) 127 | }, this) 128 | }; 129 | var h = { 130 | blob: "FileReader" in self && "Blob" in self && function () { 131 | try { 132 | return new Blob, !0 133 | } catch (a) { 134 | return !1 135 | } 136 | }(), formData: "FormData" in self 137 | }, j = ["DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT"]; 138 | i.call(l.prototype), i.call(o.prototype), self.Headers = c, self.Request = l, self.Response = o, self.fetch = function (a, b) { 139 | var c; 140 | return c = l.prototype.isPrototypeOf(a) && !b ? a : new l(a, b), new Promise(function (a, b) { 141 | function e() { 142 | return "responseURL" in d ? d.responseURL : /^X-Request-URL:/m.test(d.getAllResponseHeaders()) ? d.getResponseHeader("X-Request-URL") : void 0 143 | } 144 | 145 | var d = new XMLHttpRequest; 146 | d.onload = function () { 147 | var c = 1223 === d.status ? 204 : d.status; 148 | if (100 > c || c > 599)return b(new TypeError("Network request failed")), void 0; 149 | var f = { 150 | status: c, 151 | statusText: d.statusText, 152 | headers: n(d), 153 | url: e() 154 | }, g = "response" in d ? d.response : d.responseText; 155 | a(new o(g, f)) 156 | }, d.onerror = function () { 157 | b(new TypeError("Network request failed")) 158 | }, d.open(c.method, c.url, !0), "include" === c.credentials && (d.withCredentials = !0), "responseType" in d && h.blob && (d.responseType = "blob"), c.headers.forEach(function (a, b) { 159 | d.setRequestHeader(b, a) 160 | }), d.send("undefined" == typeof c._bodyInit ? null : c._bodyInit) 161 | }) 162 | }, self.fetch.polyfill = !0 163 | } 164 | }(); 165 | -------------------------------------------------------------------------------- /graphql/Schema/QuoteType.php: -------------------------------------------------------------------------------- 1 | $type) { 43 | $config->addField($field, $type); 44 | } 45 | 46 | $config->addField('billing_account_details', [ 47 | 'type' => new AccountType(), 48 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 49 | if (!empty($value['billing_account_details'])) { 50 | $args['id'] = $value['billing_account_details']; 51 | return AccountType::resolve($value, $args, $info); 52 | } else { 53 | return null; 54 | } 55 | }, 56 | ]); 57 | $config->addField('billing_contact_details', [ 58 | 'type' => new ContactType(), 59 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 60 | if (!empty($value['billing_contact_details'])) { 61 | $args['id'] = $value['billing_contact_details']; 62 | return ContactType::resolve($value, $args, $info); 63 | } else { 64 | return null; 65 | } 66 | }, 67 | ]); 68 | $config->addField('opportunity_details', [ 69 | 'type' => new OpportunityType(), 70 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 71 | if (!empty($value['created_user_details'])) { 72 | $args['id'] = $value['opportunity_details']; 73 | return OpportunityType::resolve($value, $args, $info); 74 | } else { 75 | return null; 76 | } 77 | }, 78 | ]); 79 | $config->addField('created_user_details', [ 80 | 'type' => new UserType(), 81 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 82 | if (!empty($value['created_user_details'])) { 83 | $args['id'] = $value['created_user_details']; 84 | return UserType::resolve($value, $args, $info); 85 | } else { 86 | return null; 87 | } 88 | }, 89 | ]); 90 | $config->addField('assigned_user_details', [ 91 | 'type' => new UserType(), 92 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 93 | if (!empty($value['assigned_user_details'])) { 94 | $args['id'] = $value['assigned_user_details']; 95 | return UserType::resolve($value, $args, $info); 96 | } else { 97 | return null; 98 | } 99 | }, 100 | ]); 101 | $config->addField('modified_user_details', [ 102 | 'type' => new UserType(), 103 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 104 | if (!empty($value['modified_user_details'])) { 105 | $args['id'] = $value['modified_user_details']; 106 | return UserType::resolve($value, $args, $info); 107 | } else { 108 | return null; 109 | } 110 | }, 111 | ]); 112 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customQuoteType.php')) { 113 | require_once __DIR__ . '/../../../../../graphql/Schema/customQuoteType.php'; 114 | if (method_exists('customQuoteType', 'getFields')) { 115 | $customFields = customQuoteType::getFields(); 116 | foreach ($customFields as $field => $type) { 117 | $config->addField($field, $type); 118 | } 119 | } 120 | } 121 | } 122 | 123 | public function resolve($value = null, $args = [], $info = null) 124 | { 125 | if (isset($args['id']) && is_array($args['id'])) { 126 | 127 | // We received a list of contacts to return 128 | foreach ($args as $key => $accountId) { 129 | // error_log(__LINE__.print_r($args,1)); 130 | if (isset($accountId) && is_array($accountId)) { 131 | foreach ($accountId as $key => $accountIdItem) { 132 | 133 | $resultArray[] = self::retrieve($accountIdItem, $info); 134 | } 135 | } elseif (!empty($contactId)) { 136 | $resultArray[] = self::retrieve($accountId, $info); 137 | } 138 | } 139 | 140 | return $resultArray; 141 | } else { 142 | 143 | // We received a list of contacts to return 144 | if (!empty($args['id'])) { 145 | return self::retrieve($args['id'], $info); 146 | } 147 | } 148 | } 149 | 150 | public function retrieve($id, $info = null) // implementing resolve function 151 | { 152 | global $sugar_config, $current_user; 153 | $moduleBean = \BeanFactory::getBean('AOS_Quotes'); 154 | $moduleBean = $moduleBean->retrieve($id); 155 | $module_arr = array(); 156 | if ($moduleBean->id && $moduleBean->ACLAccess('view')) { 157 | $module_arr = \crmHelper::getDefaultFieldsValues($moduleBean); 158 | if ($info != null) { 159 | $getFieldASTList = $info->getFieldASTList(); 160 | $queryFields = []; 161 | foreach ($getFieldASTList as $key => $value) { 162 | $queryFields[$value->getName()] = ""; 163 | } 164 | } 165 | if (isset($queryFields) && array_key_exists('modified_user_details', $queryFields)) { 166 | $module_arr['modified_user_details'] = $module_arr['modified_user_id']; 167 | } 168 | if (isset($queryFields) && array_key_exists('assigned_user_details', $queryFields)) { 169 | $module_arr['assigned_user_details'] = $module_arr['assigned_user_id']; 170 | } 171 | if (isset($queryFields) && array_key_exists('created_user_details', $queryFields)) { 172 | $module_arr['created_user_details'] = $module_arr['created_by']; 173 | } 174 | if (isset($queryFields) && array_key_exists('billing_account_details', $queryFields)) { 175 | $module_arr['billing_account_details'] = $module_arr['billing_account_id']; 176 | } 177 | if (isset($queryFields) && array_key_exists('billing_contact_details', $queryFields)) { 178 | $module_arr['billing_contact_details'] = $module_arr['billing_contact_id']; 179 | } 180 | if (isset($queryFields) && array_key_exists('opportunity_details', $queryFields)) { 181 | $module_arr['opportunity_details'] = $module_arr['opportunity_id']; 182 | } 183 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customQuoteType.php')) { 184 | require_once __DIR__ . '/../../../../../graphql/Schema/customQuoteType.php'; 185 | if (method_exists('customQuoteType', 'processFields')) { 186 | $module_arr = customQuoteType::processFields($moduleBean, $queryFields, $module_arr); 187 | } 188 | } 189 | return $module_arr; 190 | } else { 191 | // Error 192 | error_log('Error resolving QuoteType'); 193 | 194 | return; 195 | } 196 | } 197 | 198 | public function getName() 199 | { 200 | return 'quote'; // important to use the real name here, it will be used later in the Schema 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /graphql/Schema/TaskType.php: -------------------------------------------------------------------------------- 1 | $type) { 15 | $config->addField($field, $type); 16 | } 17 | $config->addField('created_user_details', [ 18 | 'type' => new UserType(), 19 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 20 | if (!empty($value['created_user_details'])) { 21 | $args['id'] = $value['created_user_details']; 22 | return UserType::resolve($value, $args, $info); 23 | } else { 24 | return null; 25 | } 26 | }, 27 | ]); 28 | $config->addField('assigned_user_details', [ 29 | 'type' => new UserType(), 30 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 31 | if (!empty($value['assigned_user_details'])) { 32 | $args['id'] = $value['assigned_user_details']; 33 | return UserType::resolve($value, $args, $info); 34 | } else { 35 | return null; 36 | } 37 | }, 38 | ]); 39 | $config->addField('modified_user_details', [ 40 | 'type' => new UserType(), 41 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 42 | if (!empty($value['modified_user_details'])) { 43 | $args['id'] = $value['modified_user_details']; 44 | return UserType::resolve($value, $args, $info); 45 | } else { 46 | return null; 47 | } 48 | }, 49 | ]); 50 | $config->addField('parent_contact', [ 51 | 'type' => new ContactType(), 52 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 53 | if (!empty($value['parent_contact'])) { 54 | $args['ids'] = $value['parent_contact']; 55 | return ContactType::resolve($value, $args, $info); 56 | } else { 57 | return null; 58 | } 59 | }, 60 | ]); 61 | $config->addField('parent_account', [ 62 | 'type' => new AccountType(), 63 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 64 | if (!empty($value['parent_account'])) { 65 | $args['ids'] = $value['parent_account']; 66 | return AccountType::resolve($value, $args, $info); 67 | } else { 68 | return null; 69 | } 70 | }, 71 | ]); 72 | $config->addField('related_contacts', [ 73 | 'type' => new ContactsListType(), 74 | 'args' => argsHelper::entityArgsHelper('Contacts'), 75 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 76 | if (!empty($value['related_contacts'])) { 77 | $args['ids'] = $value['related_contacts']; 78 | return ContactsListType::resolve($value, $args, $info); 79 | } else { 80 | return null; 81 | } 82 | }, 83 | ]); 84 | $config->addField('related_accounts', [ 85 | 'type' => new AccountsListType(), 86 | 'args' => argsHelper::entityArgsHelper('Accounts'), 87 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 88 | if (!empty($value['related_accounts'])) { 89 | $args['ids'] = $value['related_accounts']; 90 | return AccountsListType::resolve($value, $args, $info); 91 | } else { 92 | return null; 93 | } 94 | }, 95 | ]); 96 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customTaskType.php')) { 97 | require_once __DIR__ . '/../../../../../graphql/Schema/customTaskType.php'; 98 | if (method_exists('customTaskType', 'getFields')) { 99 | $customFields = customTaskType::getFields(); 100 | foreach ($customFields as $field => $type) { 101 | $config->addField($field, $type); 102 | } 103 | } 104 | } 105 | } 106 | private function retrieveTask($id, $info) 107 | { 108 | global $sugar_config, $current_user; 109 | $moduleBean = BeanFactory::getBean('Tasks'); 110 | $moduleBean = $moduleBean->retrieve($id); 111 | 112 | 113 | $module_arr = array(); 114 | if ($moduleBean->id && $moduleBean->ACLAccess('view')) { 115 | $module_arr = \crmHelper::getDefaultFieldsValues($moduleBean); 116 | if ($info != null) { 117 | $getFieldASTList = $info->getFieldASTList(); 118 | $queryFields = []; 119 | foreach ($getFieldASTList as $key => $value) { 120 | $queryFields[$value->getName()] = ""; 121 | } 122 | } 123 | $module_arr['created_user_details'] = $module_arr['created_by']; 124 | $module_arr['assigned_user_details'] = $module_arr['assigned_user_id']; 125 | $module_arr['modified_user_details'] = $module_arr['modified_user_id']; 126 | switch ($module_arr['parent_type']) { 127 | case 'Contacts': 128 | $module_arr['parent_contact'] = $module_arr['parent_id']; 129 | $module_arr['parent_account'] = ''; 130 | $module_arr['parent_opportunity'] = ''; 131 | break; 132 | case 'Accounts': 133 | $module_arr['parent_account'] = $module_arr['parent_id']; 134 | $module_arr['parent_contact'] = ''; 135 | $module_arr['parent_opportunity'] = ''; 136 | break; 137 | case 'Opportunities': 138 | $module_arr['parent_opportunity'] = $module_arr['parent_id']; 139 | $module_arr['parent_contact'] = ''; 140 | $module_arr['parent_account'] = ''; 141 | break; 142 | default: 143 | $module_arr['parent_opportunity'] = ''; 144 | $module_arr['parent_contact'] = ''; 145 | $module_arr['parent_account'] = ''; 146 | break; 147 | } 148 | if (isset($queryFields) && array_key_exists('contacts', $queryFields)) { 149 | $module_arr['related_contacts'] = array(); 150 | foreach ($moduleBean->get_linked_beans('contacts', 'Contact') as $contact) { 151 | $module_arr['related_contacts'][] = $contact->id; 152 | } 153 | } 154 | if (isset($queryFields) && array_key_exists('accounts', $queryFields)) { 155 | $module_arr['related_accounts'] = array(); 156 | foreach ($moduleBean->get_linked_beans('accounts', 'Account') as $account) { 157 | $module_arr['related_accounts'][] = $account->id; 158 | } 159 | } 160 | if (isset($queryFields) && array_key_exists('opportunities', $queryFields)) { 161 | $module_arr['related_opportunities'] = array(); 162 | foreach ($moduleBean->get_linked_beans('opportunities', 'Opportunity') as $opportunity) { 163 | $module_arr['related_opportunities'][] = $opportunity->id; 164 | } 165 | } 166 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customTaskType.php')) { 167 | require_once __DIR__ . '/../../../../../graphql/Schema/customTaskType.php'; 168 | if (method_exists('customTaskType', 'processFields')) { 169 | $module_arr = customTaskType::processFields($moduleBean, $queryFields, $module_arr); 170 | } 171 | } 172 | return $module_arr; 173 | } else { 174 | return null; 175 | } 176 | } 177 | 178 | public function resolve($value = null, $args = [], $info = null) // implementing resolve function 179 | { 180 | if (isset($args['id']) && is_array($args['id'])) { 181 | foreach ($args as $key => $moduleBeanId) { 182 | if (isset($moduleBeanId) && is_array($moduleBeanId)) { 183 | foreach ($moduleBeanId as $key => $moduleBeanIdItem) { 184 | $resultArray[] = self::retrieveTask($moduleBeanIdItem, $info); 185 | } 186 | } elseif (!empty($moduleBeanId)) { 187 | $resultArray[] = self::retrieveTask($moduleBeanId, $info); 188 | } 189 | } 190 | 191 | return $resultArray; 192 | } elseif (!empty($args['id'])) { 193 | return self::retrieveTask($args['id'], $info); 194 | } 195 | } 196 | 197 | public function getName() 198 | { 199 | return 'task'; // important to use the real name here, it will be used later in the Schema 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /graphql/Schema/ContactType.php: -------------------------------------------------------------------------------- 1 | $type) { 13 | $config->addField($field, $type); 14 | } 15 | $config->addField('calls', [ 16 | 'type' => new ListType(new CallType()), 17 | 'args' => argsHelper::entityArgsHelper('Calls'), 18 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 19 | if (!empty($value['calls'])) { 20 | $args['ids'] = $value['calls']; 21 | return CallsListType::resolve($value, $args, $info); 22 | } else { 23 | return null; 24 | } 25 | }, 26 | ]); 27 | $config->addField('cases', [ 28 | 'type' => new ListType(new CaseType()), 29 | 'args' => argsHelper::entityArgsHelper('Cases'), 30 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 31 | if (!empty($value['cases'])) { 32 | $args['ids'] = $value['cases']; 33 | return CasesListType::resolve($value, $args, $info); 34 | } else { 35 | return null; 36 | } 37 | }, 38 | ]); 39 | $config->addField('created_user_details', [ 40 | 'type' => new UserType(), 41 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 42 | if (!empty($value['created_user_details'])) { 43 | $args['id'] = $value['created_user_details']; 44 | return UserType::resolve($value, $args, $info); 45 | } else { 46 | return null; 47 | } 48 | }, 49 | ]); 50 | $config->addField('assigned_user_details', [ 51 | 'type' => new UserType(), 52 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 53 | if (!empty($value['assigned_user_details'])) { 54 | $args['id'] = $value['assigned_user_details']; 55 | return UserType::resolve($value, $args, $info); 56 | } else { 57 | return null; 58 | } 59 | }, 60 | ]); 61 | $config->addField('modified_user_details', [ 62 | 'type' => new UserType(), 63 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 64 | if (!empty($value['modified_user_details'])) { 65 | $args['id'] = $value['modified_user_details']; 66 | return UserType::resolve($value, $args, $info); 67 | } else { 68 | return null; 69 | } 70 | }, 71 | ]); 72 | $config->addField('accounts', [ 73 | 'type' => new AccountsListType(), 74 | 'args' => argsHelper::entityArgsHelper('Accounts'), 75 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 76 | if (!empty($value['accounts'])) { 77 | $args['ids'] = $value['accounts']; 78 | return AccountsListType::resolve($value, $args, $info); 79 | } else { 80 | return null; 81 | } 82 | }, 83 | ]); 84 | $config->addField('campaigns', [ 85 | 'type' => new CampaignsListType(), 86 | 'args' => argsHelper::entityArgsHelper('Campaigns'), 87 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 88 | if (!empty($value['campaigns'][0])) { 89 | $args['ids'] = $value['campaigns']; 90 | return CampaignsListType::resolve($value, $args, $info); 91 | } else { 92 | return null; 93 | } 94 | }, 95 | ]); 96 | $config->addField('tasks', [ 97 | 'type' => new TasksListType(), 98 | 'args' => argsHelper::entityArgsHelper('Tasks'), 99 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 100 | if (!empty($value['tasks'])) { 101 | $args['ids'] = $value['tasks']; 102 | return TasksListType::resolve($value, $args, $info); 103 | } else { 104 | return null; 105 | } 106 | }, 107 | ]); 108 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customContactType.php')) { 109 | require_once __DIR__ . '/../../../../../graphql/Schema/customContactType.php'; 110 | if (method_exists('customContactType', 'getFields')) { 111 | $customFields = customContactType::getFields(); 112 | foreach ($customFields as $field => $type) { 113 | $config->addField($field, $type); 114 | } 115 | } 116 | } 117 | } 118 | private function retrieveContact($id, $info = null) 119 | { 120 | global $sugar_config, $current_user; 121 | $moduleBean = \BeanFactory::getBean('Contacts'); 122 | $moduleBean = $moduleBean->retrieve($id); 123 | $module_arr = array(); 124 | if ($moduleBean->id && $moduleBean->ACLAccess('view')) { 125 | $module_arr = crmHelper::getDefaultFieldsValues($moduleBean); 126 | 127 | if ($info != null) { 128 | $getFieldASTList = $info->getFieldASTList(); 129 | $queryFields = []; 130 | foreach ($getFieldASTList as $key => $value) { 131 | $queryFields[$value->getName()] = ""; 132 | } 133 | } 134 | if (isset($queryFields) && array_key_exists('modified_user_details', $queryFields)) { 135 | $module_arr['modified_user_details'] = $module_arr['modified_user_id']; 136 | } 137 | if (isset($queryFields) && array_key_exists('assigned_user_details', $queryFields)) { 138 | $module_arr['assigned_user_details'] = $module_arr['assigned_user_id']; 139 | } 140 | if (isset($queryFields) && array_key_exists('created_user_details', $queryFields)) { 141 | $module_arr['created_user_details'] = $module_arr['created_by']; 142 | } 143 | if (isset($queryFields) && array_key_exists('calls', $queryFields)) { 144 | $module_arr['calls'] = array(); 145 | foreach ($moduleBean->get_linked_beans('calls') as $call) { 146 | $module_arr['calls'][] = $call->id; 147 | } 148 | } 149 | if (isset($queryFields) && array_key_exists('cases', $queryFields)) { 150 | $module_arr['cases'] = array(); 151 | foreach ($moduleBean->get_linked_beans('cases') as $case) { 152 | $module_arr['cases'][] = $case->id; 153 | } 154 | } 155 | if (isset($queryFields) && array_key_exists('tasks', $queryFields)) { 156 | $module_arr['tasks'] = array(); 157 | foreach ($moduleBean->get_linked_beans('tasks') as $task) { 158 | $module_arr['tasks'][] = $task->id; 159 | } 160 | } 161 | 162 | if (isset($queryFields) && array_key_exists('accounts', $queryFields)) { 163 | $module_arr['accounts'] = array(); 164 | foreach ($moduleBean->get_linked_beans('accounts') as $account) { 165 | $module_arr['accounts'][] = $account->id; 166 | } 167 | } 168 | if (isset($queryFields) && array_key_exists('campaigns', $queryFields)) { 169 | $module_arr['campaigns'] = array(); 170 | foreach ($moduleBean->get_linked_beans('campaigns') as $campaign) { 171 | $module_arr['campaigns'][] = $campaign->id; 172 | } 173 | } 174 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customContactType.php')) { 175 | require_once __DIR__ . '/../../../../../graphql/Schema/customContactType.php'; 176 | if (method_exists('customContactType', 'processFields')) { 177 | $module_arr = customContactType::processFields($moduleBean, $queryFields, $module_arr); 178 | } 179 | } 180 | return $module_arr; 181 | } else { 182 | return null; 183 | } 184 | } 185 | 186 | public function resolve($value = null, $args = [], $info = null) // implementing resolve function 187 | { 188 | if (isset($args['id']) && is_array($args['id'])) { 189 | // We received a list of contacts to return 190 | foreach ($args as $key => $moduleBeanId) { 191 | if (isset($moduleBeanId) && is_array($moduleBeanId)) { 192 | foreach ($moduleBeanId as $key => $moduleBeanIdItem) { 193 | $resultArray[] = self::retrieveContact($moduleBeanIdItem, $info); 194 | } 195 | } elseif (!empty($moduleBeanId)) { 196 | $resultArray[] = self::retrieveContact($moduleBeanId, $info); 197 | } 198 | } 199 | return $resultArray; 200 | } else { 201 | 202 | // We received a list of contacts to return 203 | if (!empty($args['id'])) { 204 | return self::retrieveContact($args['id'], $info); 205 | } 206 | } 207 | } 208 | 209 | public function getName() 210 | { 211 | return 'contact'; // important to use the real name here, it will be used later in the Schema 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /graphql/Schema/MeetingType.php: -------------------------------------------------------------------------------- 1 | $type) { 15 | $config->addField($field, $type); 16 | } 17 | $config->addField('created_user_details', [ 18 | 'type' => new UserType(), 19 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 20 | return UserType::resolve(null, ['id' => $value['created_user_details']], $info); 21 | }, 22 | ]); 23 | $config->addField('assigned_user_details', [ 24 | 'type' => new UserType(), 25 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 26 | return UserType::resolve(null, ['id' => $value['assigned_user_details']], $info); 27 | }, 28 | ]); 29 | $config->addField('modified_user_details', [ 30 | 'type' => new UserType(), 31 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 32 | return UserType::resolve(null, ['id' => $value['modified_user_details']], $info); 33 | }, 34 | ]); 35 | $config->addField('parent_contact', [ 36 | 'type' => new ContactType(), 37 | 'args' => argsHelper::entityArgsHelper('Contacts'), 38 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 39 | if (!empty($value['parent_contact'])) { 40 | return ContactType::resolve(null, ['id' => $value['parent_contact']], $info); 41 | } else { 42 | return null; 43 | } 44 | }, 45 | ]); 46 | $config->addField('parent_account', [ 47 | 'type' => new AccountType(), 48 | 'args' => argsHelper::entityArgsHelper('Accounts'), 49 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 50 | if (!empty($value['parent_account'])) { 51 | return AccountType::resolve(null, ['id' => $value['parent_account']], $info); 52 | } else { 53 | return null; 54 | } 55 | }, 56 | ]); 57 | $config->addField('parent_opportunity', [ 58 | 'type' => new OpportunityType(), 59 | 'args' => argsHelper::entityArgsHelper('Opportunities'), 60 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 61 | if (!empty($value['parent_opportunity'])) { 62 | return OpportunityType::resolve($value, ['id' => $value['parent_opportunity']], $info); 63 | } else { 64 | return null; 65 | } 66 | }, 67 | ]); 68 | $config->addField('parent_case', [ 69 | 'type' => new CaseType(), 70 | 'args' => argsHelper::entityArgsHelper('Cases'), 71 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 72 | if (!empty($value['parent_case'])) { 73 | return CaseType::resolve($value, ['id' => $value['parent_case']], $info); 74 | } else { 75 | return null; 76 | } 77 | }, 78 | ]); 79 | $config->addField('accounts', [ 80 | 'type' => new AccountsListType(), 81 | 'args' => argsHelper::entityArgsHelper('Accounts'), 82 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 83 | if (!empty($value['accounts'])) { 84 | $args['ids'] = $value['accounts']; 85 | return AccountsListType::resolve($value, $args, $info); 86 | } else { 87 | return null; 88 | } 89 | }, 90 | ]); 91 | $config->addField('contacts', [ 92 | 'type' => new ContactsListType(), 93 | 'args' => argsHelper::entityArgsHelper('Contacts'), 94 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 95 | if (!empty($value['contacts'])) { 96 | $args['ids'] = $value['contacts']; 97 | return ContactsListType::resolve($value, $args, $info); 98 | } else { 99 | return null; 100 | } 101 | }, 102 | ]); 103 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customMeetingType.php')) { 104 | require_once __DIR__ . '/../../../../../graphql/Schema/customMeetingType.php'; 105 | if (method_exists('customMeetingType', 'getFields')) { 106 | $customFields = customMeetingType::getFields(); 107 | foreach ($customFields as $field => $type) { 108 | $config->addField($field, $type); 109 | } 110 | } 111 | } 112 | } 113 | private function retrieveMeeting($id, $info) 114 | { 115 | global $sugar_config, $current_user; 116 | $moduleBean = \BeanFactory::getBean('Meetings'); 117 | $moduleBean = $moduleBean->retrieve($id); 118 | 119 | 120 | $module_arr = array(); 121 | if ($moduleBean->id && $moduleBean->ACLAccess('view')) { 122 | $module_arr = crmHelper::getDefaultFieldsValues($moduleBean); 123 | if ($info != null) { 124 | $getFieldASTList = $info->getFieldASTList(); 125 | $queryFields = []; 126 | foreach ($getFieldASTList as $key => $value) { 127 | $queryFields[$value->getName()] = ""; 128 | } 129 | } 130 | $module_arr['created_user_details'] = $module_arr['created_by']; 131 | $module_arr['assigned_user_details'] = $module_arr['assigned_user_id']; 132 | $module_arr['modified_user_details'] = $module_arr['modified_user_id']; 133 | switch ($module_arr['parent_type']) { 134 | case 'Contacts': 135 | $module_arr['parent_contact'] = $module_arr['parent_id']; 136 | $module_arr['parent_account'] = ''; 137 | $module_arr['parent_opportunity'] = ''; 138 | $module_arr['parent_case'] = ''; 139 | break; 140 | case 'Accounts': 141 | $module_arr['parent_account'] = $module_arr['parent_id']; 142 | $module_arr['parent_case'] = ''; 143 | $module_arr['parent_contact'] = ''; 144 | $module_arr['parent_opportunity'] = ''; 145 | break; 146 | case 'Cases': 147 | $module_arr['parent_case'] = $module_arr['parent_id']; 148 | $module_arr['parent_contact'] = ''; 149 | $module_arr['parent_account'] = ''; 150 | $module_arr['parent_opportunity'] = ''; 151 | break; 152 | case 'Opportunities': 153 | $module_arr['parent_opportunity'] = $module_arr['parent_id']; 154 | $module_arr['parent_contact'] = ''; 155 | $module_arr['parent_account'] = ''; 156 | $module_arr['parent_case'] = ''; 157 | break; 158 | default: 159 | $module_arr['parent_opportunity'] = ''; 160 | $module_arr['parent_contact'] = ''; 161 | $module_arr['parent_account'] = ''; 162 | $module_arr['parent_case'] = ''; 163 | break; 164 | } 165 | if (isset($queryFields) && array_key_exists('contacts', $queryFields)) { 166 | $module_arr['contacts'] = array(); 167 | foreach ($moduleBean->get_linked_beans('contacts', 'Contact') as $contact) { 168 | $module_arr['contacts'][] = $contact->id; 169 | } 170 | } 171 | if (isset($queryFields) && array_key_exists('accounts', $queryFields)) { 172 | $module_arr['accounts'] = array(); 173 | foreach ($moduleBean->get_linked_beans('accounts', 'Account') as $account) { 174 | $module_arr['accounts'][] = $account->id; 175 | } 176 | } 177 | if (isset($queryFields) && array_key_exists('opportunities', $queryFields)) { 178 | $module_arr['opportunities'] = array(); 179 | foreach ($moduleBean->get_linked_beans('opportunities', 'Opportunity') as $account) { 180 | $module_arr['opportunities'][] = $account->id; 181 | } 182 | } 183 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customMeetingType.php')) { 184 | require_once __DIR__ . '/../../../../../graphql/Schema/customMeetingType.php'; 185 | if (method_exists('customMeetingType', 'processFields')) { 186 | $module_arr = customMeetingType::processFields($moduleBean, $queryFields, $module_arr); 187 | } 188 | } 189 | return $module_arr; 190 | } else { 191 | return null; 192 | } 193 | } 194 | 195 | public function resolve($value = null, $args = [], $info = null) // implementing resolve function 196 | 197 | { 198 | if (isset($args['id']) && is_array($args['id'])) { 199 | foreach ($args as $key => $moduleBeanId) { 200 | if (isset($moduleBeanId) && is_array($moduleBeanId)) { 201 | foreach ($moduleBeanId as $key => $moduleBeanIdItem) { 202 | $resultArray[] = self::retrieveMeeting($moduleBeanIdItem, $info); 203 | } 204 | } elseif (!empty($moduleBeanId)) { 205 | $resultArray[] = self::retrieveMeeting($moduleBeanId, $info); 206 | } 207 | } 208 | return $resultArray; 209 | } elseif (!empty($args['id'])) { 210 | return self::retrieveMeeting($args['id'], $info); 211 | } 212 | } 213 | 214 | public function getName() 215 | { 216 | return 'meeting'; // important to use the real name here, it will be used later in the Schema 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /graphql/Schema/CampaignType.php: -------------------------------------------------------------------------------- 1 | $type) { 15 | $config->addField($field, $type); 16 | } 17 | $config->addField('created_user_details', [ 18 | 'type' => new UserType(), 19 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 20 | if (!empty($value['created_user_details'])) { 21 | $args['id'] = $value['created_user_details']; 22 | return UserType::resolve($value, $args, $info); 23 | } else { 24 | return null; 25 | } 26 | }, 27 | ]); 28 | $config->addField('assigned_user_details', [ 29 | 'type' => new UserType(), 30 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 31 | if (!empty($value['assigned_user_details'])) { 32 | $args['id'] = $value['assigned_user_details']; 33 | return UserType::resolve($value, $args, $info); 34 | } else { 35 | return null; 36 | } 37 | }, 38 | ]); 39 | $config->addField('modified_user_details', [ 40 | 'type' => new UserType(), 41 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 42 | if (!empty($value['modified_user_details'])) { 43 | $args['id'] = $value['modified_user_details']; 44 | return UserType::resolve($value, $args, $info); 45 | } else { 46 | return null; 47 | } 48 | }, 49 | ]); 50 | $config->addField('parent_contact', [ 51 | 'type' => new ContactType(), 52 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 53 | if (!empty($value['parent_contact'])) { 54 | $args['ids'] = $value['parent_contact']; 55 | return ContactType::resolve($value, $args, $info); 56 | } else { 57 | return null; 58 | } 59 | }, 60 | ]); 61 | $config->addField('parent_account', [ 62 | 'type' => new AccountType(), 63 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 64 | if (!empty($value['parent_account'])) { 65 | $args['ids'] = $value['parent_opportunity']; 66 | return AccountType::resolve($value, $args, $info); 67 | } else { 68 | return null; 69 | } 70 | }, 71 | ]); 72 | $config->addField('parent_opportunity', [ 73 | 'type' => new OpportunityType(), 74 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 75 | if (!empty($value['parent_opportunity'])) { 76 | $args['ids'] = $value['parent_opportunity']; 77 | return OpportunityType::resolve($value, $args, $info); 78 | } else { 79 | return null; 80 | } 81 | }, 82 | ]); 83 | $config->addField('contacts', [ 84 | 'type' => new ContactsListType(), 85 | 'args' => argsHelper::entityArgsHelper('Contacts'), 86 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 87 | if (!empty($value['contacts'])) { 88 | $args['ids'] = $value['contacts']; 89 | return ContactsListType::resolve($value, $args, $info); 90 | } else { 91 | return null; 92 | } 93 | } 94 | ]); 95 | $config->addField('accounts', [ 96 | 'type' => new AccountsListType(), 97 | 'args' => argsHelper::entityArgsHelper('Accounts'), 98 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 99 | if (!empty($value['accounts'])) { 100 | $args['ids'] = $value['accounts']; 101 | return AccountsListType::resolve($value, $args, $info); 102 | } else { 103 | return null; 104 | } 105 | }, 106 | ]); 107 | $config->addField('opportunities', [ 108 | 'type' => new OpportunitiesListType(), 109 | 'args' => argsHelper::entityArgsHelper('Opportunities'), 110 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 111 | if (!empty($value['opportunities'])) { 112 | $args['ids'] = $value['opportunities']; 113 | return OpportunitiesListType::resolve($value, $args, $info); 114 | } else { 115 | return null; 116 | } 117 | }, 118 | ]); 119 | $config->addField('notes', [ 120 | 'type' => new ListType(new NoteType()), 121 | 'args' => argsHelper::entityArgsHelper('Notes'), 122 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 123 | if (!empty($value['notes'])) { 124 | $args['ids'] = $value['notes']; 125 | return NotesListType::resolve($value, $args, $info); 126 | } else { 127 | return null; 128 | } 129 | }, 130 | ]); 131 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customCampaignType.php')) { 132 | require_once __DIR__ . '/../../../../../graphql/Schema/customCampaignType.php'; 133 | if (method_exists(customCampaignType, getFields)) { 134 | $customFields = customCampaignType::getFields(); 135 | foreach ($customFields as $field => $type) { 136 | $config->addField($field, $type); 137 | } 138 | } 139 | } 140 | } 141 | private function retrieveCampaign($id, $info) 142 | { 143 | global $sugar_config, $current_user; 144 | $moduleBean = BeanFactory::getBean('Campaigns'); 145 | $moduleBean = $moduleBean->retrieve($id); 146 | 147 | $module_arr = array(); 148 | if ($moduleBean->id && $moduleBean->ACLAccess('view')) { 149 | $module_arr = crmHelper::getDefaultFieldsValues($moduleBean); 150 | if ($info != null) { 151 | $getFieldASTList = $info->getFieldASTList(); 152 | $queryFields = []; 153 | foreach ($getFieldASTList as $key => $value) { 154 | $queryFields[$value->getName()] = ""; 155 | } 156 | } 157 | if (isset($queryFields) && array_key_exists('created_user_details', $queryFields)) { 158 | $module_arr['created_user_details'] = $module_arr['created_by']; 159 | } 160 | 161 | if (isset($queryFields) && array_key_exists('assigned_user_details', $queryFields)) { 162 | $module_arr['assigned_user_details'] = $module_arr['assigned_user_id']; 163 | } 164 | 165 | if (isset($queryFields) && array_key_exists('modified_user_details', $queryFields)) { 166 | $module_arr['modified_user_details'] = $module_arr['modified_user_id']; 167 | } 168 | 169 | switch ($module_arr['parent_type']) { 170 | case 'Contacts': 171 | $module_arr['parent_contact'] = $module_arr['parent_id']; 172 | $module_arr['parent_account'] = ''; 173 | $module_arr['parent_opportunity'] = ''; 174 | break; 175 | case 'Accounts': 176 | $module_arr['parent_account'] = $module_arr['parent_id']; 177 | $module_arr['parent_contact'] = ''; 178 | $module_arr['parent_opportunity'] = ''; 179 | break; 180 | case 'Opportunities': 181 | $module_arr['parent_opportunity'] = $module_arr['parent_id']; 182 | $module_arr['parent_contact'] = ''; 183 | $module_arr['parent_account'] = ''; 184 | break; 185 | default: 186 | $module_arr['parent_opportunity'] = ''; 187 | $module_arr['parent_contact'] = ''; 188 | $module_arr['parent_account'] = ''; 189 | break; 190 | } 191 | if (isset($queryFields) && array_key_exists('contacts', $queryFields)) { 192 | $module_arr['contacts'] = array(); 193 | foreach ($moduleBean->get_linked_beans('contacts', 'Contact') as $contact) { 194 | $module_arr['contacts'][] = $contact->id; 195 | } 196 | } 197 | if (isset($queryFields) && array_key_exists('accounts', $queryFields)) { 198 | $module_arr['accounts'] = array(); 199 | foreach ($moduleBean->get_linked_beans('accounts', 'Account') as $account) { 200 | $module_arr['accounts'][] = $account->id; 201 | } 202 | } 203 | if (isset($queryFields) && array_key_exists('opportunities', $queryFields)) { 204 | $module_arr['opportunities'] = array(); 205 | foreach ($moduleBean->get_linked_beans('opportunities', 'Opportunity') as $opportunity) { 206 | $module_arr['opportunities'][] = $opportunity->id; 207 | } 208 | } 209 | if (isset($queryFields) && array_key_exists('notes', $queryFields)) { 210 | $module_arr['notes'] = array(); 211 | foreach ($moduleBean->get_linked_beans('notes') as $note) { 212 | $module_arr['notes'][] = $note->id; 213 | } 214 | } 215 | 216 | 217 | return $module_arr; 218 | } else { 219 | return null; 220 | } 221 | } 222 | 223 | public function resolve($value = null, $args = [], $info = null) // implementing resolve function 224 | { 225 | if (isset($args['id']) && is_array($args['id'])) { 226 | foreach ($args as $key => $moduleBeanId) { 227 | if (isset($moduleBeanId) && is_array($moduleBeanId)) { 228 | foreach ($moduleBeanId as $key => $moduleBeanIdItem) { 229 | $resultArray[] = self::retrieveCampaign($moduleBeanIdItem, $info); 230 | } 231 | } elseif (!empty($moduleBeanId)) { 232 | $resultArray[] = self::retrieveCampaign($moduleBeanId, $info); 233 | } 234 | } 235 | 236 | return $resultArray; 237 | } elseif (!empty($args['id'])) { 238 | return self::retrieveCampaign($args['id'], $info); 239 | } 240 | } 241 | 242 | public function getName() 243 | { 244 | return 'campaign'; // important to use the real name here, it will be used later in the Schema 245 | } 246 | } -------------------------------------------------------------------------------- /graphql/Schema/CaseType.php: -------------------------------------------------------------------------------- 1 | $type) { 13 | $config->addField($field, $type); 14 | } 15 | $config->addField('notes', [ 16 | 'type' => new ListType(new NoteType()), 17 | 'args' => argsHelper::entityArgsHelper('Notes'), 18 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 19 | if (!empty($value['notes'])) { 20 | $args['id'] = $value['notes']; 21 | return NotesListType::resolve($value, $args, $info); 22 | } else { 23 | return null; 24 | } 25 | }, 26 | ]); 27 | $config->addField('meetings', [ 28 | 'type' => new ListType(new MeetingType()), 29 | 'args' => argsHelper::entityArgsHelper('Meetings'), 30 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 31 | if (!empty($value['meetings'])) { 32 | $args['id'] = $value['meetings']; 33 | return MeetingsListType::resolve($value, $args, $info); 34 | } else { 35 | return null; 36 | } 37 | }, 38 | ]); 39 | $config->addField('created_user_details', [ 40 | 'type' => new UserType(), 41 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 42 | if (!empty($value['created_user_details'])) { 43 | $args['id'] = $value['created_user_details']; 44 | return UserType::resolve($value, $args, $info); 45 | } else { 46 | return null; 47 | } 48 | }, 49 | ]); 50 | $config->addField('assigned_user_details', [ 51 | 'type' => new UserType(), 52 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 53 | if (!empty($value['assigned_user_details'])) { 54 | $args['id'] = $value['assigned_user_details']; 55 | return UserType::resolve($value, $args, $info); 56 | } else { 57 | return null; 58 | } 59 | }, 60 | ]); 61 | $config->addField('modified_user_details', [ 62 | 'type' => new UserType(), 63 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 64 | if (!empty($value['modified_user_details'])) { 65 | $args['id'] = $value['modified_user_details']; 66 | return UserType::resolve($value, $args, $info); 67 | } else { 68 | return null; 69 | } 70 | }, 71 | ]); 72 | $config->addField('case_updates', [ 73 | 'type' => new CaseupdatesListType(), 74 | 'args' => argsHelper::entityArgsHelper('AOP_Case_Updates'), 75 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 76 | if (!empty($value['case_updates'])) { 77 | $args['id'] = $value['case_updates']; 78 | return CaseupdatesListType::resolve($value, $args, $info); 79 | } else { 80 | return null; 81 | } 82 | }, 83 | ]); 84 | $config->addField('calls', [ 85 | 'type' => new ListType(new CallType()), 86 | 'args' => argsHelper::entityArgsHelper('Calls'), 87 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 88 | if (!empty($value['calls'])) { 89 | $args['id'] = $value['calls']; 90 | return CallsListType::resolve($value, $args, $info); 91 | } else { 92 | return null; 93 | } 94 | }, 95 | ]); 96 | $config->addField('contacts', [ 97 | 'type' => new ContactsListType(), 98 | 'args' => argsHelper::entityArgsHelper('Contacts'), 99 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 100 | if (!empty($value['contacts'])) { 101 | return ContactsListType::resolve($value, ['id' => $value['contacts']], $info); 102 | } else { 103 | return null; 104 | } 105 | }, 106 | ]); 107 | $config->addField('accounts', [ 108 | 'type' => new AccountsListType(), 109 | 'args' => argsHelper::entityArgsHelper('Accounts'), 110 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 111 | if (!empty($value['accounts'])) { 112 | return AccountsListType::resolve($value, ['id' => $value['accounts']], $info); 113 | } else { 114 | return null; 115 | } 116 | }, 117 | ]); 118 | $config->addField('account_details', [ 119 | 'type' => new AccountType(), 120 | 'args' => argsHelper::entityArgsHelper('Accounts'), 121 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 122 | if (!empty($value['account_details'])) { 123 | return AccountType::resolve($value, ['id' => $value['account_details']], $info); 124 | } else { 125 | return null; 126 | } 127 | }, 128 | ]); 129 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customCaseType.php')) { 130 | require_once __DIR__ . '/../../../../../graphql/Schema/customCaseType.php'; 131 | if (method_exists('customCaseType', 'getFields')) { 132 | $customFields = customCaseType::getFields(); 133 | foreach ($customFields as $field => $type) { 134 | $config->addField($field, $type); 135 | } 136 | } 137 | } 138 | } 139 | private function retrieveCase($id, $info) 140 | { 141 | global $sugar_config, $current_user; 142 | $moduleBean = BeanFactory::getBean('Cases'); 143 | $moduleBean = $moduleBean->retrieve($id); 144 | 145 | $module_arr = array(); 146 | if ($moduleBean->id && $moduleBean->ACLAccess('view')) { 147 | $module_arr = crmHelper::getDefaultFieldsValues($moduleBean); 148 | if ($info != null) { 149 | $getFieldASTList = $info->getFieldASTList(); 150 | $queryFields = []; 151 | foreach ($getFieldASTList as $key => $value) { 152 | $queryFields[$value->getName()] = ""; 153 | } 154 | } 155 | if (isset($queryFields) && array_key_exists('created_user_details', $queryFields)) { 156 | $module_arr['created_user_details'] = $module_arr['created_by']; 157 | } 158 | 159 | if (isset($queryFields) && array_key_exists('assigned_user_details', $queryFields)) { 160 | $module_arr['assigned_user_details'] = $module_arr['assigned_user_id']; 161 | } 162 | 163 | if (isset($queryFields) && array_key_exists('modified_user_details', $queryFields)) { 164 | $module_arr['modified_user_details'] = $module_arr['modified_user_id']; 165 | } 166 | if (isset($queryFields) && array_key_exists('calls', $queryFields)) { 167 | $module_arr['calls'] = array(); 168 | foreach ($moduleBean->get_linked_beans('calls') as $call) { 169 | $module_arr['calls'][] = $call->id; 170 | } 171 | } 172 | if (isset($queryFields) && array_key_exists('contacts', $queryFields)) { 173 | $module_arr['contacts'] = array(); 174 | foreach ($moduleBean->get_linked_beans('contacts', 'Contact') as $contact) { 175 | $module_arr['contacts'][] = $contact->id; 176 | } 177 | } 178 | if (isset($queryFields) && array_key_exists('accounts', $queryFields)) { 179 | $module_arr['accounts'] = array(); 180 | foreach ($moduleBean->get_linked_beans('accounts', 'Account') as $account) { 181 | $module_arr['accounts'][] = $account->id; 182 | } 183 | } 184 | if (isset($queryFields) && array_key_exists('case_updates', $queryFields)) { 185 | $module_arr['case_updates'] = array(); 186 | foreach ($moduleBean->get_linked_beans('aop_case_updates', 'AOP_Case_Updates') as $updates) { 187 | $module_arr['case_updates'][] = $updates->id; 188 | } 189 | } 190 | 191 | if (isset($queryFields) && array_key_exists('notes', $queryFields)) { 192 | $module_arr['notes'] = array(); 193 | foreach ($moduleBean->get_linked_beans('notes') as $note) { 194 | $module_arr['notes'][] = $note->id; 195 | } 196 | } 197 | if (isset($queryFields) && array_key_exists('meetings', $queryFields)) { 198 | $module_arr['meetings'] = array(); 199 | foreach ($moduleBean->get_linked_beans('meetings') as $meeting) { 200 | $module_arr['meetings'][] = $meeting->id; 201 | } 202 | } 203 | if (isset($queryFields) && array_key_exists('account_details', $queryFields)) { 204 | $module_arr['account_details'] = $moduleBean->account_id; 205 | } 206 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customCaseType.php')) { 207 | require_once __DIR__ . '/../../../../../graphql/Schema/customCaseType.php'; 208 | if (method_exists('customCaseType', 'processFields')) { 209 | $module_arr = customCaseType::processFields($moduleBean, $queryFields, $module_arr); 210 | } 211 | } 212 | return $module_arr; 213 | } else { 214 | return null; 215 | } 216 | } 217 | 218 | public function resolve($value = null, $args = [], $info = null) // implementing resolve function 219 | { 220 | if (isset($args['id']) && is_array($args['id'])) { 221 | foreach ($args as $key => $moduleBeanId) { 222 | if (isset($moduleBeanId) && is_array($moduleBeanId)) { 223 | foreach ($moduleBeanId as $key => $moduleBeanIdItem) { 224 | $resultArray[] = self::retrieveCase($moduleBeanIdItem, $info); 225 | } 226 | } elseif (!empty($moduleBeanId)) { 227 | $resultArray[] = self::retrieveCase($moduleBeanId, $info); 228 | } 229 | } 230 | 231 | return $resultArray; 232 | } elseif (!empty($args['id'])) { 233 | return self::retrieveCase($args['id'], $info); 234 | } 235 | } 236 | 237 | public function getName() 238 | { 239 | return 'case'; // important to use the real name here, it will be used later in the Schema 240 | } 241 | } 242 | -------------------------------------------------------------------------------- /graphql/Schema/OpportunityType.php: -------------------------------------------------------------------------------- 1 | $type) { 45 | $config->addField($field, $type); 46 | } 47 | $config->addField('contacts', [ 48 | 'type' => new ContactsListType(), 49 | 'args' => argsHelper::entityArgsHelper('Contacts'), 50 | 'resolve' => function ($value, $args, ResolveInfo $info) { 51 | if (!empty($value['contacts'])) { 52 | $args['ids'] = $value['contacts']; 53 | return ContactsListType::resolve($value, $args, $info); 54 | } else { 55 | return null; 56 | } 57 | }, 58 | ]); 59 | $config->addField('notes', [ 60 | 'type' => new NotesListType(), 61 | 'args' => argsHelper::entityArgsHelper('Notes'), 62 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 63 | if (!empty($value['notes'])) { 64 | $args['ids'] = $value['notes']; 65 | return NotesListType::resolve($value, $args, $info); 66 | } else { 67 | return null; 68 | } 69 | }, 70 | ]); 71 | $config->addField('account_details', [ 72 | 'type' => new AccountType(), 73 | 'resolve' => function ($value, $args, ResolveInfo $info) { 74 | if (!empty($value['account_id'])) { 75 | $args['id'] = $value['account_id']; 76 | return AccountType::resolve($value, $args, $info); 77 | } else { 78 | return null; 79 | } 80 | }, 81 | ]); 82 | $config->addField('calls', [ 83 | 'type' => new CallsListType(), 84 | 'args' => argsHelper::entityArgsHelper('Calls'), 85 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 86 | if (!empty($value['calls'])) { 87 | $args['ids'] = $value['calls']; 88 | return CallsListType::resolve($value, $args, $info); 89 | } else { 90 | return null; 91 | } 92 | }, 93 | ]); 94 | $config->addField('aos_quotes', [ 95 | 'type' => new QuotesListType(), 96 | 'args' => argsHelper::entityArgsHelper('AOS_Quotes'), 97 | 'resolve' => function ($value, $args, ResolveInfo $info) { 98 | if (!empty($value['aos_quotes'])) { 99 | $args['ids'] = $value['aos_quotes']; 100 | return QuotesListType::resolve($value, $args, $info); 101 | } else { 102 | return null; 103 | } 104 | }, 105 | ]); 106 | $config->addField('created_user_details', [ 107 | 'type' => new UserType(), 108 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 109 | if (!empty($value['created_user_details'])) { 110 | $args['id'] = $value['created_user_details']; 111 | return UserType::resolve($value, $args, $info); 112 | } else { 113 | return null; 114 | } 115 | }, 116 | ]); 117 | $config->addField('assigned_user_details', [ 118 | 'type' => new UserType(), 119 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 120 | if (!empty($value['assigned_user_details'])) { 121 | $args['id'] = $value['assigned_user_details']; 122 | return UserType::resolve($value, $args, $info); 123 | } else { 124 | return null; 125 | } 126 | }, 127 | ]); 128 | $config->addField('modified_user_details', [ 129 | 'type' => new UserType(), 130 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 131 | if (!empty($value['modified_user_details'])) { 132 | $args['id'] = $value['modified_user_details']; 133 | return UserType::resolve($value, $args, $info); 134 | } else { 135 | return null; 136 | } 137 | }, 138 | ]); 139 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customOpportunityType.php')) { 140 | require_once __DIR__ . '/../../../../../graphql/Schema/customOpportunityType.php'; 141 | if (method_exists('customOpportunityType', 'getFields')) { 142 | $customFields = customOpportunityType::getFields(); 143 | foreach ($customFields as $field => $type) { 144 | $config->addField($field, $type); 145 | } 146 | } 147 | } 148 | } 149 | 150 | public function resolve($value = null, $args = [], ResolveInfo $info = null) 151 | { 152 | if (isset($args['id']) && is_array($args['id'])) { 153 | // We received a list of contacts to return 154 | foreach ($args as $key => $moduleBeanId) { 155 | if (isset($moduleBeanId) && is_array($moduleBeanId)) { 156 | foreach ($moduleBeanId as $key => $moduleBeanIdItem) { 157 | 158 | $resultArray[] = self::retrieve($moduleBeanIdItem, $info); 159 | } 160 | } elseif (!empty($moduleBeanId)) { 161 | $resultArray[] = self::retrieve($moduleBeanId, $info); 162 | } 163 | } 164 | return $resultArray; 165 | } else { 166 | // We received a list of contacts to return 167 | if (!empty($args['id'])) { 168 | return self::retrieve($args['id'], $info); 169 | } 170 | } 171 | } 172 | public function retrieve($id, $info = null) // implementing resolve function 173 | { 174 | global $sugar_config, $current_user; 175 | $moduleBean = \BeanFactory::getBean('Opportunities'); 176 | $moduleBean = $moduleBean->retrieve($id); 177 | $module_arr = array(); 178 | if ($moduleBean->id && $moduleBean->ACLAccess('view')) { 179 | $module_arr = \crmHelper::getDefaultFieldsValues($moduleBean); 180 | if ($info != null) { 181 | $getFieldASTList = $info->getFieldASTList(); 182 | $queryFields = []; 183 | foreach ($getFieldASTList as $key => $value) { 184 | $queryFields[$value->getName()] = ""; 185 | } 186 | } 187 | if (isset($queryFields) && array_key_exists('contacts', $queryFields)) { 188 | $moduleBean->load_relationship('contacts'); 189 | $module_arr['contacts'] = array(); 190 | foreach ($moduleBean->contacts->getBeans() as $contact) { 191 | $module_arr['contacts'][] = $contact->id; 192 | } 193 | } 194 | if (isset($queryFields) && array_key_exists('notes', $queryFields)) { 195 | $module_arr['notes'] = array(); 196 | foreach ($moduleBean->get_linked_beans('notes') as $note) { 197 | $module_arr['notes'][] = $note->id; 198 | } 199 | } 200 | if (isset($queryFields) && array_key_exists('account_id', $queryFields)) { 201 | $moduleBean->load_relationship('accounts'); 202 | foreach ($moduleBean->accounts->getBeans() as $account) { 203 | $module_arr['account_id'] = $account->id; 204 | } 205 | } 206 | if (isset($queryFields) && array_key_exists('aos_quotes', $queryFields)) { 207 | $moduleBean->load_relationship('aos_quotes'); 208 | $module_arr['aos_quotes'] = array(); 209 | foreach ($moduleBean->aos_quotes->getBeans() as $aos_quote) { 210 | $module_arr['aos_quotes'][] = $aos_quote->id; 211 | } 212 | } 213 | if (isset($queryFields) && array_key_exists('calls', $queryFields)) { 214 | $module_arr['calls'] = array(); 215 | foreach ($moduleBean->get_linked_beans('calls') as $call) { 216 | $module_arr['calls'][] = $call->id; 217 | } 218 | } 219 | if (isset($queryFields) && array_key_exists('modified_user_details', $queryFields)) { 220 | $module_arr['modified_user_details'] = $module_arr['modified_user_id']; 221 | } 222 | if (isset($queryFields) && array_key_exists('assigned_user_details', $queryFields)) { 223 | $module_arr['assigned_user_details'] = $module_arr['assigned_user_id']; 224 | } 225 | if (isset($queryFields) && array_key_exists('created_user_details', $queryFields)) { 226 | $module_arr['created_user_details'] = $module_arr['created_by']; 227 | } 228 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customOpportunityType.php')) { 229 | require_once __DIR__ . '/../../../../../graphql/Schema/customOpportunityType.php'; 230 | if (method_exists('customOpportunityType', 'processFields')) { 231 | $module_arr = customOpportunityType::processFields($contact, $queryFields, $module_arr); 232 | } 233 | } 234 | return $module_arr; 235 | } else { 236 | // Error 237 | error_log('Error resolving OpportunityType'); 238 | 239 | return; 240 | } 241 | } 242 | 243 | public function getName() 244 | { 245 | return "opportunity"; // important to use the real name here, it will be used later in the Schema 246 | } 247 | } 248 | -------------------------------------------------------------------------------- /graphql/Schema/argsHelper.php: -------------------------------------------------------------------------------- 1 | $type) { 55 | $argsArray = array_merge($argsArray, [ 56 | $field => $type, 57 | ]); 58 | } 59 | } 60 | } 61 | if (isset($dictionary[$entity])) { 62 | $moduleFields = $dictionary[$entity]['fields']; 63 | } else { 64 | $moduleFields = null; 65 | } 66 | if (is_array($moduleFields)) { 67 | foreach ($moduleFields as $key => $value) { 68 | if ($moduleFields[$key]['type'] != 'link') { 69 | $fieldType = $moduleFields[$key]['type']; 70 | $argsArray = array_merge($argsArray, [$key => self::suitecrmToGraphqlTypeMapper($fieldType)]); 71 | if ($mutation == false) { 72 | //Mutation doesn't allow this types as they are cannot be used to insert new data 73 | if ($fieldType == 'date' || $fieldType == 'datetime' || $fieldType == 'datetimecombo') { 74 | //If the field type is a date/datetime we add 2 more fields so we can search on that field using range 75 | $fieldNameStartRange = "start_range_" . $key; 76 | $fieldNameEndRange = "end_range_" . $key; 77 | $dateFieldAtomVersion = $key . "_atom"; 78 | $argsArray = array_merge($argsArray, [$fieldNameStartRange => self::suitecrmToGraphqlTypeMapper($fieldType)]); 79 | $argsArray = array_merge($argsArray, [$fieldNameEndRange => self::suitecrmToGraphqlTypeMapper($fieldType)]); 80 | $argsArray = array_merge($argsArray, [$dateFieldAtomVersion => self::suitecrmToGraphqlTypeMapper($fieldType)]); 81 | } elseif ($fieldType == 'relate' && isset($moduleFields[$key]['module']) && $moduleFields[$key]['module'] == 'Users') { 82 | //Fields of type Related will be added a new _details FIELD to the graphql query 83 | // Which will allow to reference the related Module allowing queries like 84 | // For example, a related field named related_user_field_c, will have a 85 | // related_user_field_c_details which in turn will be linked to the User modules 86 | // So it will be possible to query related_user_field_c_details{ user_name} 87 | $fieldNamePlusDetails = $key . "_details"; 88 | $relatedFieldName = $moduleFields[$key]['id_name']; 89 | $argsArray = array_merge($argsArray, [ 90 | $fieldNamePlusDetails => 91 | [ 92 | 'type' => new UserType(), 93 | 'args' => argsHelper::entityArgsHelper('Users', true), 94 | 'resolve' => function ($value, array $args, Youshido\GraphQL\Execution\ResolveInfo $info) use ($relatedFieldName) { 95 | if (!empty($relatedFieldName)) { 96 | $args['id'] = $value[$relatedFieldName]; 97 | return UserType::resolve($value, $args, $info); 98 | } else { 99 | return null; 100 | } 101 | }, 102 | ], 103 | ]); 104 | } elseif ($fieldType == 'relate' && isset($moduleFields[$key]['module']) && $moduleFields[$key]['module'] == 'Contacts') { 105 | $fieldNamePlusDetails = $key . "_details"; 106 | $relatedFieldName = $moduleFields[$key]['id_name']; 107 | $argsArray = array_merge($argsArray, [ 108 | $fieldNamePlusDetails => 109 | [ 110 | 'type' => new ContactType(), 111 | 'args' => argsHelper::entityArgsHelper('Contacts', true), 112 | 'resolve' => function ($value, array $args, Youshido\GraphQL\Execution\ResolveInfo $info) use ($relatedFieldName) { 113 | if (!empty($relatedFieldName)) { 114 | $args['id'] = $value[$relatedFieldName]; 115 | return ContactType::resolve($value, $args, $info); 116 | } else { 117 | return null; 118 | } 119 | }, 120 | ], 121 | ]); 122 | } elseif ($fieldType == 'relate' && isset($moduleFields[$key]['module']) && $moduleFields[$key]['module'] == 'Accounts') { 123 | $fieldNamePlusDetails = $key . "_details"; 124 | $relatedFieldName = $moduleFields[$key]['id_name']; 125 | $argsArray = array_merge($argsArray, [ 126 | $fieldNamePlusDetails => 127 | [ 128 | 'type' => new AccountType(), 129 | 'args' => argsHelper::entityArgsHelper('Accounts', true), 130 | 'resolve' => function ($value, array $args, Youshido\GraphQL\Execution\ResolveInfo $info) use ($relatedFieldName) { 131 | if (!empty($relatedFieldName)) { 132 | $args['id'] = $value[$relatedFieldName]; 133 | return AccountType::resolve($value, $args, $info); 134 | } else { 135 | return null; 136 | } 137 | }, 138 | ], 139 | ]); 140 | } elseif ($fieldType == 'relate' && isset($moduleFields[$key]['module']) && $moduleFields[$key]['module'] == 'Opportunities') { 141 | $fieldNamePlusDetails = $key . "_details"; 142 | $relatedFieldName = $moduleFields[$key]['id_name']; 143 | $argsArray = array_merge($argsArray, [ 144 | $fieldNamePlusDetails => 145 | [ 146 | 'type' => new OpportunityType(), 147 | 'args' => argsHelper::entityArgsHelper('Opportunities', true), 148 | 'resolve' => function ($value, array $args, Youshido\GraphQL\Execution\ResolveInfo $info) use ($relatedFieldName) { 149 | if (!empty($relatedFieldName)) { 150 | $args['id'] = $value[$relatedFieldName]; 151 | return OpportunityType::resolve($value, $args, $info); 152 | } else { 153 | return null; 154 | } 155 | }, 156 | ], 157 | ]); 158 | } 159 | } 160 | } 161 | } 162 | } 163 | $argsArray = array_merge($argsArray, [ 164 | //TODO: This variables should only be exposed on QUERY but not to MUTATION. 165 | 'offset' => new StringType(TypeMap::TYPE_INT), 166 | 'limit' => new StringType(TypeMap::TYPE_INT), 167 | 'order' => new StringType(TypeMap::TYPE_STRING), 168 | 'distinct' => new StringType(TypeMap::TYPE_STRING), 169 | 'relate_to' => new StringType(TypeMap::TYPE_STRING), 170 | 'relate_id' => new StringType(TypeMap::TYPE_STRING), 171 | 'notifyonsave' => new StringType(TypeMap::TYPE_BOOLEAN), 172 | ]); 173 | //Some modules have more fields due to relations or special fields 174 | if ($entity == 'Contact' || $entity == 'Account' || $entity == 'Prospect' || $entity == 'Lead') { 175 | $argsArray = array_merge($argsArray, [ 176 | 'email1' => new StringType(TypeMap::TYPE_STRING), 177 | 'ids' => new ListType(new StringType(TypeMap::TYPE_STRING)), 178 | ]); 179 | } 180 | if ($entity == 'Opportunity') { 181 | $argsArray = array_merge($argsArray, [ 182 | 'account_id' => new StringType(TypeMap::TYPE_STRING), 183 | ]); 184 | } 185 | if ($entity == 'Call' || $entity == 'Case' || $entity == 'Note' || $entity == 'Account' || $entity == 'Contact' || $entity == 'Lead' || $entity == 'Opportunitiy' || $entity == 'Meeting' || $entity == 'Task') { 186 | $argsArray = array_merge($argsArray, [ 187 | 'related_bean' => new StringType(TypeMap::TYPE_STRING), 188 | 'related_id' => new StringType(TypeMap::TYPE_STRING), 189 | ]); 190 | } 191 | 192 | return $argsArray; 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /graphql/Schema/CallType.php: -------------------------------------------------------------------------------- 1 | $type) { 16 | $config->addField($field, $type); 17 | } 18 | $config->addField('created_user_details', [ 19 | 'type' => new UserType(), 20 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 21 | if (!empty($value['created_user_details'])) { 22 | $args['id'] = $value['created_user_details']; 23 | return UserType::resolve($value, $args, $info); 24 | } else { 25 | return null; 26 | } 27 | }, 28 | ]); 29 | $config->addField('assigned_user_details', [ 30 | 'type' => new UserType(), 31 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 32 | if (!empty($value['assigned_user_details'])) { 33 | $args['id'] = $value['assigned_user_details']; 34 | return UserType::resolve($value, $args, $info); 35 | } else { 36 | return null; 37 | } 38 | }, 39 | ]); 40 | $config->addField('modified_user_details', [ 41 | 'type' => new UserType(), 42 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 43 | if (!empty($value['modified_user_details'])) { 44 | $args['id'] = $value['modified_user_details']; 45 | return UserType::resolve($value, $args, $info); 46 | } else { 47 | return null; 48 | } 49 | }, 50 | ]); 51 | $config->addField('parent_contact', [ 52 | 'type' => new ContactType(), 53 | 'args' => argsHelper::entityArgsHelper('Contacts'), 54 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 55 | if (!empty($value['parent_contact'])) { 56 | $args['ids'] = $value['parent_contact']; 57 | return ContactType::resolve($value, $args, $info); 58 | } else { 59 | return null; 60 | } 61 | }, 62 | ]); 63 | $config->addField('parent_account', [ 64 | 'type' => new AccountType(), 65 | 'args' => argsHelper::entityArgsHelper('Accounts'), 66 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 67 | if (!empty($value['parent_account'])) { 68 | $args['ids'] = $value['parent_account']; 69 | return AccountType::resolve($value, $args, $info); 70 | } else { 71 | return null; 72 | } 73 | }, 74 | ]); 75 | $config->addField('parent_case', [ 76 | 'type' => new CaseType(), 77 | 'args' => argsHelper::entityArgsHelper('Cases'), 78 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 79 | if (!empty($value['parent_case'])) { 80 | $args['id'] = $value['parent_case']; 81 | return CaseType::resolve($value, $args, $info); 82 | } else { 83 | return null; 84 | } 85 | }, 86 | ]); 87 | $config->addField('parent_opportunity', [ 88 | 'type' => new OpportunityType(), 89 | 'args' => argsHelper::entityArgsHelper('Opportunities'), 90 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 91 | if (!empty($value['parent_opportunity'])) { 92 | $args['ids'] = $value['parent_opportunity']; 93 | return OpportunityType::resolve($value, $args, $info); 94 | } else { 95 | return null; 96 | } 97 | }, 98 | ]); 99 | $config->addField('contacts', [ 100 | 'type' => new ContactsListType(), 101 | 'args' => argsHelper::entityArgsHelper('Contacts'), 102 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 103 | if (!empty($value['contacts'])) { 104 | $args['ids'] = $value['contacts']; 105 | return ContactsListType::resolve($value, $args, $info); 106 | } else { 107 | return null; 108 | } 109 | }, 110 | ]); 111 | $config->addField('accounts', [ 112 | 'type' => new AccountsListType(), 113 | 'args' => argsHelper::entityArgsHelper('Accounts'), 114 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 115 | if (!empty($value['accounts'])) { 116 | $args['ids'] = $value['accounts']; 117 | return AccountsListType::resolve($value, $args, $info); 118 | } else { 119 | return null; 120 | } 121 | }, 122 | ]); 123 | $config->addField('opportunities', [ 124 | 'type' => new OpportunitiesListType(), 125 | 'args' => argsHelper::entityArgsHelper('Opportunities'), 126 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 127 | if (!empty($value['opportunities'])) { 128 | $args['ids'] = $value['opportunities']; 129 | return OpportunitiesListType::resolve($value, $args, $info); 130 | } else { 131 | return null; 132 | } 133 | }, 134 | ]); 135 | $config->addField('notes', [ 136 | 'type' => new ListType(new NoteType()), 137 | 'args' => argsHelper::entityArgsHelper('Notes'), 138 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 139 | if (!empty($value['notes'])) { 140 | $args['ids'] = $value['notes']; 141 | return NotesListType::resolve($value, $args, $info); 142 | } else { 143 | return null; 144 | } 145 | }, 146 | ]); 147 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customCallType.php')) { 148 | require_once __DIR__ . '/../../../../../graphql/Schema/customCallType.php'; 149 | if (method_exists('customCallType', 'getFields')) { 150 | $customFields = customCallType::getFields(); 151 | foreach ($customFields as $field => $type) { 152 | $config->addField($field, $type); 153 | } 154 | } 155 | } 156 | } 157 | private function retrieveCall($id, $info) 158 | { 159 | global $sugar_config, $current_user; 160 | $moduleBean = \BeanFactory::getBean('Calls'); 161 | $moduleBean = $moduleBean->retrieve($id); 162 | 163 | 164 | $module_arr = array(); 165 | if ($moduleBean->id && $moduleBean->ACLAccess('view')) { 166 | $module_arr = crmHelper::getDefaultFieldsValues($moduleBean); 167 | if ($info != null) { 168 | $getFieldASTList = $info->getFieldASTList(); 169 | $queryFields = []; 170 | foreach ($getFieldASTList as $key => $value) { 171 | $queryFields[$value->getName()] = ""; 172 | } 173 | } 174 | if (isset($queryFields) && array_key_exists('created_user_details', $queryFields)) { 175 | $module_arr['created_user_details'] = $module_arr['created_by']; 176 | } 177 | 178 | if (isset($queryFields) && array_key_exists('assigned_user_details', $queryFields)) { 179 | $module_arr['assigned_user_details'] = $module_arr['assigned_user_id']; 180 | } 181 | 182 | if (isset($queryFields) && array_key_exists('modified_user_details', $queryFields)) { 183 | $module_arr['modified_user_details'] = $module_arr['modified_user_id']; 184 | } 185 | 186 | switch ($module_arr['parent_type']) { 187 | case 'Cases': 188 | $module_arr['parent_case'] = $module_arr['parent_id']; 189 | $module_arr['parent_contact'] = ''; 190 | $module_arr['parent_account'] = ''; 191 | $module_arr['parent_opportunity'] = ''; 192 | break; 193 | case 'Contacts': 194 | $module_arr['parent_contact'] = $module_arr['parent_id']; 195 | $module_arr['parent_account'] = ''; 196 | $module_arr['parent_opportunity'] = ''; 197 | $module_arr['parent_case'] = ''; 198 | break; 199 | case 'Accounts': 200 | $module_arr['parent_account'] = $module_arr['parent_id']; 201 | $module_arr['parent_contact'] = ''; 202 | $module_arr['parent_opportunity'] = ''; 203 | $module_arr['parent_case'] = ''; 204 | break; 205 | case 'Opportunities': 206 | $module_arr['parent_opportunity'] = $module_arr['parent_id']; 207 | $module_arr['parent_contact'] = ''; 208 | $module_arr['parent_account'] = ''; 209 | $module_arr['parent_case'] = ''; 210 | break; 211 | default: 212 | $module_arr['parent_opportunity'] = ''; 213 | $module_arr['parent_contact'] = ''; 214 | $module_arr['parent_account'] = ''; 215 | $module_arr['parent_case'] = ''; 216 | break; 217 | } 218 | if (isset($queryFields) && array_key_exists('contacts', $queryFields)) { 219 | $module_arr['contacts'] = array(); 220 | foreach ($moduleBean->get_linked_beans('contacts', 'Contact') as $contact) { 221 | $module_arr['contacts'][] = $contact->id; 222 | } 223 | } 224 | if (isset($queryFields) && array_key_exists('accounts', $queryFields)) { 225 | $module_arr['accounts'] = array(); 226 | foreach ($moduleBean->get_linked_beans('accounts', 'Account') as $account) { 227 | $module_arr['accounts'][] = $account->id; 228 | } 229 | } 230 | if (isset($queryFields) && array_key_exists('opportunities', $queryFields)) { 231 | $module_arr['opportunities'] = array(); 232 | foreach ($moduleBean->get_linked_beans('opportunities', 'Opportunity') as $opportunity) { 233 | $module_arr['opportunities'][] = $opportunity->id; 234 | } 235 | } 236 | if (isset($queryFields) && array_key_exists('notes', $queryFields)) { 237 | $module_arr['notes'] = array(); 238 | foreach ($moduleBean->get_linked_beans('notes') as $note) { 239 | $module_arr['notes'][] = $note->id; 240 | } 241 | } 242 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customCallType.php')) { 243 | require_once __DIR__ . '/../../../../../graphql/Schema/customCallType.php'; 244 | if (method_exists('customCallType', 'processFields')) { 245 | $module_arr = customCallType::processFields($moduleBean, $queryFields, $module_arr); 246 | } 247 | } 248 | 249 | return $module_arr; 250 | } else { 251 | return null; 252 | } 253 | } 254 | 255 | public function resolve($value = null, $args = [], $info = null) // implementing resolve function 256 | 257 | { 258 | if (isset($args['id']) && is_array($args['id'])) { 259 | foreach ($args as $key => $moduleBeanId) { 260 | if (isset($moduleBeanId) && is_array($moduleBeanId)) { 261 | foreach ($moduleBeanId as $key => $moduleBeanIdItem) { 262 | $resultArray[] = self::retrieveCall($moduleBeanIdItem, $info); 263 | } 264 | } elseif (!empty($moduleBeanId)) { 265 | $resultArray[] = self::retrieveCall($moduleBeanId, $info); 266 | } 267 | } 268 | 269 | return $resultArray; 270 | } elseif (!empty($args['id'])) { 271 | return self::retrieveCall($args['id'], $info); 272 | } 273 | } 274 | 275 | public function getName() 276 | { 277 | return 'call'; // important to use the real name here, it will be used later in the Schema 278 | } 279 | } 280 | -------------------------------------------------------------------------------- /graphql/Schema/NoteType.php: -------------------------------------------------------------------------------- 1 | $type) { 15 | $config->addField($field, $type); 16 | } 17 | $config->addField('created_user_details', [ 18 | 'type' => new UserType(), 19 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 20 | if (!empty($value['created_user_details'])) { 21 | $args['id'] = $value['created_user_details']; 22 | return UserType::resolve($value, $args, $info); 23 | } else { 24 | return null; 25 | } 26 | }, 27 | ]); 28 | $config->addField('assigned_user_details', [ 29 | 'type' => new UserType(), 30 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 31 | if (!empty($value['assigned_user_details'])) { 32 | $args['id'] = $value['assigned_user_details']; 33 | return UserType::resolve($value, $args, $info); 34 | } else { 35 | return null; 36 | } 37 | }, 38 | ]); 39 | $config->addField('modified_user_details', [ 40 | 'type' => new UserType(), 41 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 42 | if (!empty($value['modified_user_details'])) { 43 | $args['id'] = $value['modified_user_details']; 44 | return UserType::resolve($value, $args, $info); 45 | } else { 46 | return null; 47 | } 48 | }, 49 | ]); 50 | $config->addField('contact_details', [ 51 | 'type' => new ContactType(), 52 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 53 | if (!empty($value['contact_details'])) { 54 | $args['id'] = $value['contact_details']; 55 | return ContactType::resolve($value, $args, $info); 56 | } else { 57 | return null; 58 | } 59 | }, 60 | ]); 61 | $config->addField('parent_contact', [ 62 | 'type' => new ContactType(), 63 | 'args' => argsHelper::entityArgsHelper('Contacts'), 64 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 65 | if (!empty($value['parent_contact'])) { 66 | $args['id'] = $value['parent_contact']; 67 | return ContactType::resolve($value, $args, $info); 68 | } else { 69 | return null; 70 | } 71 | }, 72 | ]); 73 | $config->addField('parent_account', [ 74 | 'type' => new AccountType(), 75 | 'args' => argsHelper::entityArgsHelper('Accounts'), 76 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 77 | if (!empty($value['parent_account'])) { 78 | $args['id'] = $value['parent_opportunity']; 79 | return AccountType::resolve($value, $args, $info); 80 | } else { 81 | return null; 82 | } 83 | }, 84 | ]); 85 | $config->addField('parent_opportunity', [ 86 | 'type' => new OpportunityType(), 87 | 'args' => argsHelper::entityArgsHelper('Opportunities'), 88 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 89 | if (!empty($value['parent_opportunity'])) { 90 | $args['id'] = $value['parent_opportunity']; 91 | return OpportunityType::resolve($value, $args, $info); 92 | } else { 93 | return null; 94 | } 95 | }, 96 | ]); 97 | $config->addField('contacts', [ 98 | 'type' => new ContactsListType(), 99 | 'args' => argsHelper::entityArgsHelper('Contacts'), 100 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 101 | if (!empty($value['contacts'])) { 102 | $args['ids'] = $value['contacts']; 103 | return ContactsListType::resolve($value, $args, $info); 104 | } else { 105 | return null; 106 | } 107 | }, 108 | ]); 109 | $config->addField('accounts', [ 110 | 'type' => new AccountsListType(), 111 | 'args' => argsHelper::entityArgsHelper('Accounts'), 112 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 113 | if (!empty($value['accounts'])) { 114 | $args['ids'] = $value['accounts']; 115 | return AccountsListType::resolve($value, $args, $info); 116 | } else { 117 | return null; 118 | } 119 | }, 120 | ]); 121 | $config->addField('opportunities', [ 122 | 'type' => new OpportunitiesListType(), 123 | 'args' => argsHelper::entityArgsHelper('Opportunities'), 124 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 125 | if (!empty($value['opportunities'])) { 126 | $args['ids'] = $value['opportunities']; 127 | return OpportunitiesListType::resolve($value, $args, $info); 128 | } else { 129 | return null; 130 | } 131 | }, 132 | ]); 133 | $config->addField('cases', [ 134 | 'type' => new CasesListType(), 135 | 'args' => argsHelper::entityArgsHelper('Cases'), 136 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 137 | if (!empty($value['cases'])) { 138 | $args['ids'] = $value['cases']; 139 | return CasesListType::resolve($value, $args, $info); 140 | } else { 141 | return null; 142 | } 143 | }, 144 | ]); 145 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customNoteType.php')) { 146 | require_once __DIR__ . '/../../../../../graphql/Schema/customNoteType.php'; 147 | if (method_exists('customNoteType', 'getFields')) { 148 | $customFields = customNoteType::getFields(); 149 | foreach ($customFields as $field => $type) { 150 | $config->addField($field, $type); 151 | } 152 | } 153 | } 154 | } 155 | private function retrieveNote($id, $info) 156 | { 157 | global $sugar_config, $current_user; 158 | $moduleBean = \BeanFactory::getBean('Notes'); 159 | $moduleBean = $moduleBean->retrieve($id); 160 | 161 | $module_arr = array(); 162 | if ($moduleBean->id && $moduleBean->ACLAccess('view')) { 163 | $module_arr = \crmHelper::getDefaultFieldsValues($moduleBean); 164 | if ($info != null) { 165 | $getFieldASTList = $info->getFieldASTList(); 166 | $queryFields = []; 167 | foreach ($getFieldASTList as $key => $value) { 168 | $queryFields[$value->getName()] = ""; 169 | } 170 | } 171 | $module_arr['created_user_details'] = $module_arr['created_by']; 172 | $module_arr['assigned_user_details'] = $module_arr['assigned_user_id']; 173 | $module_arr['modified_user_details'] = $module_arr['modified_user_id']; 174 | switch ($module_arr['parent_type']) { 175 | case 'Contacts': 176 | $module_arr['parent_contact'] = $module_arr['parent_id']; 177 | $module_arr['parent_account'] = ''; 178 | $module_arr['parent_opportunity'] = ''; 179 | $module_arr['parent_case'] = ''; 180 | $module_arr['parent_email'] = ''; 181 | break; 182 | case 'Accounts': 183 | $module_arr['parent_account'] = $module_arr['parent_id']; 184 | $module_arr['parent_contact'] = ''; 185 | $module_arr['parent_opportunity'] = ''; 186 | $module_arr['parent_case'] = ''; 187 | $module_arr['parent_email'] = ''; 188 | break; 189 | case 'Opportunities': 190 | $module_arr['parent_opportunity'] = $module_arr['parent_id']; 191 | $module_arr['parent_contact'] = ''; 192 | $module_arr['parent_account'] = ''; 193 | $module_arr['parent_case'] = ''; 194 | $module_arr['parent_email'] = ''; 195 | break; 196 | case 'Cases': 197 | $module_arr['parent_opportunity'] = $module_arr['parent_id']; 198 | $module_arr['parent_contact'] = ''; 199 | $module_arr['parent_account'] = ''; 200 | $module_arr['parent_case'] = $module_arr['parent_id']; 201 | $module_arr['parent_email'] = ''; 202 | break; 203 | case 'Emails': 204 | $module_arr['parent_opportunity'] = ''; 205 | $module_arr['parent_contact'] = ''; 206 | $module_arr['parent_account'] = ''; 207 | $module_arr['parent_case'] = ''; 208 | $module_arr['parent_email'] = $module_arr['parent_id']; 209 | break; 210 | default: 211 | $module_arr['parent_opportunity'] = ''; 212 | $module_arr['parent_contact'] = ''; 213 | $module_arr['parent_account'] = ''; 214 | $module_arr['parent_case'] = ''; 215 | $module_arr['parent_email'] = ''; 216 | break; 217 | } 218 | if (isset($queryFields) && array_key_exists('contacts', $queryFields)) { 219 | $module_arr['contacts'] = array(); 220 | foreach ($moduleBean->get_linked_beans('contacts', 'Contact') as $contact) { 221 | $module_arr['contacts'][] = $contact->id; 222 | } 223 | } 224 | if (isset($queryFields) && array_key_exists('accounts', $queryFields)) { 225 | $module_arr['accounts'] = array(); 226 | foreach ($moduleBean->get_linked_beans('accounts', 'Account') as $account) { 227 | $module_arr['accounts'][] = $account->id; 228 | } 229 | } 230 | if (isset($queryFields) && array_key_exists('opportunities', $queryFields)) { 231 | $module_arr['opportunities'] = array(); 232 | foreach ($moduleBean->get_linked_beans('opportunities', 'Opportunity') as $opportunity) { 233 | $module_arr['opportunities'][] = $opportunity->id; 234 | } 235 | } 236 | if (isset($queryFields) && array_key_exists('cases', $queryFields)) { 237 | $module_arr['cases'] = array(); 238 | foreach ($moduleBean->get_linked_beans('cases', 'aCase') as $case) { 239 | $module_arr['cases'][] = $case->id; 240 | } 241 | } 242 | $module_arr['contact_details'] = array(); 243 | if (isset($queryFields) && array_key_exists('contact_details', $queryFields)) { 244 | $module_arr['contact_details'] = $moduleBean->contact_id; 245 | } 246 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customNoteType.php')) { 247 | require_once __DIR__ . '/../../../../../graphql/Schema/customNoteType.php'; 248 | if (method_exists('customNoteType', 'processFields')) { 249 | $module_arr = customNoteType::processFields($moduleBean, $queryFields, $module_arr); 250 | } 251 | } 252 | return $module_arr; 253 | } else { 254 | return null; 255 | } 256 | } 257 | 258 | public function resolve($value = null, $args = [], $info = null) // implementing resolve function 259 | { 260 | if (isset($args['id']) && is_array($args['id'])) { 261 | foreach ($args as $key => $moduleBeanId) { 262 | // error_log(__LINE__.print_r($args,1)); 263 | if (isset($moduleBeanId) && is_array($moduleBeanId)) { 264 | foreach ($moduleBeanId as $key => $moduleBeanIdItem) { 265 | $resultArray[] = self::retrieveNote($moduleBeanIdItem, $info); 266 | } 267 | } elseif (!empty($moduleBeanId)) { 268 | $resultArray[] = self::retrieveNote($moduleBeanId, $info); 269 | } 270 | } 271 | 272 | return $resultArray; 273 | } elseif (!empty($args['id'])) { 274 | return self::retrieveNote($args['id'], $info); 275 | } 276 | } 277 | 278 | public function getName() 279 | { 280 | return 'note'; // important to use the real name here, it will be used later in the Schema 281 | } 282 | } 283 | -------------------------------------------------------------------------------- /graphql/Schema/AccountType.php: -------------------------------------------------------------------------------- 1 | $type) { 43 | $config->addField($field, $type); 44 | } 45 | $config->addField('aos_quotes', [ 46 | 'type' => new ListType(new QuoteType()), 47 | 'args' => argsHelper::entityArgsHelper('AOS_Quotes'), 48 | 'resolve' => function ($value, $args, ResolveInfo $info) { 49 | if (!empty($value['aos_quotes'])) { 50 | $args['ids'] = $value['aos_quotes']; 51 | return QuoteType::resolve($value, $args, $info); 52 | } else { 53 | return null; 54 | } 55 | }, 56 | ]); 57 | $config->addField('calls', [ 58 | 'type' => new ListType(new CallType()), 59 | 'args' => argsHelper::entityArgsHelper('Calls'), 60 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 61 | if (!empty($value['calls'])) { 62 | $args['ids'] = $value['calls']; 63 | return CallsListType::resolve($value, $args, $info); 64 | } else { 65 | return null; 66 | } 67 | }, 68 | ]); 69 | $config->addField('cases', [ 70 | 'type' => new ListType(new CaseType()), 71 | 'args' => argsHelper::entityArgsHelper('Cases'), 72 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 73 | if (!empty($value['cases'])) { 74 | $args['ids'] = $value['cases']; 75 | return CasesListType::resolve($value, $args, $info); 76 | } else { 77 | return null; 78 | } 79 | }, 80 | ]); 81 | $config->addField('contacts', [ 82 | 'type' => new ContactsListType(), 83 | 'args' => argsHelper::entityArgsHelper('Contacts'), 84 | 'resolve' => function ($value, $args, ResolveInfo $info) { 85 | if (!empty($value['contacts'])) { 86 | $args['ids'] = $value['contacts']; 87 | return ContactsListType::resolve($value, $args, $info); 88 | } else { 89 | return null; 90 | } 91 | }, 92 | ]); 93 | $config->addField('opportunities', [ 94 | 'type' => new ListType(new OpportunityType()), 95 | 'args' => argsHelper::entityArgsHelper('Opportunities'), 96 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 97 | if (!empty($value['opportunities'])) { 98 | $args['ids'] = $value['opportunities']; 99 | return OpportunitiesListType::resolve($value, $args, $info); 100 | } else { 101 | return null; 102 | } 103 | }, 104 | ]); 105 | $config->addField('created_user_details', [ 106 | 'type' => new UserType(), 107 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 108 | if (!empty($value['created_user_details'])) { 109 | $args['id'] = $value['created_user_details']; 110 | return UserType::resolve($value, $args, $info); 111 | } else { 112 | return null; 113 | } 114 | }, 115 | ]); 116 | $config->addField('assigned_user_details', [ 117 | 'type' => new UserType(), 118 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 119 | if (!empty($value['assigned_user_details'])) { 120 | $args['id'] = $value['assigned_user_details']; 121 | return UserType::resolve($value, $args, $info); 122 | } else { 123 | return null; 124 | } 125 | }, 126 | ]); 127 | $config->addField('modified_user_details', [ 128 | 'type' => new UserType(), 129 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 130 | if (!empty($value['modified_user_details'])) { 131 | $args['id'] = $value['modified_user_details']; 132 | return UserType::resolve($value, $args, $info); 133 | } else { 134 | return null; 135 | } 136 | }, 137 | ]); 138 | $config->addField('notes', [ 139 | 'type' => new NotesListType(), 140 | 'args' => argsHelper::entityArgsHelper('Notes'), 141 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 142 | if (!empty($value['notes'])) { 143 | $args['ids'] = $value['notes']; 144 | return NotesListType::resolve($value, $args, $info); 145 | } else { 146 | return null; 147 | } 148 | }, 149 | ]); 150 | $config->addField('meetings', [ 151 | 'type' => new MeetingsListType(), 152 | 'args' => argsHelper::entityArgsHelper('Meetings'), 153 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 154 | if (!empty($value['meetings'])) { 155 | $args['ids'] = $value['meetings']; 156 | return MeetingsListType::resolve($value, $args, $info); 157 | } else { 158 | return null; 159 | } 160 | }, 161 | ]); 162 | $config->addField('tasks', [ 163 | 'type' => new TasksListType(), 164 | 'args' => argsHelper::entityArgsHelper('Tasks'), 165 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 166 | if (!empty($value['tasks'])) { 167 | $args['ids'] = $value['tasks']; 168 | return TasksListType::resolve($value, $args, $info); 169 | } else { 170 | return null; 171 | } 172 | }, 173 | ]); 174 | $config->addField('campaigns', [ 175 | 'type' => new CampaignsListType(), 176 | 'args' => argsHelper::entityArgsHelper('Campaigns'), 177 | 'resolve' => function ($value, array $args, ResolveInfo $info) { 178 | if (!empty($value['campaigns'][0])) { 179 | $args['ids'] = $value['campaigns']; 180 | return CampaignsListType::resolve($value, $args, $info); 181 | } else { 182 | return null; 183 | } 184 | }, 185 | ]); 186 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customAccountType.php')) { 187 | require_once __DIR__ . '/../../../../../graphql/Schema/customAccountType.php'; 188 | if (method_exists('customAccountType', 'getFields')) { 189 | $customFields = customAccountType::getFields(); 190 | foreach ($customFields as $field => $type) { 191 | $config->addField($field, $type); 192 | } 193 | } 194 | } 195 | } 196 | 197 | public function resolve($value = null, $args = [], ResolveInfo $info = null) 198 | { 199 | if (isset($args['id']) && is_array($args['id'])) { 200 | 201 | // We received a list of contacts to return 202 | foreach ($args as $key => $moduleBeanId) { 203 | if (isset($moduleBeanId) && is_array($moduleBeanId)) { 204 | foreach ($moduleBeanId as $key => $moduleBeanIdItem) { 205 | 206 | $resultArray[] = self::retrieve($moduleBeanIdItem, $info); 207 | } 208 | } elseif (!empty($moduleBeanId)) { 209 | $resultArray[] = self::retrieve($moduleBeanId, $info); 210 | } 211 | } 212 | 213 | return $resultArray; 214 | } else { 215 | if (!empty($args['id'])) { 216 | return self::retrieve($args['id'], $info); 217 | } 218 | } 219 | } 220 | 221 | public function retrieve($id, $info = null) // implementing resolve function 222 | 223 | { 224 | global $sugar_config, $current_user; 225 | $moduleBean = \BeanFactory::getBean('Accounts'); 226 | $moduleBean = $moduleBean->retrieve($id); 227 | $module_arr = array(); 228 | 229 | if ($moduleBean->id && $moduleBean->ACLAccess('view')) { 230 | $module_arr = crmHelper::getDefaultFieldsValues($moduleBean); 231 | if ($info != null) { 232 | $getFieldASTList = $info->getFieldASTList(); 233 | $queryFields = []; 234 | foreach ($getFieldASTList as $key => $value) { 235 | $queryFields[$value->getName()] = ""; 236 | } 237 | } 238 | if (isset($queryFields) && array_key_exists('contacts', $queryFields)) { 239 | $moduleBean->load_relationship('contacts'); 240 | $module_arr['contacts'] = array(); 241 | foreach ($moduleBean->contacts->getBeans() as $contact) { 242 | $module_arr['contacts'][] = $contact->id; 243 | } 244 | } 245 | if (isset($queryFields) && array_key_exists('aos_quotes', $queryFields)) { 246 | $moduleBean->load_relationship('aos_quotes'); 247 | $module_arr['aos_quotes'] = array(); 248 | foreach ($moduleBean->aos_quotes->getBeans() as $aos_quote) { 249 | $module_arr['aos_quotes'][] = $aos_quote->id; 250 | } 251 | } 252 | if (isset($queryFields) && array_key_exists('opportunities', $queryFields)) { 253 | $moduleBean->load_relationship('opportunities'); 254 | $module_arr['opportunities'] = array(); 255 | foreach ($moduleBean->opportunities->getBeans() as $opportunity) { 256 | $module_arr['opportunities'][] = $opportunity->id; 257 | } 258 | } 259 | if (isset($queryFields) && array_key_exists('calls', $queryFields)) { 260 | $module_arr['calls'] = array(); 261 | foreach ($moduleBean->get_linked_beans('calls') as $call) { 262 | $module_arr['calls'][] = $call->id; 263 | } 264 | } 265 | if (isset($queryFields) && array_key_exists('cases', $queryFields)) { 266 | $module_arr['cases'] = array(); 267 | foreach ($moduleBean->get_linked_beans('cases') as $case) { 268 | $module_arr['cases'][] = $case->id; 269 | } 270 | } 271 | if (isset($queryFields) && array_key_exists('notes', $queryFields)) { 272 | $module_arr['notes'] = array(); 273 | foreach ($moduleBean->get_linked_beans('notes') as $note) { 274 | $module_arr['notes'][] = $note->id; 275 | } 276 | } 277 | if (isset($queryFields) && array_key_exists('meetings', $queryFields)) { 278 | $module_arr['meetings'] = array(); 279 | foreach ($moduleBean->get_linked_beans('meetings') as $meeting) { 280 | $module_arr['meetings'][] = $meeting->id; 281 | } 282 | } 283 | if (isset($queryFields) && array_key_exists('tasks', $queryFields)) { 284 | $module_arr['tasks'] = array(); 285 | foreach ($moduleBean->get_linked_beans('tasks') as $task) { 286 | $module_arr['tasks'][] = $task->id; 287 | } 288 | } 289 | if (isset($queryFields) && array_key_exists('campaigns', $queryFields)) { 290 | $module_arr['campaigns'] = array(); 291 | foreach ($moduleBean->get_linked_beans('campaigns') as $campaign) { 292 | $module_arr['campaigns'][] = $campaign->id; 293 | } 294 | } 295 | if (isset($queryFields) && array_key_exists('modified_user_details', $queryFields)) { 296 | $module_arr['modified_user_details'] = $module_arr['modified_user_id']; 297 | } 298 | if (isset($queryFields) && array_key_exists('assigned_user_details', $queryFields)) { 299 | $module_arr['assigned_user_details'] = $module_arr['assigned_user_id']; 300 | } 301 | if (isset($queryFields) && array_key_exists('created_user_details', $queryFields)) { 302 | $module_arr['created_user_details'] = $module_arr['created_by']; 303 | } 304 | if (file_exists(__DIR__ . '/../../../../../graphql/Schema/customAccountType.php')) { 305 | require_once __DIR__ . '/../../../../../graphql/Schema/customAccountType.php'; 306 | if (method_exists('customAccountType', 'processFields')) { 307 | $module_arr = \customAccountType::processFields($moduleBean, $queryFields, $module_arr); 308 | } 309 | } 310 | return $module_arr; 311 | } else { 312 | return null; 313 | } 314 | } 315 | 316 | public function getName() 317 | { 318 | return 'account'; // important to use the real name here, it will be used later in the Schema 319 | } 320 | } 321 | --------------------------------------------------------------------------------