2017-07-07 22:26:01 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
interface Resolver {
|
2019-06-30 21:54:56 +03:00
|
|
|
public function resolve($rootValue, $args, $context);
|
2017-07-07 22:26:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
class Addition implements Resolver
|
|
|
|
{
|
2019-06-30 21:54:56 +03:00
|
|
|
public function resolve($rootValue, $args, $context)
|
2017-07-07 22:26:01 +03:00
|
|
|
{
|
|
|
|
return $args['x'] + $args['y'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Echoer implements Resolver
|
|
|
|
{
|
2019-06-30 21:54:56 +03:00
|
|
|
public function resolve($rootValue, $args, $context)
|
2017-07-07 22:26:01 +03:00
|
|
|
{
|
2019-06-30 21:54:56 +03:00
|
|
|
return $rootValue['prefix'].$args['message'];
|
2017-07-07 22:26:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
2019-06-30 21:54:56 +03:00
|
|
|
'sum' => function($rootValue, $args, $context) {
|
2017-07-07 22:26:01 +03:00
|
|
|
$sum = new Addition();
|
|
|
|
|
2019-06-30 21:54:56 +03:00
|
|
|
return $sum->resolve($rootValue, $args, $context);
|
2017-07-07 22:26:01 +03:00
|
|
|
},
|
2019-06-30 21:54:56 +03:00
|
|
|
'echo' => function($rootValue, $args, $context) {
|
2017-07-07 22:26:01 +03:00
|
|
|
$echo = new Echoer();
|
|
|
|
|
2019-06-30 21:54:56 +03:00
|
|
|
return $echo->resolve($rootValue, $args, $context);
|
2017-07-07 22:26:01 +03:00
|
|
|
},
|
|
|
|
'prefix' => 'You said: ',
|
|
|
|
];
|