-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1711 from bakaphp/development
v1.0-RC5
- Loading branch information
Showing
93 changed files
with
2,445 additions
and
831 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
"hashtable", | ||
"indice", | ||
"Meili", | ||
"Metafield", | ||
"Nuwave" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/Console/Commands/Connectors/Zoho/ZohoLeadsDownloadCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Console\Commands\Connectors\Zoho; | ||
|
||
use Baka\Traits\KanvasJobsTrait; | ||
use Illuminate\Console\Command; | ||
use Kanvas\Apps\Models\Apps; | ||
use Kanvas\Companies\Models\Companies; | ||
use Kanvas\Connectors\Zoho\Actions\DownloadAllZohoLeadAction; | ||
use Kanvas\Guild\Leads\Models\LeadReceiver; | ||
|
||
class ZohoLeadsDownloadCommand extends Command | ||
{ | ||
use KanvasJobsTrait; | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'kanvas:guild-zoho-lead-sync {app_id} {company_id} {receiver_id} {page=50} {leadsPerPage=200}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string|null | ||
*/ | ||
protected $description = 'Download all leads from Zoho to this branch'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
$app = Apps::getById((int) $this->argument('app_id')); | ||
$this->overwriteAppService($app); | ||
$company = Companies::getById((int) $this->argument('company_id')); | ||
$leadReceiver = LeadReceiver::getByIdFromCompanyApp((int) $this->argument('receiver_id'), $company, $app); | ||
$page = (int) $this->argument('page'); | ||
$leadsPerPage = (int) $this->argument('leadsPerPage'); | ||
|
||
$downloadAllLeads = new DownloadAllZohoLeadAction($app, $company, $leadReceiver); | ||
$downloadAllLeads->execute($page, $leadsPerPage); | ||
|
||
$this->info($downloadAllLeads->getTotalLeadsProcessed() . ' leads downloaded from Zoho to ' . $leadReceiver->name); | ||
|
||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/GraphQL/ActionEngine/Subscriptions/TaskItemSubscription.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\GraphQL\ActionEngine\Subscriptions; | ||
|
||
use Exception; | ||
use Illuminate\Http\Request; | ||
use Kanvas\ActionEngine\Tasks\Models\TaskListItem; | ||
use Kanvas\Users\Repositories\UsersRepository; | ||
use Nuwave\Lighthouse\Execution\ResolveInfo; | ||
use Nuwave\Lighthouse\Schema\Types\GraphQLSubscription; | ||
use Nuwave\Lighthouse\Subscriptions\Subscriber; | ||
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext; | ||
|
||
class TaskItemSubscription extends GraphQLSubscription | ||
{ | ||
public function authorize(Subscriber $subscriber, Request $request): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function filter(Subscriber $subscriber, mixed $root): bool | ||
{ | ||
try { | ||
UsersRepository::belongsToCompany($subscriber->context->user, $root->companyAction->company); | ||
} catch (Exception $e) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function resolve( | ||
mixed $root, | ||
array $args, | ||
GraphQLContext $context, | ||
ResolveInfo $resolveInfo | ||
): TaskListItem { | ||
return $root; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\GraphQL\Directives; | ||
|
||
use GraphQL\Deferred; | ||
use Illuminate\Support\Carbon; | ||
use Illuminate\Support\Facades\Redis; | ||
use Nuwave\Lighthouse\Cache\CacheDirective as CacheCacheDirective; | ||
use Nuwave\Lighthouse\Execution\Resolved; | ||
use Nuwave\Lighthouse\Execution\ResolveInfo; | ||
use Nuwave\Lighthouse\Schema\Values\FieldValue; | ||
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext; | ||
|
||
class CacheRedisDirective extends CacheCacheDirective | ||
{ | ||
public static function definition(): string | ||
{ | ||
return /** @lang GraphQL */ <<<'GRAPHQL' | ||
""" | ||
Cache the result of a resolver. | ||
Place this after other field middleware to ensure it caches the correct transformed value. | ||
""" | ||
directive @cacheRedis( | ||
""" | ||
Set the duration it takes for the cache to expire in seconds. | ||
If not given, the result will be stored forever. | ||
""" | ||
maxAge: Int | ||
""" | ||
Limit access to cached data to the currently authenticated user. | ||
When the field is accessible by guest users, this will not have | ||
any effect, they will access a shared cache. | ||
""" | ||
private: Boolean = false | ||
) on FIELD_DEFINITION | ||
GRAPHQL; | ||
} | ||
|
||
public function handleField(FieldValue $fieldValue): void | ||
{ | ||
$rootCacheKey = $fieldValue->getParent()->cacheKey(); | ||
$shouldUseTags = $this->shouldUseTags(); | ||
$maxAge = $this->directiveArgValue('maxAge'); | ||
$isPrivate = $this->directiveArgValue('private', false); | ||
|
||
$fieldValue->wrapResolver(fn (callable $resolver): \Closure => function (mixed $root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($rootCacheKey, $shouldUseTags, $resolver, $maxAge, $isPrivate) { | ||
$parentName = $resolveInfo->parentType->name; | ||
$rootID = $root !== null && $rootCacheKey !== null | ||
? data_get($root, $rootCacheKey) | ||
: null; | ||
$fieldName = $resolveInfo->fieldName; | ||
$path = $resolveInfo->path; | ||
|
||
$cache = Redis::connection('graph-cache'); | ||
|
||
$cacheKey = $this->cacheKeyAndTags->key( | ||
$context->user(), | ||
$isPrivate, | ||
$parentName, | ||
$rootID, | ||
$fieldName, | ||
$args, | ||
$path, | ||
); | ||
|
||
// We found a matching value in the cache, so we can just return early without actually running the query. | ||
$value = $cache->get($cacheKey); | ||
if ($value !== null) { | ||
// Deferring the result will allow nested deferred resolves to be bundled together, see https://github.com/nuwave/lighthouse/pull/2270#discussion_r1072414584. | ||
return new Deferred(static fn () => $value); | ||
} | ||
|
||
// In Laravel cache, null is considered a non-existent value, see https://laravel.com/docs/9.x/cache#checking-for-item-existence: | ||
// > The `has` method [...] will also return false if the item exists but its value is null. | ||
// | ||
// If caching `null` value becomes something worthwhile, one possible way to achieve it is to | ||
// encapsulate the `$result` at writing time : | ||
// | ||
// $storeInCache = static function ($result) use ($cacheKey, $maxAge, $cache): void { | ||
// $value = ['rawValue' => $result]; | ||
// $maxAge | ||
// ? $cache->put($cacheKey, $value, Carbon::now()->addSeconds($maxAge)) | ||
// : $cache->forever($cacheKey, $value); | ||
// }; | ||
// | ||
// and restoring original value back at reading : | ||
// | ||
// if (is_array($value) && array_key_exists('rawValue', $value)) { // don't use isset ! | ||
// return $value['rawValue']; | ||
// } | ||
// | ||
// Such a change would introduce some potential BC, if for instance cached value was already containing | ||
// an object with a `rawValue` key prior the implementation change. A possible workaround is to choose a | ||
// less collision-probable key instead of `rawValue` (e.g. "lighthouse:rawValue"). | ||
|
||
$resolved = $resolver($root, $args, $context, $resolveInfo); | ||
|
||
$storeInCache = $maxAge | ||
? static fn ($result): bool => $cache->set($cacheKey, $result, $maxAge) | ||
: static fn ($result): bool => $cache->set($cacheKey, $result); | ||
|
||
Resolved::handle($resolved, $storeInCache); | ||
|
||
return $resolved; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.