Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- composer require mll-lab/graphql-php-scalars
- php artisan lighthouse:mutation ClassNameMutator
- use AppModelsModelName;
- ...
- public function createOrUpdate($rootValue, array $args, GraphQLContext $context)
- {
- $model = ModelName::find($args['id']);
- if ($model == null) {$model = new ModelName();}
- $model->fill($args)->save();
- $model = ModelName::select($args['field'])->find($args['id']);
- return $model;
- }
- "A Json string with format normal Array"
- scalar Mixed @scalar(class: "MLL\GraphQLScalars\Mixed")
- ...
- type Mutation {
- uoiModel(input: uoi! @spread): Mixed @field(resolver: "ClassNameMutator@createOrUpdate")
- }
- input uoi{
- id: ID! //Поле таблицы в запрос
- otherField: ID //Поле таблицы в запрос
- field: Mixed //Поля, которые нужны в ответ, указываются в виде простого массива ["field1","field2","fieldn"]
- }
- mutation {
- uoiModel(
- input: {
- id: 900003
- status: 49
- field: [
- "id",
- "status"
- ]
- }
- )
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement