Skip to content

Commit

Permalink
composer fix-style
Browse files Browse the repository at this point in the history
  • Loading branch information
mfn committed Nov 27, 2019
1 parent 876759d commit 44e3ee8
Show file tree
Hide file tree
Showing 20 changed files with 201 additions and 91 deletions.
6 changes: 4 additions & 2 deletions src/GraphQL.php
Expand Up @@ -239,10 +239,12 @@ protected function buildObjectTypeFromClass($type, array $opts = []): Type

if (! $type instanceof TypeConvertible) {
throw new TypeNotFound(
sprintf('Unable to convert %s to a GraphQL type, please add/implement the interface %s',
sprintf(
'Unable to convert %s to a GraphQL type, please add/implement the interface %s',
get_class($type),
TypeConvertible::class
));
)
);
}

foreach ($opts as $key => $value) {
Expand Down
12 changes: 8 additions & 4 deletions src/Support/ResolveInfoFieldsAndArguments.php
Expand Up @@ -130,12 +130,16 @@ private function foldSelectionSet(SelectionSetNode $selectionSet, int $descend):
$spreadName = $selectionNode->name->value;
if (isset($this->info->fragments[$spreadName])) {
$fragment = $this->info->fragments[$spreadName];
$fields = (array) array_replace_recursive($this->foldSelectionSet($fragment->selectionSet, $descend),
$fields);
$fields = (array) array_replace_recursive(
$this->foldSelectionSet($fragment->selectionSet, $descend),
$fields
);
}
} elseif ($selectionNode instanceof InlineFragmentNode) {
$fields = (array) array_replace_recursive($this->foldSelectionSet($selectionNode->selectionSet, $descend),
$fields);
$fields = (array) array_replace_recursive(
$this->foldSelectionSet($selectionNode->selectionSet, $descend),
$fields
);
}
}

Expand Down
59 changes: 46 additions & 13 deletions src/Support/SelectFields.php
Expand Up @@ -190,8 +190,14 @@ protected static function handleFields(
if (is_a($parentType, config('graphql.pagination_type', PaginationType::class))) {
/* @var GraphqlType $fieldType */
$fieldType = $fieldObject->config['type'];
self::handleFields($queryArgs, $field, $fieldType->getWrappedType(), $select,
$with, $ctx);
self::handleFields(
$queryArgs,
$field,
$fieldType->getWrappedType(),
$select,
$with,
$ctx
);
}
// With
elseif (is_array($field['fields']) && $queryable) {
Expand All @@ -208,11 +214,26 @@ protected static function handleFields(

self::addAlwaysFields($fieldObject, $field, $parentTable, true);

$with[$relationsKey] = self::getSelectableFieldsAndRelations($queryArgs, $field, $newParentType,
$customQuery, false, $ctx);
$with[$relationsKey] = self::getSelectableFieldsAndRelations(
$queryArgs,
$field,
$newParentType,
$customQuery,
false,
$ctx
);
} elseif (is_a($parentTypeUnwrapped, \GraphQL\Type\Definition\InterfaceType::class)) {
self::handleInterfaceFields($queryArgs, $field, $parentTypeUnwrapped, $select, $with, $ctx,
$fieldObject, $key, $customQuery);
self::handleInterfaceFields(
$queryArgs,
$field,
$parentTypeUnwrapped,
$select,
$with,
$ctx,
$fieldObject,
$key,
$customQuery
);
} else {
self::handleFields($queryArgs, $field, $fieldObject->config['type'], $select, $with, $ctx);
}
Expand Down Expand Up @@ -361,8 +382,11 @@ private static function handleRelation(array &$select, $relation, ?string $paren
} else {
$foreignKey = $relation->getQualifiedForeignKeyName();
}
$foreignKey = $parentTable ? ($parentTable.'.'.preg_replace('/^'.preg_quote($parentTable, '/').'\./',
'', $foreignKey)) : $foreignKey;
$foreignKey = $parentTable ? ($parentTable.'.'.preg_replace(
'/^'.preg_quote($parentTable, '/').'\./',
'',
$foreignKey
)) : $foreignKey;
if (is_a($relation, MorphTo::class)) {
$foreignKeyType = $relation->getMorphType();
$foreignKeyType = $parentTable ? ($parentTable.'.'.$foreignKeyType) : $foreignKeyType;
Expand All @@ -377,8 +401,10 @@ private static function handleRelation(array &$select, $relation, ?string $paren
$select[] = $foreignKey;
}
} // If 'HasMany', then add it in the 'with'
elseif ((is_a($relation, HasMany::class) || is_a($relation, MorphMany::class) || is_a($relation,
HasOne::class) || is_a($relation, MorphOne::class))
elseif ((is_a($relation, HasMany::class) || is_a($relation, MorphMany::class) || is_a(
$relation,
HasOne::class
) || is_a($relation, MorphOne::class))
&& ! array_key_exists($foreignKey, $field)) {
$segments = explode('.', $foreignKey);
$foreignKey = end($segments);
Expand Down Expand Up @@ -478,7 +504,8 @@ protected static function handleInterfaceFields(
function (GraphqlType $type) use ($query) {
/* @var Relation $query */
return app($type->config['model'])->getTable() === $query->getParent()->getTable();
});
}
);
$typesFiltered = array_values($typesFiltered ?? []);

if (count($typesFiltered) === 1) {
Expand All @@ -496,8 +523,14 @@ function (GraphqlType $type) use ($query) {
}

/** @var callable $callable */
$callable = self::getSelectableFieldsAndRelations($queryArgs, $field, $newParentType, $customQuery,
false, $ctx);
$callable = self::getSelectableFieldsAndRelations(
$queryArgs,
$field,
$newParentType,
$customQuery,
false,
$ctx
);

return $callable($query);
};
Expand Down
Expand Up @@ -36,7 +36,8 @@ public function testUniquePassRulePass(): void
],
]);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select count(*) as aggregate from "users" where "name" = ?;
SQL
);
Expand Down Expand Up @@ -72,7 +73,8 @@ public function testUniqueFailRulePass(): void
],
]);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select count(*) as aggregate from "users" where "name" = ?;
SQL
);
Expand Down Expand Up @@ -143,7 +145,8 @@ public function testUniqueFailRuleFail(): void
],
]);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select count(*) as aggregate from "users" where "name" = ?;
SQL
);
Expand Down
Expand Up @@ -51,7 +51,8 @@ public function testAlwaysSingleHasManyRelationField(): void
'expectErrors' => true,
]);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "users"."id" from "users";
SQL
);
Expand Down Expand Up @@ -134,7 +135,8 @@ public function testAlwaysSingleMorphRelationField(): void
'expectErrors' => true,
]);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "users"."name", "users"."id" from "users";
SQL
);
Expand Down
12 changes: 8 additions & 4 deletions tests/Database/SelectFields/AlwaysTests/AlwaysTest.php
Expand Up @@ -44,7 +44,8 @@ public function testAlwaysSingleField(): void

$result = $this->graphql($query);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "posts"."body", "posts"."title", "posts"."id" from "posts";
select "comments"."id", "comments"."post_id", "comments"."body" from "comments" where "comments"."post_id" in (?) order by "comments"."id" asc;
SQL
Expand Down Expand Up @@ -99,7 +100,8 @@ public function testAlwaysSingleMultipleFieldInString(): void

$result = $this->graphql($query);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "posts"."body", "posts"."title", "posts"."id" from "posts";
select "comments"."id", "comments"."post_id", "comments"."body", "comments"."title" from "comments" where "comments"."post_id" in (?) order by "comments"."id" asc;
SQL
Expand Down Expand Up @@ -154,7 +156,8 @@ public function testAlwaysSingleMultipleFieldInArray(): void

$result = $this->graphql($query);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "posts"."body", "posts"."title", "posts"."id" from "posts";
select "comments"."id", "comments"."post_id", "comments"."body", "comments"."title" from "comments" where "comments"."post_id" in (?) order by "comments"."id" asc;
SQL
Expand Down Expand Up @@ -209,7 +212,8 @@ public function testAlwaysSameFieldTwice(): void

