mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-24 13:56:04 +03:00
36 lines
744 B
PHP
36 lines
744 B
PHP
<?php
|
|
|
|
interface Resolver {
|
|
public function resolve($rootValue, $args, $context);
|
|
}
|
|
|
|
class Addition implements Resolver
|
|
{
|
|
public function resolve($rootValue, $args, $context)
|
|
{
|
|
return $args['x'] + $args['y'];
|
|
}
|
|
}
|
|
|
|
class Echoer implements Resolver
|
|
{
|
|
public function resolve($rootValue, $args, $context)
|
|
{
|
|
return $rootValue['prefix'].$args['message'];
|
|
}
|
|
}
|
|
|
|
return [
|
|
'sum' => function($rootValue, $args, $context) {
|
|
$sum = new Addition();
|
|
|
|
return $sum->resolve($rootValue, $args, $context);
|
|
},
|
|
'echo' => function($rootValue, $args, $context) {
|
|
$echo = new Echoer();
|
|
|
|
return $echo->resolve($rootValue, $args, $context);
|
|
},
|
|
'prefix' => 'You said: ',
|
|
];
|