Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.
Open
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
21 changes: 12 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@
"graphql-tools"
],
"require": {
"php": ">=7.2",
"webonyx/graphql-php": "~0.13",
"php": "^8.2",
"webonyx/graphql-php": "^15.0",
"ext-json": "*"
},
"require-dev": {
"squizlabs/php_codesniffer": "3.4.2",
"phpunit/phpunit": "^7.3 || ^8.0",
"react/promise": "^2.7",
"doctrine/coding-standard": "^5.0",
"phpstan/phpstan": "^0.10.5",
"phpstan/phpstan-phpunit": "^0.10.0",
"phpstan/phpstan-strict-rules": "^0.10.1"
"squizlabs/php_codesniffer": "^3.4",
"phpunit/phpunit": "^9.1",
"react/promise": "^3.2",
"doctrine/coding-standard": "^13.0",
"phpstan/phpstan": "^2.0"
},
"autoload": {
"psr-4": {
Expand All @@ -42,5 +40,10 @@
"test": "phpunit",
"lint": "phpcs",
"static-analysis": "phpstan analyse --ansi"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
5 changes: 0 additions & 5 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,3 @@ parameters:
paths:
- %currentWorkingDirectory%/src
- %currentWorkingDirectory%/tests

includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon
34 changes: 14 additions & 20 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="E_ALL"/>
</php>

<testsuites>
<testsuite name="t3n/graphql-tools Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<php>
<ini name="error_reporting" value="E_ALL"/>
</php>
<testsuites>
<testsuite name="t3n/graphql-tools Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
37 changes: 20 additions & 17 deletions src/Generate/AddResolveFunctionsToSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use GraphQL\Type\Schema;
use GraphQLTools\Transforms\ConvertEnumValues;
use GraphQLTools\Transforms\Transforms;

use function array_keys;
use function assert;
use function gettype;
use function is_array;
use function is_callable;
Expand All @@ -31,10 +33,10 @@ class AddResolveFunctionsToSchema
* @throws SchemaError
*/
public static function invoke(
$options,
$legacyInputResolvers = null,
?array $legacyInputValidationOptions = null
) : Schema {
Schema|array $options,
array|null $legacyInputResolvers = null,
array|null $legacyInputValidationOptions = null,
): Schema {
if ($options instanceof Schema) {
$options = [
'schema' => $options,
Expand All @@ -43,8 +45,8 @@ public static function invoke(
];
}

/** @var Schema $schema */
$schema = $options['schema'];
$schema = $options['schema'];
assert($schema instanceof Schema);
$inputResolvers = $options['resolvers'];
$resolverValidationOptions = $options['resolverValidationOptions'] ?? [];
$inheritResolversFromInterfaces = $options['inheritResolversFromInterfaces'] ?? false;
Expand All @@ -62,13 +64,13 @@ public static function invoke(
if (! is_array($resolverValue) && ! is_object($resolverValue) && ! is_callable($resolverValue)) {
throw new SchemaError(
'"' . $typeName . '" defined in resolvers, but has invalid value "' .
gettype($resolverValue) . '". A resolver\'s value must be of type object or function.'
gettype($resolverValue) . '". A resolver\'s value must be of type object or function.',
);
}

try {
$type = $schema->getType($typeName);
} catch (Error $error) {
} catch (Error) {
$type = null;
}

Expand Down Expand Up @@ -104,6 +106,7 @@ public static function invoke(
default:
$type->$fieldName = $resolverValue[$fieldName];
}

continue;
}

Expand All @@ -114,11 +117,11 @@ public static function invoke(
}

throw new SchemaError(
$typeName . '.' . $fieldName . ' was defined in resolvers, but enum is not in schema'
$typeName . '.' . $fieldName . ' was defined in resolvers, but enum is not in schema',
);
}

$enumValueMap[$type->name] = $enumValueMap[$type->name] ?? [];
$enumValueMap[$type->name] ??= [];
$enumValueMap[$type->name][$fieldName] = $resolverValue[$fieldName];
continue;
}
Expand Down Expand Up @@ -147,9 +150,10 @@ public static function invoke(
} else {
if (! is_array($fieldResolve)) {
throw new SchemaError(
'Resolver ' . $typeName . '.' . $fieldName . ' must be object or function'
'Resolver ' . $typeName . '.' . $fieldName . ' must be object or function',
);
}

static::setFieldProperties($field, $fieldResolve);
}
}
Expand All @@ -162,12 +166,11 @@ public static function invoke(
]);
}

