<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [toc] #### 預備知識 本文檔假定您熟悉GraphQL概念,如果沒有,可以先學[官網](http://graphql.org/learn/)的GraphQL介紹。 #### 安裝 Using [composer](https://getcomposer.org/doc/00-intro.md),`composer.json` ~~~ { "require": { "webonyx/graphql-php": "^0.8" } } ~~~ #### 更新 [upgrade instructions](https://github.com/webonyx/graphql-php/blob/master/UPGRADE.md) #### 安裝工具(可選) 雖然可以使用常規的`HTTP`與`GraphQL API`通訊,但是使用[`GraphiQL`](https://github.com/graphql/graphiql),用瀏覽器內的工具探索`GraphQL APIs` 更方便的方式是安裝chrome 擴展。 * [ GraphiQL Feen](https://chrome.google.com/webstore/detail/graphiql-feen/mcbfdonlkfpbfdpimkjilhdneikhfklp) * [ChromeiQL](https://chrome.google.com/webstore/detail/chromeiql/fkkiamalmpiidkljmicmjfbieiclmeij) #### Hello World 讓我們創建類型系統來處理下面的簡單查詢。 ~~~ query { echo(message: "Hello World") } ~~~ 為此我們需要定義帶有字段`echo`的對象類型。 ~~~ use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\Type; $queryType = new ObjectType([ 'name' => 'Query', 'fields' => [ 'echo' => [ 'type' => Type::string(), 'args' => [ 'message' => Type::nonNull(Type::string()), ], 'resolve' => function ($root, $args) { return $root['prefix'] . $args['message']; } ], ], ]); ~~~ (Note:類型定義能夠使用不同的方式,這里為了簡單使用內聯方式定義) 有意思的部分是這里字段定義的`resolve`選項,它負責返回字段的值,`scalar`類型字段的值會直接包含到響應中,然而如果是`complex`類型(`objects`, `interfaces`, `unions`)的值會被傳給它下面嵌套的字段解析器。 現在類型已經準備好,讓我們創建GraphQL服務端點。 ~~~ use GraphQL\GraphQL; use GraphQL\Schema; $schema = new Schema([ 'query' => $queryType ]); $rawInput = file_get_contents('php://input'); try { $rootValue = ['prefix' => 'You said: ']; $result = GraphQL::execute($schema, $rawInput, $rootValue); } catch (\Exception $e) { $result = [ 'error' => [ 'message' => $e->getMessage() ] ]; } header('Content-Type: application/json; charset=UTF-8'); echo json_encode($result); ~~~ 運行代碼 ~~~ php -S localhost:8000 graphql.php curl http://localhost:8000 -d "query { echo(message: \"Hello World\") }" ~~~ hello world示例只是很簡單的例子,可以查看下一例子,它更接近現實生活的應用程序。 #### Blog Example 通過更容易從全功能的例子開始,然后返回文檔開始你自己的工作。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看