Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
fdfcd88
wip
spawnia Sep 18, 2019
121e580
wip
spawnia Sep 18, 2019
fccc25d
Finish implementation
spawnia Sep 19, 2019
6c62ecd
Add Introspection::fromSchema
spawnia Sep 21, 2019
c4021fd
wip test
spawnia Sep 21, 2019
3c729c4
format
spawnia Sep 21, 2019
f8e9e6b
types
spawnia Sep 21, 2019
0f7d970
Use array instead of stdClass
spawnia Oct 31, 2019
38ea6df
Add tests
spawnia Oct 31, 2019
ed3e57c
Mention TypeKind constants change in UPGRADE.md
spawnia Nov 1, 2019
10be064
Adress review comments
spawnia Nov 1, 2019
e9dadce
Some codestyle fixes
spawnia Nov 1, 2019
67b0a8f
Merge branch 'master' into BuildClientSchema
spawnia Nov 3, 2019
2b30fa7
Fix codestyle and static analysis
spawnia Nov 8, 2019
8f6f638
Build some tests
spawnia Nov 11, 2019
6d0fb28
Add more tests
spawnia Nov 16, 2019
c8560f0
Fix test and implementation
spawnia Nov 19, 2019
1b588ce
Merge branch 'master' into BuildClientSchema
spawnia Nov 19, 2019
b5cc5fd
Fix codestyle
spawnia Nov 19, 2019
9603ef1
Change wording
spawnia Nov 19, 2019
a15a2a8
Revert implementation of defaultValueExists
spawnia Nov 20, 2019
71550b0
Fix codestyle
spawnia Nov 20, 2019
622e632
Call instance method not statically
spawnia Nov 20, 2019
063c0d5
Fix codestyle
spawnia Nov 20, 2019
c4d4396
Make callable functions public
spawnia Nov 20, 2019
0b1bc87
Merge branch 'master' into BuildClientSchema
spawnia Dec 5, 2019
c06d5e0
Merge branch 'master' into BuildClientSchema
spawnia Dec 16, 2019
ce1f68c
Merge branch 'master' into BuildClientSchema
spawnia Jan 6, 2020
f8cbca3
Merge branch 'master' into BuildClientSchema
spawnia Jan 17, 2020
44e9718
Update src/Type/Introspection.php
spawnia Jan 19, 2020
7525beb
Update tests/Utils/BuildClientSchemaTest.php
spawnia Jan 19, 2020
4203e0d
Iterable
spawnia Jan 20, 2020
d78980b
Revert change in Utils.php
spawnia Jan 20, 2020
c35106a
Re-add minimal docs fix
spawnia Jan 20, 2020
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
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
### Breaking (major): dropped deprecations
- dropped deprecated `GraphQL\Schema`. Use `GraphQL\Type\Schema`.

### Breaking: change TypeKind constants
The constants in `\GraphQL\Type\TypeKind` were partly renamed and their values
have been changed to match their name instead of a numeric index.

## Upgrade v0.12.x > v0.13.x

### Breaking (major): minimum supported version of PHP
Expand Down
37 changes: 33 additions & 4 deletions src/Type/Introspection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace GraphQL\Type;

use Exception;
use GraphQL\GraphQL;
use GraphQL\Language\DirectiveLocation;
use GraphQL\Language\Printer;
use GraphQL\Type\Definition\Directive;
Expand Down Expand Up @@ -184,6 +185,34 @@ public static function getTypes()
];
}

/**
* Build an introspection query from a Schema
*
* Introspection is useful for utilities that care about type and field
* relationships, but do not need to traverse through those relationships.
*
* This is the inverse of BuildClientSchema::build(). The primary use case is outside
* of the server context, for instance when doing schema comparisons.
*
* Options:
* - descriptions
* Whether to include descriptions in the introspection result.
* Default: true
*
* @param array<string, bool> $options
*
* @return array<string, array<mixed>>|null
*/
public static function fromSchema(Schema $schema, array $options = []) : ?array
{
$result = GraphQL::executeQuery(
$schema,
self::getIntrospectionQuery($options)
);

return $result->data;
}

public static function _schema()
{
if (! isset(self::$map['__Schema'])) {
Expand Down Expand Up @@ -263,7 +292,7 @@ public static function _type()
'resolve' => static function (Type $type) {
switch (true) {
case $type instanceof ListOfType:
return TypeKind::LIST_KIND;
return TypeKind::LIST;
case $type instanceof NonNull:
return TypeKind::NON_NULL;
case $type instanceof ScalarType:
Expand All @@ -275,7 +304,7 @@ public static function _type()
case $type instanceof InputObjectType:
return TypeKind::INPUT_OBJECT;
case $type instanceof InterfaceType:
return TypeKind::INTERFACE_KIND;
return TypeKind::INTERFACE;
case $type instanceof UnionType:
return TypeKind::UNION;
default:
Expand Down Expand Up @@ -408,7 +437,7 @@ public static function _typeKind()
'description' => 'Indicates this type is an object. `fields` and `interfaces` are valid fields.',
],
'INTERFACE' => [
'value' => TypeKind::INTERFACE_KIND,
'value' => TypeKind::INTERFACE,
'description' => 'Indicates this type is an interface. `fields` and `possibleTypes` are valid fields.',
],
'UNION' => [
Expand All @@ -424,7 +453,7 @@ public static function _typeKind()
'description' => 'Indicates this type is an input object. `inputFields` is a valid field.',
],
'LIST' => [
'value' => TypeKind::LIST_KIND,
'value' => TypeKind::LIST,
'description' => 'Indicates this type is a list. `ofType` is a valid field.',
],
'NON_NULL' => [
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private function collectAllTypes()
*/
public function getDirectives()
{
return $this->config->directives ?: GraphQL::getStandardDirectives();
return $this->config->directives ?? GraphQL::getStandardDirectives();
}

/**
Expand Down
16 changes: 8 additions & 8 deletions src/Type/TypeKind.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

class TypeKind
{
const SCALAR = 0;
const OBJECT = 1;
const INTERFACE_KIND = 2;
const UNION = 3;
const ENUM = 4;
const INPUT_OBJECT = 5;
const LIST_KIND = 6;
const NON_NULL = 7;
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';
}
Loading