$result = $this->graphql($query);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "posts"."body", "posts"."title", "posts"."id" from "posts";
select "comments"."id", "comments"."post_id", "comments"."body" from "comments" where "comments"."post_id" in (?) order by "comments"."id" asc;
SQL
Expand Down
Expand Up @@ -42,7 +42,8 @@ public function testComputedProperty(): void

$result = $this->graphql($query);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "users"."id", "users"."name" from "users";
select "posts"."id", "posts"."published_at", "posts"."user_id" from "posts" where "posts"."user_id" in (?) order by "posts"."id" asc;
SQL
Expand Down
3 changes: 2 additions & 1 deletion tests/Database/SelectFields/DepthTests/DepthTest.php
Expand Up @@ -96,7 +96,8 @@ public function testDefaultDepthAdjusted(): void

$result = $this->graphql($graphql);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "users"."id" from "users";
select "posts"."id", "posts"."user_id" from "posts" where "posts"."user_id" in (?) order by "posts"."id" asc;
select "users"."id" from "users" where "users"."id" in (?);
Expand Down
24 changes: 16 additions & 8 deletions tests/Database/SelectFields/InterfaceTests/InterfaceTest.php
Expand Up @@ -34,7 +34,8 @@ public function testGeneratedSqlQuery(): void

$result = $this->graphql($graphql);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "title" from "posts";
SQL
);
Expand Down Expand Up @@ -79,7 +80,8 @@ public function testGeneratedRelationSqlQuery(): void

$result = $this->graphql($graphql);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "id", "title" from "posts";
select "comments"."title", "comments"."post_id", "comments"."id" from "comments" where "comments"."post_id" in (?) and "id" >= ? order by "comments"."id" asc;
SQL
Expand Down Expand Up @@ -141,14 +143,16 @@ public function testGeneratedInterfaceFieldSqlQuery(): void
$result = $this->graphql($graphql);

if (Application::VERSION < '5.6') {
$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "users"."id" from "users";
select "likes"."likable_id", "likes"."likable_type", "likes"."user_id", "likes"."id" from "likes" where "likes"."user_id" in (?);
select * from "posts" where "posts"."id" in (?);
SQL
);
} else {
$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "users"."id" from "users";
select "likes"."likable_id", "likes"."likable_type", "likes"."user_id", "likes"."id" from "likes" where "likes"."user_id" in (?);
select "id", "title" from "posts" where "posts"."id" in (?);
Expand Down Expand Up @@ -223,15 +227,17 @@ public function testGeneratedInterfaceFieldWithRelationSqlQuery(): void
$result = $this->graphql($graphql);

if (Application::VERSION < '5.6') {
$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "users"."id" from "users";
select "likes"."likable_id", "likes"."likable_type", "likes"."user_id", "likes"."id" from "likes" where "likes"."user_id" in (?, ?);
select * from "posts" where "posts"."id" in (?);
select "likes"."id", "likes"."likable_id", "likes"."likable_type" from "likes" where "likes"."likable_id" in (?) and "likes"."likable_type" = ? and 0=0;
SQL
);
} else {
$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "users"."id" from "users";
select "likes"."likable_id", "likes"."likable_type", "likes"."user_id", "likes"."id" from "likes" where "likes"."user_id" in (?, ?);
select "id", "title" from "posts" where "posts"."id" in (?);
Expand Down Expand Up @@ -334,15 +340,17 @@ public function testGeneratedInterfaceFieldWithRelationAndCustomQueryOnInterface
$result = $this->graphql($graphql);

if (Application::VERSION < '5.6') {
$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "users"."id" from "users";
select "likes"."likable_id", "likes"."likable_type", "likes"."user_id", "likes"."id" from "likes" where "likes"."user_id" in (?, ?);
select * from "comments" where "comments"."id" in (?);
select "likes"."id", "likes"."likable_id", "likes"."likable_type" from "likes" where "likes"."likable_id" in (?) and "likes"."likable_type" = ? and 1=1;
SQL
);
} else {
$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "users"."id" from "users";
select "likes"."likable_id", "likes"."likable_type", "likes"."user_id", "likes"."id" from "likes" where "likes"."user_id" in (?, ?);
select "id", "title" from "comments" where "comments"."id" in (?);
Expand Down
Expand Up @@ -55,7 +55,8 @@ public function testQueryNoSelectFields(): void

$result = $this->graphql($graphql);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select * from "users" order by "users"."id" asc;
select * from "posts" where "posts"."user_id" = ? and "posts"."user_id" is not null order by "posts"."id" asc;
select * from "comments" where "comments"."post_id" = ? and "comments"."post_id" is not null order by "comments"."id" asc;
Expand Down Expand Up @@ -196,7 +197,8 @@ public function testQuerySelect(): void

$result = $this->graphql($graphql);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "users"."id", "users"."name" from "users" order by "users"."id" asc;
select * from "posts" where "posts"."user_id" = ? and "posts"."user_id" is not null order by "posts"."id" asc;
select * from "comments" where "comments"."post_id" = ? and "comments"."post_id" is not null order by "comments"."id" asc;
Expand Down Expand Up @@ -337,7 +339,8 @@ public function testQueryWith(): void

$result = $this->graphql($graphql);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select * from "users" order by "users"."id" asc;
select "posts"."body", "posts"."id", "posts"."title", "posts"."user_id" from "posts" where "posts"."user_id" in (?, ?) order by "posts"."id" asc;
select "comments"."body", "comments"."id", "comments"."title", "comments"."post_id" from "comments" where "comments"."post_id" in (?, ?, ?, ?) order by "comments"."id" asc;
Expand Down Expand Up @@ -474,7 +477,8 @@ public function testQuerySelectAndWith(): void

$result = $this->graphql($graphql);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "users"."id", "users"."name" from "users" order by "users"."id" asc;
select "posts"."body", "posts"."id", "posts"."title", "posts"."user_id" from "posts" where "posts"."user_id" in (?, ?) order by "posts"."id" asc;
select "comments"."body", "comments"."id", "comments"."title", "comments"."post_id" from "comments" where "comments"."post_id" in (?, ?, ?, ?) order by "comments"."id" asc;
Expand Down Expand Up @@ -624,7 +628,8 @@ public function testQuerySelectAndWithAndSubArgs(): void

$result = $this->graphql($graphql);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "users"."id", "users"."name" from "users" order by "users"."id" asc;
select "posts"."body", "posts"."id", "posts"."title", "posts"."user_id" from "posts" where "posts"."user_id" in (?, ?) and "posts"."flag" = ? order by "posts"."id" asc;
select "comments"."body", "comments"."id", "comments"."title", "comments"."post_id" from "comments" where "comments"."post_id" in (?, ?) order by "comments"."id" asc;
Expand Down Expand Up @@ -750,7 +755,8 @@ public function testQuerySelectAndWithAndNestedSubArgs(): void

$result = $this->graphql($graphql);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "users"."id", "users"."name" from "users" order by "users"."id" asc;
select "posts"."body", "posts"."id", "posts"."title", "posts"."user_id" from "posts" where "posts"."user_id" in (?, ?) and "posts"."flag" = ? order by "posts"."id" asc;
select "comments"."body", "comments"."id", "comments"."title", "comments"."post_id" from "comments" where "comments"."post_id" in (?, ?) and "comments"."flag" = ? order by "comments"."id" asc;
Expand Down Expand Up @@ -833,7 +839,8 @@ public function testRelationshipAlias(): void

$result = $this->graphql($graphql);

$this->assertSqlQueries(<<<'SQL'
$this->assertSqlQueries(
<<<'SQL'
select "users"."id", "users"."name" from "users" order by "users"."id" asc;
select "posts"."body", "posts"."id", "posts"."title", "posts"."user_id" from "posts" where "posts"."user_id" in (?) and "posts"."flag" = ? order by "posts"."id" asc;
SQL
Expand Down

0 comments on commit 44e3ee8

Please sign in to comment.