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 Feb 27, 2018
1 parent 974e772 commit 6b88c6b
Show file tree
Hide file tree
Showing 11 changed files with 796 additions and 35 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
}
}
}
}
}
}
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"./src/Type/definition.php",
"./src/Type/directives.php",
"./src/Type/scalars.php",
"./src/Util/helpers.php"
"./src/Util/helpers.php",
"./src/graphql.php"
],
"psr-4": {
"Digia\\GraphQL\\": "./src"
Expand Down
20 changes: 17 additions & 3 deletions src/Execution/ExecutionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Digia\GraphQL\Execution;

use Digia\GraphQL\Contract\SerializationInterface;
use Digia\GraphQL\Error\GraphQLError;

class ExecutionResult
class ExecutionResult implements SerializationInterface
{

/**
* @var GraphQLError[]
*/
Expand All @@ -18,10 +20,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 +47,15 @@ public function addError(GraphQLError $error): ExecutionResult
$this->errors[] = $error;
return $this;
}

/**
* @inheritdoc
*/
public function toArray(): array
{
return [
'data' => $this->data,
'errors' => $this->errors,
];
}
}
6 changes: 3 additions & 3 deletions src/Language/AST/Node/Behavior/NameTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public function getName(): ?NameNode
}

/**
* @return string
* @return string|null
*/
public function getNameValue(): string
public function getNameValue(): ?string
{
return $this->name->getValue();
return null !== $this->name ? $this->name->getValue() : null;
}

/**
Expand Down
27 changes: 0 additions & 27 deletions src/Type/Definition/Behavior/FieldsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,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 @@ -11,6 +11,7 @@
use Digia\GraphQL\Type\Definition\Contract\TypeInterface;
use Digia\GraphQL\Type\Definition\Contract\WrappingTypeInterface;
use Digia\GraphQL\Type\Definition\EnumType;
use Digia\GraphQL\Type\Definition\Field;
use Digia\GraphQL\Type\Definition\InputObjectType;
use Digia\GraphQL\Type\Definition\InterfaceType;
use Digia\GraphQL\Type\Definition\ListType;
Expand Down

0 comments on commit 6b88c6b

Please sign in to comment.