Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
Add initial support for introspection
Browse files Browse the repository at this point in the history
  • Loading branch information
crisu83 committed Mar 2, 2018
1 parent 7ce0c8f commit 28ba55c
Show file tree
Hide file tree
Showing 9 changed files with 796 additions and 30 deletions.
91 changes: 91 additions & 0 deletions Resources/introspection.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {
name
description
locations
args {
...InputValue
}
}
}
}

fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
description
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}

fragment InputValue on __InputValue {
name
description
type { ...TypeRef }
defaultValue
}

fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}
29 changes: 26 additions & 3 deletions src/Execution/ExecutionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace Digia\GraphQL\Execution;

use function Digia\GraphQL\Util\jsonEncode;
use Digia\GraphQL\Util\SerializationInterface;
use Digia\GraphQL\Error\GraphQLError;

class ExecutionResult
class ExecutionResult implements SerializationInterface
{

/**
* @var GraphQLError[]
*/
Expand All @@ -18,10 +21,11 @@ class ExecutionResult

/**
* ExecutionResult constructor.
* @param mixed[] $data
*
* @param mixed[] $data
* @param GraphQLError[] $errors
*/
public function __construct(array $data, array $errors)
public function __construct(?array $data, ?array $errors)
{
$this->errors = $errors;
$this->data = $data;
Expand All @@ -44,4 +48,23 @@ public function addError(GraphQLError $error): ExecutionResult
$this->errors[] = $error;
return $this;
}

/**
* @inheritdoc
*/
public function toArray(): array
{
return [
'data' => $this->data,
'errors' => $this->errors,
];
}

/**
* @inheritdoc
*/
public function toJSON(): string
{
return jsonEncode($this->toArray());
}
}
26 changes: 0 additions & 26 deletions src/Type/Definition/FieldsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,6 @@ trait FieldsTrait
*/
private $_isFieldMapDefined = false;

/**
* @param Field $field
* @return $this
* @throws \Exception
*/
public function addField(Field $field)
{
$this->_fieldMap[$field->getName()] = $field;

return $this;
}

/**
* @param array $fields
* @return $this
* @throws \Exception
*/
public function addFields(array $fields)
{
foreach ($fields as $field) {
$this->addField($field);
}

return $this;
}

/**
* @return Field[]
* @throws \Exception
Expand Down
25 changes: 25 additions & 0 deletions src/Type/TypeKindEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Digia\GraphQL\Type;

class TypeKindEnum
{

const SCALAR = 'SCALAR';
const OBJECT = 'OBJECT';
const INTERFACE = 'INTERFACE';
const UNION = 'UNION';
const ENUM = 'ENUM';
const INPUT_OBJECT = 'INPUT_OBJECT';
const LIST = 'LIST';
const NON_NULL = 'NON_NULL';

/**
* @return array
* @throws \ReflectionException
*/
public static function values(): array
{
return array_values((new \ReflectionClass(__CLASS__))->getConstants());
}
}
1 change: 1 addition & 0 deletions src/Type/definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Digia\GraphQL\Type\Definition\CompositeTypeInterface;
use Digia\GraphQL\Type\Definition\Directive;
use Digia\GraphQL\Type\Definition\EnumType;
use Digia\GraphQL\Type\Definition\Field;
use Digia\GraphQL\Type\Definition\InputObjectType;
use Digia\GraphQL\Type\Definition\InputTypeInterface;
use Digia\GraphQL\Type\Definition\InterfaceType;
Expand Down

0 comments on commit 28ba55c

Please sign in to comment.