Skip to content
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
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
| Q | A
| ---------------- | -----
| Bug report? | yes/no
| Feature request? | yes/no
| BC Break report? | yes/no
| RFC? | yes/no
| Version/Branch | x.y.z

<!--
Please fill in this template according to your issue.
-->
15 changes: 15 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
| Q | A
| ------------- | ---
| Bug fix? | yes/no
| New feature? | yes/no
| BC breaks? | yes/no
| Deprecations? | yes/no
| Tests pass? | yes/no
| Documented? | yes/no
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
| License | MIT

<!--
- Please fill in this template according to the PR you're about to submit.
- Replace this comment by a description of what your PR is solving.
-->
1 change: 0 additions & 1 deletion Config/EnumTypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public function getDefinition()
->append($this->nameSection())
->arrayNode('values')
->useAttributeAsKey('name')
// if value not define we use name as value
->beforeNormalization()
->ifTrue(function ($v) {
return is_array($v);
Expand Down
2 changes: 1 addition & 1 deletion Config/ObjectTypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getDefinition()
$node
->children()
->append($this->nameSection())
->append($this->outputFieldsSelection('fields', true))
->append($this->outputFieldsSelection('fields'))
->append($this->descriptionSection())
->arrayNode('interfaces')
->prototype('scalar')->info('One of internal or custom interface types.')->end()
Expand Down
99 changes: 49 additions & 50 deletions Config/TypeWithOutputFieldsDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,26 @@

abstract class TypeWithOutputFieldsDefinition extends TypeDefinition
{
const BUILDER_FIELD_TYPE = 'field';
const BUILDER_ARGS_TYPE = 'args';

/**
* @var MappingInterface[]
*/
private static $argsBuilderClassMap = [
'ForwardConnectionArgs' => 'Overblog\GraphQLBundle\Relay\Connection\ForwardConnectionArgsDefinition',
'BackwardConnectionArgs' => 'Overblog\GraphQLBundle\Relay\Connection\BackwardConnectionArgsDefinition',
'ConnectionArgs' => 'Overblog\GraphQLBundle\Relay\Connection\ConnectionArgsDefinition',
'Relay::ForwardConnection' => 'Overblog\GraphQLBundle\Relay\Connection\ForwardConnectionArgsDefinition',
'Relay::BackwardConnection' => 'Overblog\GraphQLBundle\Relay\Connection\BackwardConnectionArgsDefinition',
'Relay::Connection' => 'Overblog\GraphQLBundle\Relay\Connection\ConnectionArgsDefinition',
];

/**
* @var MappingInterface[]
*/
private static $fieldBuilderClassMap = [
'Mutation' => 'Overblog\GraphQLBundle\Relay\Mutation\MutationFieldDefinition',
'GlobalId' => 'Overblog\GraphQLBundle\Relay\Node\GlobalIdFieldDefinition',
'Node' => 'Overblog\GraphQLBundle\Relay\Node\NodeFieldDefinition',
'PluralIdentifyingRoot' => 'Overblog\GraphQLBundle\Relay\Node\PluralIdentifyingRootFieldDefinition',
'Relay::Mutation' => 'Overblog\GraphQLBundle\Relay\Mutation\MutationFieldDefinition',
'Relay::GlobalId' => 'Overblog\GraphQLBundle\Relay\Node\GlobalIdFieldDefinition',
'Relay::Node' => 'Overblog\GraphQLBundle\Relay\Node\NodeFieldDefinition',
'Relay::PluralIdentifyingRoot' => 'Overblog\GraphQLBundle\Relay\Node\PluralIdentifyingRootFieldDefinition',
];

public static function addArgsBuilderClass($name, $argBuilderClass)
Expand Down Expand Up @@ -80,40 +83,40 @@ protected static function checkBuilderClass($builderClass, $type)
}

/**
* @param $name
* @param string $name
* @param string $type
*
* @return MappingInterface
*
* @return MappingInterface|null
* @throws InvalidConfigurationException if builder class not define
*/
protected function getArgsBuilder($name)
protected function getBuilder($name, $type)
{
static $builders = [];
if (isset($builders[$name])) {
return $builders[$name];
if (isset($builders[$type][$name])) {
return $builders[$type][$name];
}

if (isset(self::$argsBuilderClassMap[$name])) {
return $builders[$name] = new self::$argsBuilderClassMap[$name]();
}
}
$builderClassMap = self::${$type.'BuilderClassMap'};

/**
* @param $name
*
* @return MappingInterface|null
*/
protected function getFieldBuilder($name)
{
static $builders = [];
if (isset($builders[$name])) {
return $builders[$name];
if (isset($builderClassMap[$name])) {
return $builders[$type][$name] = new $builderClassMap[$name]();
}
// deprecated relay builder name ?
$newName = 'Relay::'.rtrim($name, 'Args');
if (isset($builderClassMap[$newName])) {
@trigger_error(
sprintf('The "%s" %s builder is deprecated as of 0.7 and will be removed in 0.8. Use "%s" instead.', $name, $type, $newName),
E_USER_DEPRECATED
);

if (isset(self::$fieldBuilderClassMap[$name])) {
return $builders[$name] = new self::$fieldBuilderClassMap[$name]();
return $builders[$type][$newName] = new $builderClassMap[$newName]();
}

throw new InvalidConfigurationException(sprintf('%s builder "%s" not found.', ucfirst($type), $name));
}

protected function outputFieldsSelection($name, $withAccess = false)
protected function outputFieldsSelection($name)
{
$builder = new TreeBuilder();
$node = $builder->root($name);
Expand All @@ -140,12 +143,7 @@ protected function outputFieldsSelection($name, $withAccess = false)
}

if ($argsBuilderName) {
if (!($argsBuilder = $this->getArgsBuilder($argsBuilderName))) {
throw new InvalidConfigurationException(sprintf('Args builder "%s" not found.', $argsBuilder));
}

$args = $argsBuilder->toMappingDefinition([]);

$args = $this->getBuilder($argsBuilderName, static::BUILDER_ARGS_TYPE)->toMappingDefinition([]);
$field['args'] = isset($field['args']) && is_array($field['args']) ? array_merge($args, $field['args']) : $args;
}

Expand All @@ -163,6 +161,11 @@ protected function outputFieldsSelection($name, $withAccess = false)
$fieldBuilderName = $field['builder'];
unset($field['builder']);
} elseif (is_string($field)) {
@trigger_error(
'The builder short syntax (Field: Builder => Field: {builder: Builder}) is deprecated as of 0.7 and will be removed in 0.8. '.
'It will be replaced by the field type short syntax (Field: Type => Field: {type: Type})',
E_USER_DEPRECATED
);
$fieldBuilderName = $field;
}

Expand All @@ -175,10 +178,7 @@ protected function outputFieldsSelection($name, $withAccess = false)
}

if ($fieldBuilderName) {
if (!($fieldBuilder = $this->getFieldBuilder($fieldBuilderName))) {
throw new InvalidConfigurationException(sprintf('Field builder "%s" not found.', $fieldBuilderName));
}
$buildField = $fieldBuilder->toMappingDefinition($builderConfig);
$buildField = $this->getBuilder($fieldBuilderName, static::BUILDER_FIELD_TYPE)->toMappingDefinition($builderConfig);
$field = is_array($field) ? array_merge($buildField, $field) : $buildField;
}

Expand All @@ -193,9 +193,18 @@ protected function outputFieldsSelection($name, $withAccess = false)
->info('Array of possible type arguments. Each entry is expected to be an array with following keys: name (string), type')
->useAttributeAsKey('name', false)
->prototype('array')
// Allow arg type short syntax (Arg: Type => Arg: {type: Type})
->beforeNormalization()
->ifTrue(function ($options) {
return is_string($options);
})
->then(function ($options) {
return ['type' => $options];
})
->end()
->children()
->append($this->typeSelection(true))
->scalarNode('description')->end()
->append($this->descriptionSection())
->append($this->defaultValueSection())
->end()
->end()
Expand All @@ -211,18 +220,8 @@ protected function outputFieldsSelection($name, $withAccess = false)
->variableNode('complexity')
->info('Custom complexity calculator.')
->end()
->variableNode('map')->end()
->end();

if ($withAccess) {
$prototype
->children()
->variableNode('access')
->info('Access control to field (expression language can be use here)')
->end()
->end();
}

return $node;
}
}
2 changes: 1 addition & 1 deletion Resources/config/graphql_types.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
# GraphQL ccalar types
# GraphQL build-in Scalars types
overblog_graphql.definition.string_type:
class: GraphQL\Type\Definition\StringType
factory: ["GraphQL\\Type\\Definition\\Type", string]
Expand Down
3 changes: 1 addition & 2 deletions Resources/doc/definitions/index.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
Definitions
===========

* [System types](system-types/index.md)
* [Type System](type-system/index.md)
* [Schema](schema.md)

Go further
----------

* [Custom scalar](custom-scalar.md)
* [Mutation](mutation.md)
* [Relay](relay/index.md)
* [Builders](builders/index.md)
Expand Down
6 changes: 3 additions & 3 deletions Resources/doc/definitions/relay/connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ User:
type: String
friends:
type: friendConnection
argsBuilder: ConnectionArgs
argsBuilder: "Relay::Connection"
resolve: '@=resolver("friends", [value, args])'
friendsForward:
type: userConnection
argsBuilder: ForwardConnectionArgs
argsBuilder: "Relay::ForwardConnection
resolve: '@=resolver("friends", [value, args])'
friendsBackward:
type: userConnection
argsBuilder: BackwardConnectionArgs
argsBuilder: "Relay::BackwardConnection"
resolve: '@=resolver("friends", [value, args])'

friendConnection:
Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/definitions/relay/mutation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Mutation:
config:
fields:
introduceShip:
builder: Mutation
builder: "Relay::Mutation"
builderConfig:
inputType: IntroduceShipInput
payloadType: IntroduceShipPayload
Expand Down
8 changes: 4 additions & 4 deletions Resources/doc/definitions/relay/node/global-id.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Query:
config:
fields:
node:
builder: Node
builder: "Relay::Node"
builderConfig:
nodeInterfaceType: NodeInterface
idFetcher: '@=service("overblog_graphql.test.resolver.global").idFetcher(value)'
Expand All @@ -25,7 +25,7 @@ User:
config:
fields:
id:
builder: GlobalId
builder: "Relay::GlobalId"
builderConfig:
typeName: User
name:
Expand All @@ -37,7 +37,7 @@ Photo:
config:
fields:
id:
builder: GlobalId
builder: "Relay::GlobalId"
builderConfig:
typeName: Photo
idFetcher: '@=value["photoId"]'
Expand All @@ -50,7 +50,7 @@ Post:
config:
fields:
id:
builder: GlobalId
builder: "Relay::GlobalId"
builderConfig:
typeName: Post
text:
Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/definitions/relay/node/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Query:
config:
fields:
node:
builder: Node
builder: "Relay::Node"
builderConfig:
nodeInterfaceType: Node
idFetcher: '@=resolver("node_id_fetcher", [value])'
Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/definitions/relay/node/plural.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Query:
config:
fields:
usernames:
builder: PluralIdentifyingRoot
builder: "Relay::PluralIdentifyingRoot"
builderConfig:
argName: 'usernames'
description: 'Map from a username to the user'
Expand Down
11 changes: 0 additions & 11 deletions Resources/doc/definitions/system-types/index.md

This file was deleted.

17 changes: 17 additions & 0 deletions Resources/doc/definitions/type-system/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Type System
============

Types
-----

Types can be defined in bundle Resources/config/graphql using
this file extension **.types.yml** or **.types.xml**.

* [Scalars](scalars.md)
* [Object](object.md)
* [Interface](interface.md)
* [Union](union.md)
* [Enum](enum.md)
* [Input Object](input-object.md)
* [Lists](lists.md)
* [Non-Null](non-null.md)
5 changes: 5 additions & 0 deletions Resources/doc/definitions/type-system/lists.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Lists
======

To denote that a field uses a List type the item type is wrapped in square brackets like this: **[Pet]**.
If using yaml like config file, the double quote is required like this: **"[Pet]"**.
4 changes: 4 additions & 0 deletions Resources/doc/definitions/type-system/non-null.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Non-Null
========

A trailing exclamation mark is used to denote a field that uses a Non‐Null type like this: **String!**.
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Custom scalar
Scalars
=======

Here a simple example to add a custom scalar:
Here all supported built‐in Scalars:

* **Int**
* **Float**
* **String**
* **Boolean**
* **ID**

Custom Scalar
-------------

Here a simple example of how to add a custom Scalar:

```yaml
DateTime:
Expand Down
Loading