mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-06 07:49:24 +03:00
Deployed 961e44c with MkDocs version: 0.15.3
This commit is contained in:
parent
d10aba97b7
commit
292b7e035b
@ -157,20 +157,6 @@
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../error-handling/">Handling Errors</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../data-fetching/">Fetching Data</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../best-practices/">Best Practices</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
@ -180,10 +166,10 @@
|
||||
|
||||
<ul>
|
||||
|
||||
<li class="toctree-l3"><a href="#relay">Relay</a></li>
|
||||
<li class="toctree-l3"><a href="#integrations">Integrations</a></li>
|
||||
|
||||
|
||||
<li class="toctree-l3"><a href="#graphiql">GraphiQL</a></li>
|
||||
<li class="toctree-l3"><a href="#tools">Tools</a></li>
|
||||
|
||||
|
||||
</ul>
|
||||
@ -223,8 +209,19 @@
|
||||
<div role="main">
|
||||
<div class="section">
|
||||
|
||||
<h1 id="relay">Relay</h1>
|
||||
<h1 id="graphiql">GraphiQL</h1>
|
||||
<h1 id="integrations">Integrations</h1>
|
||||
<ul>
|
||||
<li><a href="https://github.com/ivome/graphql-relay-php">Integration with Relay</a></li>
|
||||
<li><a href="https://github.com/Folkloreatelier/laravel-graphql">Integration with Laravel 5</a> + <a href="https://github.com/nuwave/laravel-graphql-relay">Relay Helpers for Laravel</a></li>
|
||||
<li><a href="https://github.com/overblog/GraphQLBundle">Symfony Bundle</a> by Overblog</li>
|
||||
</ul>
|
||||
<h1 id="tools">Tools</h1>
|
||||
<ul>
|
||||
<li><a href="https://github.com/graphql/graphiql">GraphiQL</a> - An in-browser IDE for exploring GraphQL</li>
|
||||
<li><a href="https://chrome.google.com/webstore/detail/chromeiql/fkkiamalmpiidkljmicmjfbieiclmeij">ChromeiQL</a>
|
||||
or <a href="https://chrome.google.com/webstore/detail/graphiql-feen/mcbfdonlkfpbfdpimkjilhdneikhfklp">GraphiQL Feen</a> -
|
||||
GraphiQL as Google Chrome extension</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@ -233,7 +230,7 @@
|
||||
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
|
||||
|
||||
|
||||
<a href="../best-practices/" class="btn btn-neutral" title="Best Practices"><span class="icon icon-circle-arrow-left"></span> Previous</a>
|
||||
<a href="../error-handling/" class="btn btn-neutral" title="Handling Errors"><span class="icon icon-circle-arrow-left"></span> Previous</a>
|
||||
|
||||
</div>
|
||||
|
||||
@ -259,7 +256,7 @@
|
||||
<span class="rst-current-version" data-toggle="rst-current-version">
|
||||
|
||||
|
||||
<span><a href="../best-practices/" style="color: #fcfcfc;">« Previous</a></span>
|
||||
<span><a href="../error-handling/" style="color: #fcfcfc;">« Previous</a></span>
|
||||
|
||||
|
||||
</span>
|
||||
|
@ -173,20 +173,6 @@
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../data-fetching/">Fetching Data</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../best-practices/">Best Practices</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
@ -334,14 +320,17 @@ when it makes sense to return <code>500</code> error code for GraphQL endpoint:<
|
||||
// ...
|
||||
]);
|
||||
|
||||
$result = GraphQL::execute($schema, $query);
|
||||
$body = GraphQL::execute($schema, $query);
|
||||
$status = 200;
|
||||
} catch(\Exception $e) {
|
||||
header('Content-Type: application/json', true, 500);
|
||||
echo json_encode([
|
||||
$body = json_encode([
|
||||
'message' => 'Unexpected error'
|
||||
]);
|
||||
exit;
|
||||
$status = 500;
|
||||
}
|
||||
|
||||
header('Content-Type: application/json', true, $status);
|
||||
echo json_encode($body);
|
||||
</code></pre>
|
||||
|
||||
</div>
|
||||
@ -350,7 +339,7 @@ when it makes sense to return <code>500</code> error code for GraphQL endpoint:<
|
||||
|
||||
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
|
||||
|
||||
<a href="../data-fetching/" class="btn btn-neutral float-right" title="Fetching Data">Next <span class="icon icon-circle-arrow-right"></span></a>
|
||||
<a href="../complementary-tools/" class="btn btn-neutral float-right" title="Complementary Tools">Next <span class="icon icon-circle-arrow-right"></span></a>
|
||||
|
||||
|
||||
<a href="../executing-queries/" class="btn btn-neutral" title="Executing Queries"><span class="icon icon-circle-arrow-left"></span> Previous</a>
|
||||
@ -382,7 +371,7 @@ when it makes sense to return <code>500</code> error code for GraphQL endpoint:<
|
||||
<span><a href="../executing-queries/" style="color: #fcfcfc;">« Previous</a></span>
|
||||
|
||||
|
||||
<span style="margin-left: 15px"><a href="../data-fetching/" style="color: #fcfcfc">Next »</a></span>
|
||||
<span style="margin-left: 15px"><a href="../complementary-tools/" style="color: #fcfcfc">Next »</a></span>
|
||||
|
||||
</span>
|
||||
</div>
|
||||
|
@ -173,20 +173,6 @@
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../error-handling/">Handling Errors</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../data-fetching/">Fetching Data</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../best-practices/">Best Practices</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
@ -266,7 +252,7 @@ See also section on <a href="../error-handling/">error handling</a>.</p>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>queryString</td>
|
||||
<td><code>string</code> or <code>GraphQL\Language\AST\Document</code></td>
|
||||
<td><code>string</code> or <code>GraphQL\Language\AST\DocumentNode</code></td>
|
||||
<td><strong>Required.</strong> Actual GraphQL query string to be parsed, validated and executed. If you parse query elsewhere before executing - pass corresponding ast document here to avoid new parsing.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -73,6 +73,9 @@
|
||||
<li class="toctree-l3"><a href="#installation">Installation</a></li>
|
||||
|
||||
|
||||
<li class="toctree-l3"><a href="#upgrading">Upgrading</a></li>
|
||||
|
||||
|
||||
<li class="toctree-l3"><a href="#install-tools-optional">Install Tools (optional)</a></li>
|
||||
|
||||
|
||||
@ -176,20 +179,6 @@
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../error-handling/">Handling Errors</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../data-fetching/">Fetching Data</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../best-practices/">Best Practices</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
@ -240,14 +229,16 @@ first learn about GraphQL on <a href="http://graphql.org/learn/">official websi
|
||||
add <code>composer.json</code> file to your project root folder with following contents:</p>
|
||||
<pre><code>{
|
||||
"require": {
|
||||
"webonyx/graphql-php": "^0.7"
|
||||
"webonyx/graphql-php": "^0.8"
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
<p>and run <code>composer install</code>. </p>
|
||||
<p>If you already have composer.json file - simply run: <code>composer require webonyx/graphql-php</code></p>
|
||||
<p>If you are upgrading, see <a href="https://github.com/webonyx/graphql-php/blob/master/UPGRADE.md">upgrade instructions</a></p>
|
||||
<p>If you already have composer.json file - simply run: <code>composer require webonyx/graphql-php="^0.8"</code></p>
|
||||
<h1 id="upgrading">Upgrading</h1>
|
||||
<p>We try to keep library releases backwards compatible. But when breaking changes are inevitable
|
||||
they are explained in <a href="https://github.com/webonyx/graphql-php/blob/master/UPGRADE.md">upgrade instructions</a>.</p>
|
||||
<h1 id="install-tools-optional">Install Tools (optional)</h1>
|
||||
<p>While it is possible to communicate with GraphQL API using regular HTTP tools it is way
|
||||
more convenient for humans to use <a href="https://github.com/graphql/graphiql">GraphiQL</a> - an in-browser
|
||||
@ -290,7 +281,7 @@ $queryType = new ObjectType([
|
||||
</code></pre>
|
||||
|
||||
<p>(Note: type definition can be expressed in <a href="../type-system/#type-definition-styles">different styles</a>,
|
||||
including <strong>inheritance</strong>, <strong>composition</strong> and <strong>inline</strong>. This example uses <strong>inline</strong> style for simplicity)</p>
|
||||
but this example uses <strong>inline</strong> style for simplicity)</p>
|
||||
<p>The interesting piece here is <code>resolve</code> option of field definition. It is responsible for retuning
|
||||
value of our field. Values of <strong>scalar</strong> fields will be directly included in response while values of
|
||||
<strong>complex</strong> fields (objects, interfaces, unions) will be passed down to nested field resolvers
|
||||
|
30
index.html
30
index.html
@ -67,6 +67,8 @@
|
||||
|
||||
<li><a class="toctree-l4" href="#current-status">Current Status</a></li>
|
||||
|
||||
<li><a class="toctree-l4" href="#github">Github</a></li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
@ -169,20 +171,6 @@
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="error-handling/">Handling Errors</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="data-fetching/">Fetching Data</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="best-practices/">Best Practices</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
@ -225,6 +213,11 @@
|
||||
<div role="main">
|
||||
<div class="section">
|
||||
|
||||
<p><a href="https://github.com/webonyx/graphql-php"><img alt="GitHub stars" src="https://img.shields.io/github/stars/webonyx/graphql-php.svg?style=social&label=Star" /></a>
|
||||
<a href="https://travis-ci.org/webonyx/graphql-php"><img alt="Build Status" src="https://travis-ci.org/webonyx/graphql-php.svg?branch=master" /></a>
|
||||
<a href="https://coveralls.io/github/webonyx/graphql-php"><img alt="Coverage Status" src="https://coveralls.io/repos/github/webonyx/graphql-php/badge.svg" /></a>
|
||||
<a href="https://packagist.org/packages/webonyx/graphql-php"><img alt="Latest Stable Version" src="https://poser.pugx.org/webonyx/graphql-php/version" /></a>
|
||||
<a href="https://packagist.org/packages/webonyx/graphql-php"><img alt="License" src="https://poser.pugx.org/webonyx/graphql-php/license" /></a></p>
|
||||
<h1 id="about-graphql">About GraphQL</h1>
|
||||
<p>GraphQL is a modern way to build HTTP APIs consumed by web and mobile clients.
|
||||
It is intended to be a replacement for REST and SOAP APIs (even for <strong>existing applications</strong>).</p>
|
||||
@ -243,7 +236,7 @@ are used. Instead it provides tools for creating rich API for your existing app.
|
||||
<p>These tools include:</p>
|
||||
<ul>
|
||||
<li>Primitives to express your app as a Type System</li>
|
||||
<li>Tools for validation and introspection of this Type System (for compatibility with tools like <a href="./complementary-tools/#graphiql">GraphiQL</a>)</li>
|
||||
<li>Tools for validation and introspection of this Type System (for compatibility with tools like <a href="./complementary-tools/#tools">GraphiQL</a>)</li>
|
||||
<li>Tools for parsing, validating and executing GraphQL queries against this Type System</li>
|
||||
<li>Rich error reporting, including query validation and execution errors</li>
|
||||
<li>Optional tools for parsing GraphQL Schema Definition language</li>
|
||||
@ -251,10 +244,13 @@ are used. Instead it provides tools for creating rich API for your existing app.
|
||||
<p>Also several <a href="./complementary-tools/">complementary tools</a> are available which provide integrations with
|
||||
existing PHP frameworks, add support for Relay, etc.</p>
|
||||
<h2 id="current-status">Current Status</h2>
|
||||
<p>Current version supports all features described by GraphQL specification
|
||||
<p>First version of this library (v0.1) was released on August 10th 2015.</p>
|
||||
<p>Current version (v0.7) supports all features described by GraphQL specification
|
||||
(including April 2016 add-ons) as well as some experimental features like
|
||||
Schema Language parser.</p>
|
||||
<p>Ready for real-world usage.</p>
|
||||
<h2 id="github">Github</h2>
|
||||
<p>Project source code is <a href="https://github.com/webonyx/graphql-php">hosted on GitHub</a>.</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@ -300,5 +296,5 @@ Schema Language parser.</p>
|
||||
|
||||
<!--
|
||||
MkDocs version : 0.15.3
|
||||
Build Date UTC : 2016-11-08 13:41:37.144000
|
||||
Build Date UTC : 2016-11-25 11:10:09.813000
|
||||
-->
|
||||
|
File diff suppressed because one or more lines are too long
14
search.html
14
search.html
@ -153,20 +153,6 @@
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="error-handling/">Handling Errors</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="data-fetching/">Fetching Data</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="best-practices/">Best Practices</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
|
46
sitemap.xml
46
sitemap.xml
@ -4,7 +4,7 @@
|
||||
|
||||
<url>
|
||||
<loc>None/</loc>
|
||||
<lastmod>2016-11-08</lastmod>
|
||||
<lastmod>2016-11-25</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
<url>
|
||||
<loc>None/getting-started/</loc>
|
||||
<lastmod>2016-11-08</lastmod>
|
||||
<lastmod>2016-11-25</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
@ -21,61 +21,61 @@
|
||||
|
||||
<url>
|
||||
<loc>None/type-system/</loc>
|
||||
<lastmod>2016-11-08</lastmod>
|
||||
<lastmod>2016-11-25</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>None/type-system/object-types/</loc>
|
||||
<lastmod>2016-11-08</lastmod>
|
||||
<lastmod>2016-11-25</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>None/type-system/scalar-types/</loc>
|
||||
<lastmod>2016-11-08</lastmod>
|
||||
<lastmod>2016-11-25</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>None/type-system/enum-types/</loc>
|
||||
<lastmod>2016-11-08</lastmod>
|
||||
<lastmod>2016-11-25</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>None/type-system/lists-and-nonnulls/</loc>
|
||||
<lastmod>2016-11-08</lastmod>
|
||||
<lastmod>2016-11-25</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>None/type-system/interfaces/</loc>
|
||||
<lastmod>2016-11-08</lastmod>
|
||||
<lastmod>2016-11-25</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>None/type-system/unions/</loc>
|
||||
<lastmod>2016-11-08</lastmod>
|
||||
<lastmod>2016-11-25</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>None/type-system/input-types/</loc>
|
||||
<lastmod>2016-11-08</lastmod>
|
||||
<lastmod>2016-11-25</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>None/type-system/directives/</loc>
|
||||
<lastmod>2016-11-08</lastmod>
|
||||
<lastmod>2016-11-25</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>None/type-system/schema/</loc>
|
||||
<lastmod>2016-11-08</lastmod>
|
||||
<lastmod>2016-11-25</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
@ -84,7 +84,7 @@
|
||||
|
||||
<url>
|
||||
<loc>None/executing-queries/</loc>
|
||||
<lastmod>2016-11-08</lastmod>
|
||||
<lastmod>2016-11-25</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
@ -92,23 +92,7 @@
|
||||
|
||||
<url>
|
||||
<loc>None/error-handling/</loc>
|
||||
<lastmod>2016-11-08</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
|
||||
|
||||
<url>
|
||||
<loc>None/data-fetching/</loc>
|
||||
<lastmod>2016-11-08</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
|
||||
|
||||
<url>
|
||||
<loc>None/best-practices/</loc>
|
||||
<lastmod>2016-11-08</lastmod>
|
||||
<lastmod>2016-11-25</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
@ -116,7 +100,7 @@
|
||||
|
||||
<url>
|
||||
<loc>None/complementary-tools/</loc>
|
||||
<lastmod>2016-11-08</lastmod>
|
||||
<lastmod>2016-11-25</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
|
@ -167,20 +167,6 @@
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../error-handling/">Handling Errors</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../data-fetching/">Fetching Data</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../best-practices/">Best Practices</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
|
@ -173,20 +173,6 @@
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../error-handling/">Handling Errors</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../data-fetching/">Fetching Data</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../best-practices/">Best Practices</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
@ -260,8 +246,8 @@ $episodeEnum = new EnumType([
|
||||
]);
|
||||
</code></pre>
|
||||
|
||||
<p>This example uses <strong>inline</strong> style for Enum Type definition, but there are also
|
||||
<a href="../../type-system/#type-definition-styles">other styles</a> (using inheritance or composition).</p>
|
||||
<p>This example uses <strong>inline</strong> style for Enum Type definition, but you can also use
|
||||
<a href="../../type-system/#type-definition-styles">inheritance</a>.</p>
|
||||
<h1 id="configuration-options">Configuration options</h1>
|
||||
<p>Enum Type constructor accepts array with following options:</p>
|
||||
<table>
|
||||
|
@ -170,20 +170,6 @@
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../error-handling/">Handling Errors</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../data-fetching/">Fetching Data</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../best-practices/">Best Practices</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
@ -253,7 +239,7 @@ $myType = new ObjectType([
|
||||
]);
|
||||
</code></pre>
|
||||
|
||||
<p>Class per type, using inheritance:</p>
|
||||
<p>Class per type:</p>
|
||||
<pre><code class="php"><?php
|
||||
namespace MyApp;
|
||||
|
||||
@ -276,30 +262,6 @@ class MyType extends ObjectType
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
<p>Class per type, using composition:</p>
|
||||
<pre><code class="php"><?php
|
||||
namespace MyApp;
|
||||
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
use GraphQL\Type\DefinitionContainer;
|
||||
|
||||
class MyType implements DefinitionContainer
|
||||
{
|
||||
private $definition;
|
||||
|
||||
public function getDefinition()
|
||||
{
|
||||
return $this->definition ?: ($this->definition = new ObjectType([
|
||||
'name' => 'MyType',
|
||||
'fields' => [
|
||||
'id' => Type::id()
|
||||
]
|
||||
]));
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
<p>You can also mix-and-match styles for convenience. For example:</p>
|
||||
<pre><code class="php"><?php
|
||||
namespace MyApp;
|
||||
@ -328,7 +290,7 @@ class BlogPostType extends ObjectType
|
||||
</code></pre>
|
||||
|
||||
<h1 id="type-registry">Type Registry</h1>
|
||||
<p>Every type must be presented in Schema with single instance (<strong>graphql-php</strong>
|
||||
<p>Every type must be presented in Schema by single instance (<strong>graphql-php</strong>
|
||||
throws when it discovers several instances with the same <code>name</code> in schema).</p>
|
||||
<p>Therefore if you define your type as separate PHP class you must ensure that only one
|
||||
instance of that class is added to schema.</p>
|
||||
|
@ -173,20 +173,6 @@
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../error-handling/">Handling Errors</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../data-fetching/">Fetching Data</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../best-practices/">Best Practices</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
|
@ -179,20 +179,6 @@
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../error-handling/">Handling Errors</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../data-fetching/">Fetching Data</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../best-practices/">Best Practices</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
@ -270,8 +256,8 @@ $character = new InterfaceType([
|
||||
]);
|
||||
</code></pre>
|
||||
|
||||
<p>This example uses <strong>inline</strong> style for Interface definition, but there are also
|
||||
<a href="../../type-system/#type-definition-styles">other styles</a> (using inheritance or composition).</p>
|
||||
<p>This example uses <strong>inline</strong> style for Interface definition, but you can also use<br />
|
||||
<a href="../../type-system/#type-definition-styles">inheritance</a>.</p>
|
||||
<h1 id="configuration-options">Configuration options</h1>
|
||||
<p>Constructor of InterfaceType accepts an array. Below is a full list of allowed options:</p>
|
||||
<table>
|
||||
|
@ -167,20 +167,6 @@
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../error-handling/">Handling Errors</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../data-fetching/">Fetching Data</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../best-practices/">Best Practices</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
|
@ -185,20 +185,6 @@
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../error-handling/">Handling Errors</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../data-fetching/">Fetching Data</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../best-practices/">Best Practices</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
@ -300,8 +286,8 @@ $blogStory = new ObjectType([
|
||||
]);
|
||||
</code></pre>
|
||||
|
||||
<p>This example uses <strong>inline</strong> style for Object Type definitions, but there are also
|
||||
<a href="../../type-system/#type-definition-styles">other styles</a> (using inheritance or composition).</p>
|
||||
<p>This example uses <strong>inline</strong> style for Object Type definitions, but you can also use<br />
|
||||
<a href="../../type-system/#type-definition-styles">inheritance</a>.</p>
|
||||
<h1 id="configuration-options">Configuration options</h1>
|
||||
<p>Object type constructor expects configuration array. Below is a full list of available options:</p>
|
||||
<table>
|
||||
|
@ -167,20 +167,6 @@
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../error-handling/">Handling Errors</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../data-fetching/">Fetching Data</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../best-practices/">Best Practices</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
@ -264,12 +250,12 @@ or hardcoded in source code) to <strong>serialized</strong> representation inclu
|
||||
</ol>
|
||||
<p>Those cases are covered by methods <code>serialize</code>, <code>parseValue</code> and <code>parseLiteral</code> of abstract <code>ScalarType</code>
|
||||
class respectively.</p>
|
||||
<p>Here is an example of simple <code>Email</code> type (using inheritance):</p>
|
||||
<p>Here is an example of simple <code>Email</code> type:</p>
|
||||
<pre><code class="php"><?php
|
||||
namespace MyApp;
|
||||
|
||||
use GraphQL\Error\Error;
|
||||
use GraphQL\Language\AST\StringValue;
|
||||
use GraphQL\Language\AST\StringValueNode;
|
||||
use GraphQL\Type\Definition\ScalarType;
|
||||
use GraphQL\Utils;
|
||||
|
||||
@ -317,44 +303,21 @@ class EmailType extends ScalarType
|
||||
* user(email: "user@example.com")
|
||||
* }
|
||||
*
|
||||
* @param \GraphQL\Language\AST\Node $valueAST
|
||||
* @param \GraphQL\Language\AST\Node $valueNode
|
||||
* @return string
|
||||
* @throws Error
|
||||
*/
|
||||
public function parseLiteral($valueAST)
|
||||
public function parseLiteral($valueNode)
|
||||
{
|
||||
// Note: throwing GraphQL\Error\Error vs \UnexpectedValueException to benefit from GraphQL
|
||||
// error location in query:
|
||||
if (!$valueAST instanceof StringValue) {
|
||||
throw new Error('Query error: Can only parse strings got: ' . $valueAST->kind, [$valueAST]);
|
||||
if (!$valueNode instanceof StringValueNode) {
|
||||
throw new Error('Query error: Can only parse strings got: ' . $valueNode->kind, [$valueNode]);
|
||||
}
|
||||
if (!filter_var($valueAST->value, FILTER_VALIDATE_EMAIL)) {
|
||||
throw new Error("Not a valid email", [$valueAST]);
|
||||
if (!filter_var($valueNode->value, FILTER_VALIDATE_EMAIL)) {
|
||||
throw new Error("Not a valid email", [$valueNode]);
|
||||
}
|
||||
return $valueAST->value;
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
<p>Same example, using composition over inheritance:</p>
|
||||
<pre><code class="php"><?php
|
||||
namespace MyApp;
|
||||
|
||||
use GraphQL\Type\DefinitionContainer;
|
||||
use GraphQL\Type\Definition\CustomScalarType;
|
||||
|
||||
class EmailType implements DefinitionContainer
|
||||
{
|
||||
private $definition;
|
||||
|
||||
public function getDefinition()
|
||||
{
|
||||
return $this->definition ?: ($this->definition = new CustomScalarType([
|
||||
'name' => 'Email',
|
||||
'serialize' => function($value) {/* See function body above */},
|
||||
'parseValue' => function($value) {/* See function body above */},
|
||||
'parseLiteral' => function($valueAST) {/* See function body above */},
|
||||
]));
|
||||
return $valueNode->value;
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
@ -367,7 +330,7 @@ $emailType = new CustomScalarType([
|
||||
'name' => 'Email',
|
||||
'serialize' => function($value) {/* See function body above */},
|
||||
'parseValue' => function($value) {/* See function body above */},
|
||||
'parseLiteral' => function($valueAST) {/* See function body above */},
|
||||
'parseLiteral' => function($valueNode) {/* See function body above */},
|
||||
]);
|
||||
</code></pre>
|
||||
|
||||
|
@ -170,20 +170,6 @@
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../error-handling/">Handling Errors</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../data-fetching/">Fetching Data</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../best-practices/">Best Practices</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
|
@ -167,20 +167,6 @@
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../error-handling/">Handling Errors</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../data-fetching/">Fetching Data</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<li>
|
||||
<li class="toctree-l1 ">
|
||||
<a class="" href="../../best-practices/">Best Practices</a>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
@ -248,8 +234,8 @@ Value of Union Type is actually a value of one of included Object Types.</p>
|
||||
]);
|
||||
</code></pre>
|
||||
|
||||
<p>This example uses <strong>inline</strong> style for Union definition, but there are also
|
||||
<a href="../../type-system/#type-definition-styles">other styles</a> (using inheritance or composition).</p>
|
||||
<p>This example uses <strong>inline</strong> style for Union definition, but you can also use<br />
|
||||
<a href="../../type-system/#type-definition-styles">inheritance</a>.</p>
|
||||
<h1 id="configuration-options">Configuration options</h1>
|
||||
<p>Constructor of UnionType accepts an array. Below is a full list of allowed options:</p>
|
||||
<table>
|
||||
|
Loading…
x
Reference in New Issue
Block a user