Skip to content

Commit

Permalink
Merge 4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Jan 10, 2025
2 parents 9389b4f + 361fd6c commit a8d0c84
Show file tree
Hide file tree
Showing 27 changed files with 175 additions and 48 deletions.
38 changes: 38 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Changelog

## v4.1.0-alpha.1

### Bug fixes

* [67fbe51c5](https://github.com/api-platform/core/commit/67fbe51c570abe1ece6651ae6a037662e9012881) fix: reintroduce the `show_webby` parameter in Laravel config (#6741)

### Features

* [00787f32d](https://github.com/api-platform/core/commit/00787f32da54418de7d869cff218e22d8ae2ae1d) feat(laravel): automatically register policies (#6623)
* [12c42096b](https://github.com/api-platform/core/commit/12c42096bb0006d6ebae60ae5d90e9b356f9a335) feat(metadata): ability to hide an hydra class/operation (#6871)
* [57f15cf4f](https://github.com/api-platform/core/commit/57f15cf4f38278315c5f31d3949416c9455ba0d0) feat(state): strict query parameters (#6399)
* [bd0e92936](https://github.com/api-platform/core/commit/bd0e92936f82d3cd4563cd45ebf1f73fd1db9f01) feat(openapi): HTTP Authentication Support for Swagger UI (#6665)
* [be98f4e01](https://github.com/api-platform/core/commit/be98f4e01a52d8341ef9b65ed2f4e3b46ab31165) feat(graphql): allow to configure max query depth and max query complexity (#6880)
* [c78ed0b78](https://github.com/api-platform/core/commit/c78ed0b78baf5d2e1b7444a9882ba039c70a3887) feat(laravel): boolean filter (#6806)
* [d0a442786](https://github.com/api-platform/core/commit/d0a44278630d201b91cbba0774a09f4eeaac88f7) feat(doctrine): enhance getLinksHandler with method validation and typo suggestions (#6874)
* [f67f6f1ac](https://github.com/api-platform/core/commit/f67f6f1acb6476182c18a3503f2a8bc80ae89a0b) feat(doctrine): doctrine filters like laravel eloquent filters (#6775)

## v4.0.14

### Bug fixes

* [97cdb6b3f](https://github.com/api-platform/core/commit/97cdb6b3f43471789e096c9dc3a0c3c7b6d4e43c) fix(state): remove ProcessorInterface laravel specific type
* [b12a0d005](https://github.com/api-platform/core/commit/b12a0d005fda58a162b82a3574e6ee877838a55b) fix(graphql): register types for parameter args (#6895)

### Features

## v4.0.13

### Bug fixes
Expand Down Expand Up @@ -248,6 +274,18 @@ Notes:

* [0d5f35683](https://github.com/api-platform/core/commit/0d5f356839eb6aa9f536044abe4affa736553e76) feat(laravel): laravel component (#5882)

## v3.4.14

### Bug fixes

* [0cf752bce](https://github.com/api-platform/core/commit/0cf752bcec692718b2503250e655d05aea670316) fix(metadata): make the schema attribute to fallback to null for parameters in YamlResourceExtractor (#6896)
* [2b3c55db2](https://github.com/api-platform/core/commit/2b3c55db2a9ecc52f62c441fa8a5696233a30b87) fix(symfony): remove unsolvable deprecation (#6899) see also (#6655)
* [9493b9b6e](https://github.com/api-platform/core/commit/9493b9b6ec0264ab5b700c861ad1b97455b4f88d) fix(symfony): revert json schema bc break (#6903)
* [b82f9ac76](https://github.com/api-platform/core/commit/b82f9ac76ce89dd3910849c73da42317ee1339ed) fix(openapi): not forbidden response on openAPI doc (#6886)

I mispublished a v3.4.13 on some repositories to fix them all I bumped 3.4.10 to 3.4.14
More details at #6888.

## v3.4.10

### Bug fixes
Expand Down
10 changes: 9 additions & 1 deletion src/GraphQl/Type/FieldsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,15 @@ private function getResourceFieldConfiguration(?string $property, ?string $field
}

$args = $this->getFilterArgs($args, $resourceClass, $rootResource, $resourceOperation, $rootOperation, $property, $depth);
$args = $this->getParameterArgs($rootOperation, $args);

// Also register parameter args in the types container
// Note: This is a workaround, for more information read the comment on the parameterToObjectType function.
foreach ($this->getParameterArgs($rootOperation) as $key => $arg) {
if ($arg instanceof InputObjectType || (\is_array($arg) && isset($arg['name']))) {
$this->typesContainer->set(\is_array($arg) ? $arg['name'] : $arg->name(), $arg);
}
$args[$key] = $arg;
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/Laravel/Eloquent/Filter/DateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ public function getSchema(Parameter $parameter): array
return ['type' => 'date'];
}

public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null
/**
* @return OpenApiParameter[]
*/
public function getOpenApiParameters(Parameter $parameter): array
{
$in = $parameter instanceof QueryParameter ? 'query' : 'header';
$key = $parameter->getKey();
Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/Eloquent/Filter/OrFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getSchema(Parameter $parameter): array
return ['type' => 'array', 'items' => $schema];
}

public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null
public function getOpenApiParameters(Parameter $parameter): OpenApiParameter
{
return new OpenApiParameter(name: $parameter->getKey().'[]', in: 'query', style: 'deepObject', explode: true);
}
Expand Down
5 changes: 4 additions & 1 deletion src/Laravel/Eloquent/Filter/OrderFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public function getSchema(Parameter $parameter): array
return ['type' => 'string', 'enum' => ['asc', 'desc']];
}

public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null
/**
* @return OpenApiParameter[]|null
*/
public function getOpenApiParameters(Parameter $parameter): ?array
{
if (str_contains($parameter->getKey(), ':property')) {
$parameters = [];
Expand Down
5 changes: 4 additions & 1 deletion src/Laravel/Eloquent/Filter/RangeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public function getSchema(Parameter $parameter): array
return ['type' => 'number'];
}

public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null
/**
* @return OpenApiParameter[]
*/
public function getOpenApiParameters(Parameter $parameter): array
{
$in = $parameter instanceof QueryParameter ? 'query' : 'header';
$key = $parameter->getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function create(string $resourceClass, string $property, array $options =

return $propertyMetadata
->withBuiltinTypes([$type])
->withWritable($propertyMetadata->isWritable() ?? true)
->withWritable($propertyMetadata->isWritable() ?? true === $p['fillable'])
->withReadable($propertyMetadata->isReadable() ?? false === $p['hidden']);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/Eloquent/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(

public function count(): int
{
return $this->paginator->count();
return $this->paginator->count(); // @phpstan-ignore-line
}

public function getLastPage(): float
Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/Eloquent/PartialPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(

public function count(): int
{
return $this->paginator->count();
return $this->paginator->count(); // @phpstan-ignore-line
}

public function getCurrentPage(): float
Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/Routing/IriConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private function generateRoute(object|string $resource, int $referenceType = Url
if (\is_object($resource)) {
try {
$identifiers = $this->identifiersExtractor->getIdentifiersFromItem($resource, $identifiersExtractorOperation, $context);
} catch (InvalidArgumentException|RuntimeException $e) {
} catch (RuntimeException $e) {
// We can try using context uri variables if any
if (!$identifiers) {
throw new InvalidArgumentException(\sprintf('Unable to generate an IRI for the item of type "%s"', $operation->getClass()), $e->getCode(), $e);
Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/Routing/SkolemIriConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function getResourceFromIri(string $iri, array $context = [], ?Operation
/**
* {@inheritdoc}
*/
public function getIriFromResource(object|string $resource, int $referenceType = UrlGeneratorInterface::ABS_PATH, ?Operation $operation = null, array $context = []): ?string
public function getIriFromResource(object|string $resource, int $referenceType = UrlGeneratorInterface::ABS_PATH, ?Operation $operation = null, array $context = []): string
{
$referenceType = $operation ? ($operation->getUrlGenerationStrategy() ?? $referenceType) : $referenceType;
if (($isObject = \is_object($resource)) && $this->objectHashMap->contains($resource)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MakeStateProcessorCommandTest extends TestCase
/** @var string */
private const CHOSEN_CLASS_NAME = 'Choose a class name for your state processor (e.g. <fg=yellow>AwesomeStateProcessor</>)';

private ?Filesystem $filesystem;
private Filesystem $filesystem;
private PathResolver $pathResolver;
private AppServiceFileGenerator $appServiceFileGenerator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MakeStateProviderCommandTest extends TestCase
/** @var string */
private const STATE_PROVIDER_CLASS_NAME = 'Choose a class name for your state provider (e.g. <fg=yellow>AwesomeStateProvider</>)';

private ?Filesystem $filesystem;
private Filesystem $filesystem;
private PathResolver $pathResolver;
private AppServiceFileGenerator $appServiceFileGenerator;

Expand Down
37 changes: 27 additions & 10 deletions src/Laravel/Tests/GraphQlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,37 @@ public function testGetBooksWithSimplePagination(): void

public function testGetBooksWithPaginationAndOrder(): void
{
BookFactory::new()->has(AuthorFactory::new())->count(10)->create();
$response = $this->postJson('/api/graphql', ['query' => '{
books(first: 3, order: {name: "desc"}) {
edges {
node {
id, name, publicationDate, author { id, name }
}
}
}
}'], ['accept' => ['application/json']]);
// Create books in reverse alphabetical order to test the 'asc' order
BookFactory::new()
->count(10)
->sequence(fn ($sequence) => ['name' => \chr(122 - $sequence->index)]) // ASCII codes starting from 'z'
->has(AuthorFactory::new())
->create();

$response = $this->postJson('/api/graphql', [
'query' => '
query getBooks($first: Int!, $order: orderBookcollection_query!) {
books(first: $first, order: $order) {
edges {
node {
id, name, publicationDate, author { id, name }
}
}
}
}
',
'variables' => [
'first' => 3,
'order' => ['name' => 'asc'],
],
], ['accept' => ['application/json']]);
$response->assertStatus(200);
$data = $response->json();
$this->assertArrayHasKey('data', $data);
$this->assertCount(3, $data['data']['books']['edges']);
$this->assertEquals('q', $data['data']['books']['edges'][0]['node']['name']);
$this->assertEquals('r', $data['data']['books']['edges'][1]['node']['name']);
$this->assertEquals('s', $data['data']['books']['edges'][2]['node']['name']);
$this->assertArrayNotHasKey('errors', $data);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Laravel/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
"illuminate/container": "^11.0",
"symfony/web-link": "^6.4 || ^7.1",
"willdurand/negotiation": "^3.1",
"phpstan/phpdoc-parser": "^1.29",
"phpstan/phpdoc-parser": "^1.29 || ^2.0",
"phpdocumentor/reflection-docblock": "^5.1"
},
"require-dev": {
"doctrine/dbal": "^4.0",
"larastan/larastan": "^2.0",
"larastan/larastan": "^2.0 || ^3.0",
"orchestra/testbench": "^9.1",
"phpunit/phpunit": "^11.2",
"api-platform/graphql": "^4.0",
Expand Down
4 changes: 2 additions & 2 deletions src/Laravel/workbench/app/Models/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class Book extends Model
use HasFactory;
use HasUlids;

protected $visible = ['name', 'author', 'isbn', 'publication_date', 'published', 'is_available'];
protected $fillable = ['name', 'is_available'];
protected $visible = ['name', 'author', 'isbn', 'publication_date', 'is_available', 'published'];
protected $fillable = ['name', 'publication_date', 'isbn', 'is_available', 'published'];
protected $casts = [
'is_available' => 'boolean',
];
Expand Down
4 changes: 4 additions & 0 deletions src/Laravel/workbench/app/Models/Vault.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class Vault extends Model
{
use HasFactory;

protected $fillable = [
'secret',
];

public static function provide(): self
{
$v = new self();
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Extractor/YamlResourceExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ private function buildParameters(array $resource): ?array
$parameters[$key] = new $cl(
key: $key,
required: $this->phpize($parameter, 'required', 'bool'),
schema: $parameter['schema'],
schema: $parameter['schema'] ?? null,
openApi: ($parameter['openapi'] ?? null) ? new Parameter(
name: $parameter['openapi']['name'],
in: $parameter['in'] ?? 'query',
Expand Down
10 changes: 8 additions & 2 deletions src/Metadata/Tests/Extractor/Adapter/XmlResourceAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,14 @@ private function buildParameters(\SimpleXMLElement $resource, ?array $values = n
$childNode = $node->addChild('parameter');
$childNode->addAttribute('in', 'query');
$childNode->addAttribute('key', $key);
$childNode->addAttribute('required', $this->parse($value['required']));
$this->buildValues($childNode->addChild('schema'), $value['schema']);

if (\array_key_exists('required', $value)) {
$childNode->addAttribute('required', $this->parse($value['required']));
}

if (\array_key_exists('schema', $value)) {
$this->buildValues($childNode->addChild('schema'), $value['schema']);
}
}
}

Expand Down
Loading

0 comments on commit a8d0c84

Please sign in to comment.