This is just a simple in-memory data holder for the sake of example. Data layer for real app may use Doctrine or query the database directly (e.g. in CQRS style)
コード例 #1
0
ファイル: QueryType.php プロジェクト: webonyx/graphql-php
 public function lastStoryPosted()
 {
     return DataSource::findLatestStory();
 }
コード例 #2
0
ファイル: StoryType.php プロジェクト: aeshion/ZeroPHP
 public function comments(Story $story, $args)
 {
     $args += ['after' => null];
     return DataSource::findComments($story->id, $args['limit'], $args['after']);
 }
コード例 #3
0
ファイル: UserType.php プロジェクト: webonyx/graphql-php
 public function lastStoryPosted(User $user)
 {
     return DataSource::findLastStoryFor($user->id);
 }
コード例 #4
0
ファイル: CommentType.php プロジェクト: aeshion/ZeroPHP
 public function totalReplyCount(Comment $comment)
 {
     return DataSource::countReplies($comment->id);
 }
コード例 #5
0
ファイル: graphql.php プロジェクト: webonyx/graphql-php
if (!empty($_GET['debug'])) {
    // Enable additional validation of type configs
    // (disabled by default because it is costly)
    Config::enableValidation();
    // Catch custom errors (to report them in query results if debugging is enabled)
    $phpErrors = [];
    set_error_handler(function ($severity, $message, $file, $line) use(&$phpErrors) {
        $phpErrors[] = new ErrorException($message, 0, $severity, $file, $line);
    });
}
try {
    // Initialize our fake data source
    DataSource::init();
    // Prepare context that will be available in all field resolvers (as 3rd argument):
    $appContext = new AppContext();
    $appContext->viewer = DataSource::findUser('1');
    // simulated "currently logged-in user"
    $appContext->rootUrl = 'http://localhost:8080';
    $appContext->request = $_REQUEST;
    // Parse incoming query and variables
    if (isset($_SERVER['CONTENT_TYPE']) && strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== false) {
        $raw = file_get_contents('php://input') ?: '';
        $data = json_decode($raw, true);
    } else {
        $data = $_REQUEST;
    }
    $data += ['query' => null, 'variables' => null];
    if (null === $data['query']) {
        $data['query'] = '{hello}';
    }
    // GraphQL schema to be passed to query executor: