Skip to content

Commit

Permalink
Merge branch 3.0 into main
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Nov 4, 2022
2 parents d44ddb1 + 6771f53 commit 1f747a4
Show file tree
Hide file tree
Showing 93 changed files with 1,128 additions and 462 deletions.
32 changes: 32 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,24 @@
# Changelog

## v3.0.3

### Bug fixes

* [176fff2cb](https://github.com/api-platform/core/commit/176fff2cb15efa01b6c898d0442a4f540d4ddeaa) fix(metadata): upgrade script keep operation name (#5109)
* [1b64ebf6a](https://github.com/api-platform/core/commit/1b64ebf6a438222ae091ec3690063d0fb1b61977) fix: upgrade command remove ApiSubresource attribute (#5049)
* [27fcdc6b2](https://github.com/api-platform/core/commit/27fcdc6b270d1699e76c37ccda690b8a5ed8b4c9) fix(metadata): deprecate when user decorates in legacy mode (#5091)
* [310363d56](https://github.com/api-platform/core/commit/310363d56129c94cf4d51977f85486729e582fbc) fix: remove @internal annotation for Operations (#5089)
* [41bbad94e](https://github.com/api-platform/core/commit/41bbad94e93df49eb4ade0fe1307b20d9cd07102) fix: update yaml extractor test file coding standard (#5068)
* [44337ddb3](https://github.com/api-platform/core/commit/44337ddb3908d7b05ed75b75325b7941581f575b) fix(graphql): use right nested operation (#5102)
* [541b738e9](https://github.com/api-platform/core/commit/541b738e942156b711665952b50fbd4f060fcdea) fix(graphql): add clearer error message when TwigBundle is disabled but graphQL clients are enabled (#5064)
* [59826bbe9](https://github.com/api-platform/core/commit/59826bbe9e246cf839bdc0c4d0d470f54e27b453) fix: only alias if exists for opcache preload
* [7044c5a1b](https://github.com/api-platform/core/commit/7044c5a1b2895e72f0579d1e788740606f94dece) fix(doctrine): use abitrary index instead of value (#5079)
* [8250d41a3](https://github.com/api-platform/core/commit/8250d41a38913a17364d617875bb5a90f434ec48) fix(metadata): define a name on a single operation (#5090)
* [9c19fa171](https://github.com/api-platform/core/commit/9c19fa17110aac7dd39bff827091c00b42a80d4f) fix(metadata): add class key in payload argument resolver (#5067)
* [a4cd12b2a](https://github.com/api-platform/core/commit/a4cd12b2a73bc0f726c5724de790f885884e6113) fix: uri template should respect rfc 6570 (#5080)
* [bbeaf7082](https://github.com/api-platform/core/commit/bbeaf7082bba4a019206c3862425cf849d55addd) fix(graphql): always allow to query nested resources (#5112)
* [c1cb3cd2f](https://github.com/api-platform/core/commit/c1cb3cd2ff32c8b1ee694b0989efeb133fbd8438) Revert "fix(graphql): use right nested operation (#5102)" (#5111)

## 3.0.2

* Metadata: generate skolem IRI by default, use `genId: false` to disable **BC**
Expand Down Expand Up @@ -54,6 +73,19 @@ Breaking changes:
* Serializer: `skip_null_values` now defaults to `true`
* Metadata: `Patch` is added to the automatic CRUD

## v2.7.3

### Bug fixes

* [176fff2cb](https://github.com/api-platform/core/commit/176fff2cb15efa01b6c898d0442a4f540d4ddeaa) fix(metadata): upgrade script keep operation name (#5109)
* [1b64ebf6a](https://github.com/api-platform/core/commit/1b64ebf6a438222ae091ec3690063d0fb1b61977) fix: upgrade command remove ApiSubresource attribute (#5049)
* [27fcdc6b2](https://github.com/api-platform/core/commit/27fcdc6b270d1699e76c37ccda690b8a5ed8b4c9) fix(metadata): deprecate when user decorates in legacy mode (#5091)
* [310363d56](https://github.com/api-platform/core/commit/310363d56129c94cf4d51977f85486729e582fbc) fix: remove @internal annotation for Operations (#5089)
* [41bbad94e](https://github.com/api-platform/core/commit/41bbad94e93df49eb4ade0fe1307b20d9cd07102) fix: update yaml extractor test file coding standard (#5068)
* [59826bbe9](https://github.com/api-platform/core/commit/59826bbe9e246cf839bdc0c4d0d470f54e27b453) fix: only alias if exists for opcache preload
* [8250d41a3](https://github.com/api-platform/core/commit/8250d41a38913a17364d617875bb5a90f434ec48) fix(metadata): define a name on a single operation (#5090)
* [9c19fa171](https://github.com/api-platform/core/commit/9c19fa17110aac7dd39bff827091c00b42a80d4f) fix(metadata): add class key in payload argument resolver (#5067)

## 2.7.2

* Metadata: no skolem IRI by default
Expand Down
46 changes: 46 additions & 0 deletions features/graphql/collection.feature
Expand Up @@ -910,3 +910,49 @@ Feature: GraphQL collection support
Then the response status code should be 200
And the response should be in JSON
And the JSON node "data.fooDummies.collection" should have 1 element

@createSchema
Scenario: Retrieve paginated collections using mixed pagination
Given there are 5 fooDummy objects with fake names
When I send the following GraphQL request:
"""
{
fooDummies(page: 1) {
collection {
id
name
soManies(first: 2) {
edges {
node {
content
}
cursor
}
pageInfo {
startCursor
endCursor
hasNextPage
hasPreviousPage
}
}
}
paginationInfo {
itemsPerPage
lastPage
totalCount
}
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the JSON node "data.fooDummies.collection" should have 3 elements
And the JSON node "data.fooDummies.collection[2].id" should exist
And the JSON node "data.fooDummies.collection[2].name" should exist
And the JSON node "data.fooDummies.collection[2].soManies" should exist
And the JSON node "data.fooDummies.collection[2].soManies.edges" should have 2 elements
And the JSON node "data.fooDummies.collection[2].soManies.edges[1].node.content" should be equal to "So many 1"
And the JSON node "data.fooDummies.collection[2].soManies.pageInfo.startCursor" should be equal to "MA=="
And the JSON node "data.fooDummies.paginationInfo.itemsPerPage" should be equal to the number 3
And the JSON node "data.fooDummies.paginationInfo.lastPage" should be equal to the number 2
And the JSON node "data.fooDummies.paginationInfo.totalCount" should be equal to the number 5
36 changes: 31 additions & 5 deletions features/main/default_order.feature
Expand Up @@ -79,35 +79,61 @@ Feature: Default order
"@type": "FooDummy",
"id": 5,
"name": "Balbo",
"dummy": "/dummies/5"
"dummy": "/dummies/5",
"soManies": [
"/so_manies/13",
"/so_manies/14",
"/so_manies/15"
]
},
{
"@id": "/foo_dummies/3",
"@type": "FooDummy",
"id": 3,
"name": "Sthenelus",
"dummy": "/dummies/3"
"dummy": "/dummies/3",
"soManies": [
"/so_manies/7",
"/so_manies/8",
"/so_manies/9"
]
},
{
"@id": "/foo_dummies/2",
"@type": "FooDummy",
"id": 2,
"name": "Ephesian",
"dummy": "/dummies/2"
"dummy": "/dummies/2",
"soManies": [
"/so_manies/4",
"/so_manies/5",
"/so_manies/6"
]
},
{
"@id": "/foo_dummies/1",
"@type": "FooDummy",
"id": 1,
"name": "Hawsepipe",
"dummy": "/dummies/1"
"dummy": "/dummies/1",
"soManies": [
"/so_manies/1",
"/so_manies/2",
"/so_manies/3"
]
},
{
"@id": "/foo_dummies/4",
"@type": "FooDummy",
"id": 4,
"name": "Separativeness",
"dummy": "/dummies/4"
"dummy": "/dummies/4",
"soManies": [
"/so_manies/10",
"/so_manies/11",
"/so_manies/12"
]
}
],
"hydra:totalItems": 5,
Expand Down
25 changes: 25 additions & 0 deletions generate-changelog.sh
@@ -0,0 +1,25 @@
#!/bin/bash
# usage: generate-changelog.sh previous_tag next_tag
# example: generate-changelog.sh v2.7.2 v2.7.3 > CHANGELOG.new.md
log=$(git log "$1..HEAD" --pretty='format:* [%h](https://github.com/api-platform/core/commit/%H) %s' --no-merges)

diff=$(
printf "# Changelog\n\n"
printf "## %s\n\n" "$2"
if [[ 0 != $(echo "$log" | grep fix | grep -v chore | wc -l) ]];
then
printf "### Bug fixes\n\n"
printf "$log" | grep fix | grep -v chore | sort
printf "\n\n"
fi
if [[ 0 != $(echo "$log" | grep feat | grep -v chore | wc -l) ]];
then
printf "### Features\n\n"
printf "$log" | grep feat | grep -v chore | sort
fi
)

changelog=$(tail -n+2 CHANGELOG.md)
printf "%s\n%s" "$diff" "$changelog"
3 changes: 1 addition & 2 deletions src/Doctrine/Odm/Extension/OrderExtension.php
Expand Up @@ -19,7 +19,6 @@
use Doctrine\ODM\MongoDB\Aggregation\Builder;
use Doctrine\ODM\MongoDB\Aggregation\Stage\Sort;
use Doctrine\Persistence\ManagerRegistry;
use OutOfRangeException;

/**
* Applies selected ordering while querying resource collection.
Expand Down Expand Up @@ -100,7 +99,7 @@ private function hasSortStage(Builder $aggregationBuilder): bool
// If at least one stage is sort, then it has sorting
return true;
}
} catch (OutOfRangeException) {
} catch (\OutOfRangeException $outOfRangeException) {
// There is no more stages on the aggregation builder
$shouldStop = true;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Doctrine/Orm/Filter/SearchFilter.php
Expand Up @@ -179,7 +179,7 @@ protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuild
$parameters = [];
foreach ($values as $key => $value) {
$keyValueParameter = sprintf('%s_%s', $valueParameter, $key);
$parameters[$caseSensitive ? $value : strtolower($value)] = $keyValueParameter;
$parameters[] = [$caseSensitive ? $value : strtolower($value), $keyValueParameter];

$ors[] = match ($strategy) {
self::STRATEGY_PARTIAL => $queryBuilder->expr()->like(
Expand Down Expand Up @@ -209,7 +209,9 @@ protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuild
}

$queryBuilder->andWhere($queryBuilder->expr()->orX(...$ors));
array_walk($parameters, $queryBuilder->setParameter(...));
foreach ($parameters as $parameter) {
$queryBuilder->setParameter($parameter[1], $parameter[0]);
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/GraphQl/Action/EntrypointAction.php
Expand Up @@ -34,7 +34,7 @@ final class EntrypointAction
{
private int $debug;

public function __construct(private readonly SchemaBuilderInterface $schemaBuilder, private readonly ExecutorInterface $executor, private readonly GraphiQlAction $graphiQlAction, private readonly GraphQlPlaygroundAction $graphQlPlaygroundAction, private readonly NormalizerInterface $normalizer, private readonly ErrorHandlerInterface $errorHandler, bool $debug = false, private readonly bool $graphiqlEnabled = false, private readonly bool $graphQlPlaygroundEnabled = false, private readonly ?string $defaultIde = null)
public function __construct(private readonly SchemaBuilderInterface $schemaBuilder, private readonly ExecutorInterface $executor, private readonly ?GraphiQlAction $graphiQlAction, private readonly ?GraphQlPlaygroundAction $graphQlPlaygroundAction, private readonly NormalizerInterface $normalizer, private readonly ErrorHandlerInterface $errorHandler, bool $debug = false, private readonly bool $graphiqlEnabled = false, private readonly bool $graphQlPlaygroundEnabled = false, private readonly ?string $defaultIde = null)
{
$this->debug = $debug ? DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE : DebugFlag::NONE;
}
Expand All @@ -43,11 +43,11 @@ public function __invoke(Request $request): Response
{
try {
if ($request->isMethod('GET') && 'html' === $request->getRequestFormat()) {
if ('graphiql' === $this->defaultIde && $this->graphiqlEnabled) {
if ('graphiql' === $this->defaultIde && $this->graphiqlEnabled && $this->graphiQlAction) {
return ($this->graphiQlAction)($request);
}

if ('graphql-playground' === $this->defaultIde && $this->graphQlPlaygroundEnabled) {
if ('graphql-playground' === $this->defaultIde && $this->graphQlPlaygroundEnabled && $this->graphQlPlaygroundAction) {
return ($this->graphQlPlaygroundAction)($request);
}
}
Expand Down
@@ -0,0 +1,67 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\GraphQl\Metadata\Factory;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Resource\Factory\OperationDefaultsTrait;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;

final class GraphQlNestedOperationResourceMetadataFactory implements ResourceMetadataCollectionFactoryInterface
{
use OperationDefaultsTrait;

public function __construct(array $defaults, private readonly ?ResourceMetadataCollectionFactoryInterface $decorated = null, ?LoggerInterface $logger = null)
{
$this->defaults = $defaults;
$this->camelCaseToSnakeCaseNameConverter = new CamelCaseToSnakeCaseNameConverter();
$this->logger = $logger ?? new NullLogger();
}

public function create(string $resourceClass): ResourceMetadataCollection
{
$resourceMetadataCollection = new ResourceMetadataCollection($resourceClass);

if ($this->decorated) {
$resourceMetadataCollection = $this->decorated->create($resourceClass);
}

if (0 < \count($resourceMetadataCollection)) {
return $resourceMetadataCollection;
}

$shortName = (false !== $pos = strrpos($resourceClass, '\\')) ? substr($resourceClass, $pos + 1) : $resourceClass;

$apiResource = new ApiResource(
class: $resourceClass,
shortName: $shortName
);

if (class_exists($resourceClass)) {
$refl = new \ReflectionClass($resourceClass);
$attribute = $refl->getAttributes(ApiResource::class)[0] ?? null;
$attributeInstance = $attribute?->newInstance();
if ($filters = $attributeInstance?->getFilters()) {
$apiResource = $apiResource->withFilters($filters);
}
}

$resourceMetadataCollection[0] = $this->addDefaultGraphQlOperations($apiResource);

return $resourceMetadataCollection;
}
}

0 comments on commit 1f747a4

Please sign in to comment.