Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. composer require mll-lab/graphql-php-scalars
  2.  
  3. php artisan lighthouse:mutation ClassNameMutator
  4.  
  5. use AppModelsModelName;
  6.  
  7. ...
  8.  
  9. public function createOrUpdate($rootValue, array $args, GraphQLContext $context)
  10. {
  11. $model = ModelName::find($args['id']);
  12. if ($model == null) {$model = new ModelName();}
  13. $model->fill($args)->save();
  14. $model = ModelName::select($args['field'])->find($args['id']);
  15.  
  16. return $model;
  17. }
  18.  
  19. "A Json string with format normal Array"
  20. scalar Mixed @scalar(class: "MLL\GraphQLScalars\Mixed")
  21.  
  22. ...
  23.  
  24. type Mutation {
  25. uoiModel(input: uoi! @spread): Mixed @field(resolver: "ClassNameMutator@createOrUpdate")
  26. }
  27. input uoi{
  28. id: ID! //Поле таблицы в запрос
  29. otherField: ID //Поле таблицы в запрос
  30. field: Mixed //Поля, которые нужны в ответ, указываются в виде простого массива ["field1","field2","fieldn"]
  31. }
  32.  
  33. mutation {
  34. uoiModel(
  35. input: {
  36. id: 900003
  37. status: 49
  38. field: [
  39. "id",
  40. "status"
  41. ]
  42. }
  43. )
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement