Work in progress on better docs

This commit is contained in:
vladar 2016-11-25 18:07:51 +07:00
parent 7ee3431298
commit 2cc2255b1a
9 changed files with 25 additions and 20 deletions

View File

@ -9,7 +9,7 @@ To enable validation - call: `GraphQL\Type\Definition\Config::enableValidation()
but make sure to restrict it to debug/development mode only. but make sure to restrict it to debug/development mode only.
# Type Registry # Type Registry
**graphql-php** expects that each type in Schema is presented with single instance. Therefore **graphql-php** expects that each type in Schema is presented by single instance. Therefore
if you define your types as separate PHP classes you need to ensure that each type is referenced only once. if you define your types as separate PHP classes you need to ensure that each type is referenced only once.
Technically you can create several instances of your type (for example for tests), but `GraphQL\Schema` Technically you can create several instances of your type (for example for tests), but `GraphQL\Schema`

View File

@ -126,12 +126,15 @@ try {
// ... // ...
]); ]);
$result = GraphQL::execute($schema, $query); $body = GraphQL::execute($schema, $query);
$status = 200;
} catch(\Exception $e) { } catch(\Exception $e) {
header('Content-Type: application/json', true, 500); $body = json_encode([
echo json_encode([
'message' => 'Unexpected error' 'message' => 'Unexpected error'
]); ]);
exit; $status = 500;
} }
header('Content-Type: application/json', true, $status);
echo json_encode($body);
``` ```

View File

@ -15,9 +15,11 @@ add `composer.json` file to your project root folder with following contents:
``` ```
and run `composer install`. and run `composer install`.
If you already have composer.json file - simply run: `composer require webonyx/graphql-php` If you already have composer.json file - simply run: `composer require webonyx/graphql-php="^0.7"`
If you are upgrading, see [upgrade instructions](https://github.com/webonyx/graphql-php/blob/master/UPGRADE.md) # Upgrading
We try to keep library releases backwards compatible. But when breaking changes are inevitable
they are explained in [upgrade instructions](https://github.com/webonyx/graphql-php/blob/master/UPGRADE.md).
# Install Tools (optional) # Install Tools (optional)
While it is possible to communicate with GraphQL API using regular HTTP tools it is way While it is possible to communicate with GraphQL API using regular HTTP tools it is way
@ -68,7 +70,7 @@ $queryType = new ObjectType([
``` ```
(Note: type definition can be expressed in [different styles](type-system/#type-definition-styles), (Note: type definition can be expressed in [different styles](type-system/#type-definition-styles),
including **inheritance**, **composition** and **inline**. This example uses **inline** style for simplicity) but this example uses **inline** style for simplicity)
The interesting piece here is `resolve` option of field definition. It is responsible for retuning The interesting piece here is `resolve` option of field definition. It is responsible for retuning
value of our field. Values of **scalar** fields will be directly included in response while values of value of our field. Values of **scalar** fields will be directly included in response while values of

View File

@ -28,8 +28,8 @@ $episodeEnum = new EnumType([
]); ]);
``` ```
This example uses **inline** style for Enum Type definition, but there are also This example uses **inline** style for Enum Type definition, but you can also use
[other styles](/type-system/#type-definition-styles) (using inheritance or composition). [inheritance](/type-system/#type-definition-styles).
# Configuration options # Configuration options
Enum Type constructor accepts array with following options: Enum Type constructor accepts array with following options:

View File

@ -79,7 +79,7 @@ class BlogPostType extends ObjectType
``` ```
# Type Registry # Type Registry
Every type must be presented in Schema with single instance (**graphql-php** Every type must be presented in Schema by single instance (**graphql-php**
throws when it discovers several instances with the same `name` in schema). throws when it discovers several instances with the same `name` in schema).
Therefore if you define your type as separate PHP class you must ensure that only one Therefore if you define your type as separate PHP class you must ensure that only one

View File

@ -31,8 +31,8 @@ $character = new InterfaceType([
} }
]); ]);
``` ```
This example uses **inline** style for Interface definition, but there are also This example uses **inline** style for Interface definition, but you can also use
[other styles](/type-system/#type-definition-styles) (using inheritance or composition). [inheritance](/type-system/#type-definition-styles).
# Configuration options # Configuration options
Constructor of InterfaceType accepts an array. Below is a full list of allowed options: Constructor of InterfaceType accepts an array. Below is a full list of allowed options:

View File

@ -56,8 +56,8 @@ $blogStory = new ObjectType([
] ]
]); ]);
``` ```
This example uses **inline** style for Object Type definitions, but there are also This example uses **inline** style for Object Type definitions, but you can also use
[other styles](/type-system/#type-definition-styles) (using inheritance or composition). [inheritance](/type-system/#type-definition-styles).
# Configuration options # Configuration options

View File

@ -22,8 +22,8 @@ $searchResultType = new UnionType([
]); ]);
``` ```
This example uses **inline** style for Union definition, but there are also This example uses **inline** style for Union definition, but you can also use
[other styles](/type-system/#type-definition-styles) (using inheritance or composition). [inheritance](/type-system/#type-definition-styles).
# Configuration options # Configuration options
Constructor of UnionType accepts an array. Below is a full list of allowed options: Constructor of UnionType accepts an array. Below is a full list of allowed options:

View File

@ -15,7 +15,7 @@ pages:
- Schema: type-system/schema.md - Schema: type-system/schema.md
- Executing Queries: executing-queries.md - Executing Queries: executing-queries.md
- Handling Errors: error-handling.md - Handling Errors: error-handling.md
- Fetching Data: data-fetching.md # - Fetching Data: data-fetching.md
- Best Practices: best-practices.md # - Best Practices: best-practices.md
- Complementary Tools: complementary-tools.md - Complementary Tools: complementary-tools.md
theme: readthedocs theme: readthedocs