Replies: 4 comments
-
@onurkose - Interesting idea, but here is covered a very particular problem. Maybe a better approach is to create a separate Manager for this like for the Field, Table or Redis. Maybe you have time and vocation to jump on this feature a create a Pull Request ;) |
Beta Was this translation helpful? Give feedback.
-
Actually, it works as it is right now. No need a Manager or any other coding/improving your package. Maybe, rebing/graphql-laravel package may only need an upgrade to use your HasSettingsTable or Redis approach. But your package is just fine. |
Beta Was this translation helpful? Give feedback.
-
Also, the only reason why it's niche is because GraphQL is way under-utilized. That will change. ;) Thanks for sharing, I will be adopting your designs for Laravel Lighthouse. |
Beta Was this translation helpful? Give feedback.
-
Here is my directive for Laravel lighthouse. <?php
namespace App\GraphQL\Directives;
use App\Models\LocalModel;
use Glorand\Model\Settings\Exceptions\ModelSettingsException;
use Glorand\Model\Settings\Traits\HasSettingsField;
use GraphQL\Type\Definition\ResolveInfo;
use Nuwave\Lighthouse\Execution\Arguments\ArgumentSet;
use Nuwave\Lighthouse\Schema\Directives\BaseDirective;
use Nuwave\Lighthouse\Schema\Values\FieldValue;
use Nuwave\Lighthouse\Support\Contracts\ArgResolver;
use Nuwave\Lighthouse\Support\Contracts\FieldResolver;
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;
class SettingsDirective extends BaseDirective implements ArgResolver, FieldResolver
{
public function resolveField(FieldValue $fieldValue): FieldValue
{
return $fieldValue->setResolver(
function ($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) {
/** @var HasSettingsField $root */
return $root->settings()->get();
}
);
}
/**
* @param LocalModel|HasSettingsField $root
* @param mixed|ArgumentSet|ArgumentSet[] $value
* @return LocalModel|HasSettingsField
* @throws ModelSettingsException
*/
public function __invoke($root, $value)
{
$root->settings()->setMultiple($value->toArray());
return $root;
}
} In Lighthouse it is used like so: type ProjectSettings {
locale: String!
}
type Project implements BaseModel {
id: ID!
name: String!
settings: ProjectSettings! @settings
}
extend type Query @middleware(checks: ["auth:api"]) {
project(id: ID! @eq): Project @find
}
extend type Mutation @middleware(checks: ["auth:api"]) {
projectCreate(input: ProjectCreateInput! @spread): Project! @create
projectUpdate(id: ID!, input: ProjectUpdateInput! @spread): Project! @update
projectDelete(id: ID!): Project! @delete
}
input ProjectSettingsInput {
locale: String @rules(apply: ["size:5", "regex:/^[a-z]{2}-[A-Z]{2}$/", "in:en-CA,fr-CA"])
}
input ProjectCreateInput {
name: String! @rules(apply: ["between:3,250"])
settings: ProjectSettingsInput @settings
}
input ProjectUpdateInput {
name: String @rules(apply: ["between:3,250"])
settings: ProjectSettingsInput @settings
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
Thank you for this package.
I am using rebing/graphql-laravel for my API works.
I've figured out how to integrate your package into GraphQL type declarations. This one uses HasSettingsField option.
Here is the sample code:
This is the type declaration for settings iteration:
Beta Was this translation helpful? Give feedback.
All reactions