Skip to content

Commit

Permalink
兼容 lighthouse ~4.0,删除 group 指令
Browse files Browse the repository at this point in the history
  • Loading branch information
hwbrzzl committed Oct 8, 2019
1 parent b79934a commit 926893e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 107 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"require-dev": {
"composer/composer": "^1.7",
"mockery/mockery": "~1.0",
"nuwave/lighthouse": "~3.0",
"nuwave/lighthouse": "~4.0",
"orchestra/database": "3.5.*|3.6.*|3.7.*@dev",
"orchestra/testbench": "3.5.*|3.6.*|3.7.*",
"phpunit/phpunit": "~7.0"
Expand Down
45 changes: 31 additions & 14 deletions src/Lighthouse/Directives/GetlistDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
use GraphQL\Language\AST\ObjectTypeDefinitionNode;
use Nuwave\Lighthouse\Exceptions\DirectiveException;
use Nuwave\Lighthouse\Schema\Directives\BaseDirective;
use Nuwave\Lighthouse\Support\Contracts\DefinedDirective;
use Nuwave\Lighthouse\Support\Contracts\FieldResolver;
use Nuwave\Lighthouse\Support\Contracts\FieldManipulator;
use MatrixLab\LaravelAdvancedSearch\ConditionsGeneratorTrait;

class GetlistDirective extends BaseDirective implements FieldResolver, FieldManipulator
class GetlistDirective extends BaseDirective implements FieldResolver, FieldManipulator, DefinedDirective
{

use ConditionsGeneratorTrait;

/**
Expand All @@ -28,30 +30,45 @@ public function name(): string
return 'getlist';
}

public static function definition(): string
{
return /* @lang GraphQL */ <<<'SDL'
"""
Query multiple entries as a paginated list.
"""
directive @getlist(
"""
Reference a function to customize the complexity score calculation.
Consists of two parts: a class name and a method name, seperated by an `@` symbol.
If you pass only a class name, the method name defaults to `__invoke`.
"""
resolver: String
) on FIELD_DEFINITION
SDL;
}

/**
* @param FieldDefinitionNode $fieldDefinition
* @param ObjectTypeDefinitionNode $parentType
* @param DocumentAST $current
* @param FieldDefinitionNode $fieldDefinition
* @param ObjectTypeDefinitionNode $parentType
* @param DocumentAST $current
*
* @return DocumentAST
* @throws DirectiveException
* @throws \Nuwave\Lighthouse\Exceptions\ParseException
*/
public function manipulateSchema(FieldDefinitionNode $fieldDefinition, ObjectTypeDefinitionNode $parentType, DocumentAST $current): DocumentAST
{
return PaginationManipulator::transformToPaginatedField(
$this->getPaginationType(),
$fieldDefinition,
$parentType,
$current,
$this->directiveArgValue('defaultCount')
);
public function manipulateFieldDefinition(
DocumentAST &$documentAST,
FieldDefinitionNode &$fieldDefinition,
ObjectTypeDefinitionNode &$parentType
): void {
PaginationManipulator::transformToPaginatedField($this->getPaginationType(), $fieldDefinition, $parentType,
$documentAST, $this->directiveArgValue('defaultCount'));
}

/**
* Resolve the field directive.
*
* @param FieldValue $fieldValue
* @param FieldValue $fieldValue
*
* @return FieldValue
* @throws DirectiveException
Expand Down
88 changes: 0 additions & 88 deletions src/Lighthouse/Directives/GroupDirective.php

This file was deleted.

8 changes: 4 additions & 4 deletions src/Lighthouse/Directives/PaginationManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ public static function registerPaginator(FieldDefinitionNode $fieldDefinition, O
$fieldDefinition->type = PartialParser::namedType($paginatorTypeName);
$parentType->fields = ASTHelper::mergeNodeList($parentType->fields, [$fieldDefinition]);

$documentAST->setDefinition($paginatorType);
$documentAST->setDefinition($parentType);
$documentAST->setDefinition($paginationCursor);
$documentAST->setDefinition($paginatorInput);
$documentAST->setTypeDefinition($paginatorType);
$documentAST->setTypeDefinition($parentType);
$documentAST->setTypeDefinition($paginationCursor);
$documentAST->setTypeDefinition($paginatorInput);

return $documentAST;
}
Expand Down

0 comments on commit 926893e

Please sign in to comment.