Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated documentation to spec April2016, upgrade instructions #48

Merged
merged 1 commit into from
Sep 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ $> curl -sS https://getcomposer.org/installer | php
$> php composer.phar require webonyx/graphql-php='dev-master'
```

If you are upgrading, see [upgrade instructions](UPGRADE.md)

## Requirements
PHP >=5.4

Expand All @@ -52,7 +54,7 @@ Examples below implement the type system described in this document.
### Type System
To start using GraphQL you are expected to implement a Type system.

GraphQL PHP provides several *kinds* of types to build hierarchical type system:
GraphQL PHP provides several *kinds* of types to build a hierarchical type system:
`scalar`, `enum`, `object`, `interface`, `union`, `listOf`, `nonNull`.

#### Internal types
Expand Down Expand Up @@ -357,7 +359,17 @@ $queryType = new ObjectType([
// TODOC
$mutationType = null;

$schema = new Schema($queryType, $mutationType);
$schema = new Schema([
'query' => $queryType,
'mutation' => $mutationType,

// We need to pass the types that implement interfaces in case the types are only created on demand.
// This ensures that they are available during query validation phase for interfaces.
'types' => [
$humanType,
$droidType
]
]);
```

**Notes:**
Expand Down Expand Up @@ -447,6 +459,7 @@ try {
$schema,
$requestString,
/* $rootValue */ null,
/* $context */ null, // A custom context that can be used to pass current User object etc to resolvers.
$variableValues,
$operationName
);
Expand Down
58 changes: 58 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Upgrade

## Upgrade v0.6.x > v0.7.x

There are a few new breaking changes in v0.7.0 that were added to the graphql-js reference implementation
with the spec of April2016

### 1. Context for resolver

You can now pass a custom context to the `GraphQL::execute` function that is available in all resolvers.
This can for example be used to pass the current user etc. The new signature looks like this:

```php
GraphQL::execute(
$schema,
$query,
$rootObject,
$context,
$variables,
$operationName
);
```

The signature of all resolve methods has changed to the following:

```php
/**
* @param mixed $object The parent resolved object
* @param array $args Input arguments
* @param mixed $context The context object hat was passed to GraphQL::execute
* @param ResolveInfo $info ResolveInfo object
* @return mixed
*/
function resolveMyField($object, array $args, $context, ResolveInfo $info){
//...
}
```

### 2. Schema constructor signature

The signature of the Schema constructor now accepts an associative config array instead of positional arguments:

```php
$schema = new Schema([
'query' => $queryType,
'mutation' => $mutationType,
'types' => $arrayOfTypesWithInterfaces // See 3.
]);
```

### 3. Types can be directly passed to schema

In case your implementation creates types on demand, the types might not be available when an interface
is queried and query validation will fail. In that case, you need to pass the types that implement the
interfaces directly to the schema, so it knows of their existence during query validation.
Also see webonyx/graphql-php#38

If your types are created each time the Schema is created, this can be ignored.