/**
* @return FieldDefinition[]|null
*/
protected static function getFieldsForType(Type $type) : ?array
/** @return FieldDefinition[]|null */
protected static function getFieldsForType(Type $type): array|null
{
if ($type instanceof ObjectType ||
if (
$type instanceof ObjectType ||
$type instanceof InterfaceType
) {
return $type->getFields();
Expand All @@ -181,7 +184,7 @@ protected static function getFieldsForType(Type $type) : ?array
*
* @param mixed[] $propertiesObj
*/
protected static function setFieldProperties(FieldDefinition $field, array $propertiesObj) : void
protected static function setFieldProperties(FieldDefinition $field, array $propertiesObj): void
{
foreach ($propertiesObj as $propertyName => $property) {
switch ($propertyName) {
Expand Down
7 changes: 4 additions & 3 deletions src/Generate/AddSchemaLevelResolveFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Schema;

use function array_filter;
use function mt_getrandmax;
use function mt_rand;

class AddSchemaLevelResolveFunction
{
public static function invoke(Schema $schema, callable $fn) : void
public static function invoke(Schema $schema, callable $fn): void
{
/** @var ObjectType[] $rootTypes */
$rootTypes = array_filter([
Expand All @@ -39,7 +40,7 @@ public static function invoke(Schema $schema, callable $fn) : void
}
}

protected static function wrapResolver(?callable $innerResolver, callable $outerResolver) : callable
protected static function wrapResolver(callable|null $innerResolver, callable $outerResolver): callable
{
return static function ($obj, $args, &$ctx, ResolveInfo $info) use ($innerResolver, $outerResolver) {
$root = $outerResolver($obj, $args, $ctx, $info);
Expand All @@ -52,7 +53,7 @@ protected static function wrapResolver(?callable $innerResolver, callable $outer
};
}

protected static function runAtMostOncePerRequest(callable $fn) : callable
protected static function runAtMostOncePerRequest(callable $fn): callable
{
$value = null;
// cast to string to all $randomNumber to be an array key
Expand Down
23 changes: 10 additions & 13 deletions src/Generate/AssertResolveFunctionsPresent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Schema;
use TypeError;

use function count;
use function is_callable;

class AssertResolveFunctionsPresent
{
/**
* @param mixed[] $resolverValidationOptions
*/
public static function invoke(Schema $schema, array $resolverValidationOptions = []) : void
/** @param mixed[] $resolverValidationOptions */
public static function invoke(Schema $schema, array $resolverValidationOptions = []): void
{
$requireResolversForArgs = $resolverValidationOptions['requireResolversForArgs'] ?? false;
$requireResolversForNonScalar = $resolverValidationOptions['requireResolversForNonScalar'] ?? false;
Expand All @@ -27,7 +26,7 @@ public static function invoke(Schema $schema, array $resolverValidationOptions =
throw new TypeError(
'requireResolversForAllFields takes precedence over the more specific assertions. ' .
'Please configure either requireResolversForAllFields or requireResolversForArgs / ' .
'requireResolversForNonScalar, but not a combination of them.'
'requireResolversForNonScalar, but not a combination of them.',
);
}

Expand All @@ -36,12 +35,12 @@ public static function invoke(Schema $schema, array $resolverValidationOptions =
static function (
FieldDefinition $field,
string $typeName,
string $fieldName
string $fieldName,
) use (
$requireResolversForAllFields,
$requireResolversForArgs,
$requireResolversForNonScalar
) : void {
$requireResolversForNonScalar,
): void {
if ($requireResolversForAllFields) {
static::expectResolveFunction($field, $typeName, $fieldName);
}
Expand All @@ -55,14 +54,12 @@ static function (
}

static::expectResolveFunction($field, $typeName, $fieldName);
}
},
);
}

/**
* @throws SchemaError
*/
protected static function expectResolveFunction(FieldDefinition $field, string $typeName, string $fieldName) : void
/** @throws SchemaError */
protected static function expectResolveFunction(FieldDefinition $field, string $typeName, string $fieldName): void
{
if (! $field->resolveFn) {
throw new TypeError('Resolve function missing for "' . $typeName . '.' . $fieldName . '"');
Expand Down
8 changes: 4 additions & 4 deletions src/Generate/AttachConnectorsToContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use GraphQLTools\Utils;
use stdClass;
use TypeError;

use function call_user_func;
use function class_exists;
use function count;
Expand All @@ -20,10 +21,8 @@

class AttachConnectorsToContext
{
/**
* @param mixed[] $connectors
*/
public static function invoke(Schema $schema, array $connectors) : void
/** @param mixed[] $connectors */
public static function invoke(Schema $schema, array $connectors): void
{
if (count($connectors) === 0) {
throw new TypeError('Expected connectors to not be an empty array');
Expand All @@ -42,6 +41,7 @@ public static function invoke(Schema $schema, array $connectors) : void
$attachconnectorFn = static function ($root, array $args, &$ctx) use ($connectors) {
if (! is_object($ctx)) {
$contextType = gettype($ctx);

throw new Exception('Cannot attach connector because context is not an object: ' . $contextType);
}

Expand Down
17 changes: 8 additions & 9 deletions src/Generate/AttachDirectiveResolvers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
use GraphQL\Type\Definition\FieldDefinition;
use GraphQL\Type\Schema;
use GraphQLTools\SchemaDirectiveVisitor;

use function call_user_func;

class AttachDirectiveResolvers
{
/**
* @param mixed[] $directiveResolvers
*/
public static function invoke(Schema $schema, array $directiveResolvers) : void
/** @param mixed[] $directiveResolvers */
public static function invoke(Schema $schema, array $directiveResolvers): void
{
$schemaDirectives = [];
foreach ($directiveResolvers as $directiveName => $resolver) {
Expand All @@ -28,10 +27,8 @@ public function __construct(callable $resolver)
$this->resolver = $resolver;
}

/**
* @param mixed[] $details
*/
public function visitFieldDefinition(FieldDefinition $field, array $details) : void
/** @param mixed[] $details */
public function visitFieldDefinition(FieldDefinition $field, array $details): mixed
{
$resolver = $this->resolver;
$originalResolver = $field->resolveFn ?? [Executor::class, 'defaultFieldResolver'];
Expand All @@ -48,9 +45,11 @@ static function () use ($originalResolver, $args) {
$source,
$directiveArgs,
$context,
$info
$info,
);
};

return null;
}
};
}
Expand Down
Loading