Skip to content

Merge 25 #3603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 16, 2020
Merged
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
52 changes: 47 additions & 5 deletions features/graphql/input_output.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ Feature: GraphQL DTO input and output

@createSchema
Scenario: Retrieve an Output with GraphQL
Given there is a RelatedDummy with 0 friends
When I add "Content-Type" header equal to "application/ld+json"
And I send a "POST" request to "/dummy_dto_input_outputs" with body:
"""
{
"foo": "test",
"bar": 1
"bar": 1,
"relatedDummies": ["/related_dummies/1"]
}
"""
Then the response status code should be 201
Expand All @@ -22,20 +24,51 @@ Feature: GraphQL DTO input and output
"hydra": "http://www.w3.org/ns/hydra/core#",
"id": "OutputDto/id",
"baz": "OutputDto/baz",
"bat": "OutputDto/bat"
"bat": "OutputDto/bat",
"relatedDummies": "OutputDto/relatedDummies"
},
"@type": "DummyDtoInputOutput",
"@id": "/dummy_dto_input_outputs/1",
"id": 1,
"baz": 1,
"bat": "test"
"bat": "test",
"relatedDummies": [
{
"@context": "/contexts/RelatedDummy",
"@id": "/related_dummies/1",
"@type": "https://schema.org/Product",
"name": "RelatedDummy with friends",
"dummyDate": null,
"thirdLevel": null,
"relatedToDummyFriend": [],
"dummyBoolean": null,
"embeddedDummy": {
"dummyName": null,
"dummyBoolean": null,
"dummyDate": null,
"dummyFloat": null,
"dummyPrice": null,
"symfony": null
},
"id": 1,
"symfony": "symfony",
"age": null
}
]
}
"""
When I send the following GraphQL request:
"""
{
dummyDtoInputOutput(id: "/dummy_dto_input_outputs/1") {
_id, id, baz
_id, id, baz,
relatedDummies {
edges {
node {
name
}
}
}
}
}
"""
Expand All @@ -49,7 +82,16 @@ Feature: GraphQL DTO input and output
"dummyDtoInputOutput": {
"_id": 1,
"id": "/dummy_dto_input_outputs/1",
"baz": 1
"baz": 1,
"relatedDummies": {
"edges": [
{
"node": {
"name": "RelatedDummy with friends"
}
}
]
}
}
}
}
Expand Down
24 changes: 16 additions & 8 deletions features/jsonld/input_output.feature
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,15 @@ Feature: JSON-LD DTO input and output
"hydra": "http://www.w3.org/ns/hydra/core#",
"id": "OutputDto/id",
"baz": "OutputDto/baz",
"bat": "OutputDto/bat"
"bat": "OutputDto/bat",
"relatedDummies": "OutputDto/relatedDummies"
},
"@type": "DummyDtoInputOutput",
"@id": "/dummy_dto_input_outputs/1",
"id": 1,
"baz": 1,
"bat": "test"
"bat": "test",
"relatedDummies": []
}
"""
When I add "Accept" header equal to "application/ld+json"
Expand All @@ -178,13 +180,15 @@ Feature: JSON-LD DTO input and output
"hydra": "http://www.w3.org/ns/hydra/core#",
"id": "OutputDto/id",
"baz": "OutputDto/baz",
"bat": "OutputDto/bat"
"bat": "OutputDto/bat",
"relatedDummies": "OutputDto/relatedDummies"
},
"@type": "DummyDtoInputOutput",
"@id": "/dummy_dto_input_outputs/1",
"id": 1,
"baz": 2,
"bat": "test"
"bat": "test",
"relatedDummies": []
}
"""

Expand Down Expand Up @@ -237,13 +241,15 @@ Feature: JSON-LD DTO input and output
"hydra": "http://www.w3.org/ns/hydra/core#",
"id": "OutputDto/id",
"baz": "OutputDto/baz",
"bat": "OutputDto/bat"
"bat": "OutputDto/bat",
"relatedDummies": "OutputDto/relatedDummies"
},
"@type": "DummyDtoNoInput",
"@id": "/dummy_dto_no_inputs/1",
"id": 1,
"baz": 1,
"bat": "test"
"bat": "test",
"relatedDummies": []
}
"""

Expand All @@ -260,13 +266,15 @@ Feature: JSON-LD DTO input and output
"hydra": "http://www.w3.org/ns/hydra/core#",
"id": "OutputDto/id",
"baz": "OutputDto/baz",
"bat": "OutputDto/bat"
"bat": "OutputDto/bat",
"relatedDummies": "OutputDto/relatedDummies"
},
"@type": "DummyDtoNoInput",
"@id": "/dummy_dto_no_inputs/1",
"id": 1,
"baz": 1,
"bat": "testtest"
"bat": "testtest",
"relatedDummies": []
}
"""

Expand Down
9 changes: 8 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ parameters:
symfony:
container_xml_path: tests/Fixtures/app/var/cache/test/appAppKernelTestDebugContainer.xml
constant_hassers: false
autoload_files:
bootstrapFiles:
- tests/Fixtures/app/AppKernel.php
excludes_analyse:
- tests/Fixtures/app/var/cache
Expand Down Expand Up @@ -132,3 +132,10 @@ parameters:
-
message: "#Call to function method_exists\\(\\) with ApiPlatform\\\\Core\\\\JsonApi\\\\Serializer\\\\ItemNormalizer and 'setCircularReferenc…' will always evaluate to false\\.#"
path: tests/JsonApi/Serializer/ItemNormalizerTest.php

# Waiting to be fixed by https://github.com/Roave/BetterReflection/issues/663
-
message: '#Call to private method getNestedFieldPath\(\) of class ApiPlatform\\Core\\Bridge\\Elasticsearch\\DataProvider\\Filter\\AbstractFilter\.#'
paths:
- src/Bridge/Elasticsearch/DataProvider/Filter/OrderFilter.php
- src/Bridge/Elasticsearch/DataProvider/Filter/AbstractSearchFilter.php
8 changes: 7 additions & 1 deletion src/Bridge/Doctrine/Orm/Filter/ExistsFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\InputBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
Expand Down Expand Up @@ -204,8 +205,13 @@ protected function extractProperties(Request $request/*, string $resourceClass*/

@trigger_error(sprintf('The use of "%s::extractProperties()" is deprecated since 2.2. Use the "filters" key of the context instead.', __CLASS__), E_USER_DEPRECATED);

$properties = $request->query->get($this->existsParameterName);
// symfony > 5.1
if (class_exists(InputBag::class)) {
return $request->query->all($this->existsParameterName);
}

$properties = $request->query->get($this->existsParameterName);
/* @phpstan-ignore-next-line */
return \is_array($properties) ? $properties : [];
}
}
9 changes: 8 additions & 1 deletion src/Bridge/Doctrine/Orm/Filter/OrderFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\InputBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
Expand Down Expand Up @@ -120,8 +121,14 @@ protected function filterProperty(string $property, $direction, QueryBuilder $qu
protected function extractProperties(Request $request/*, string $resourceClass*/): array
{
@trigger_error(sprintf('The use of "%s::extractProperties()" is deprecated since 2.2. Use the "filters" key of the context instead.', __CLASS__), E_USER_DEPRECATED);
$properties = $request->query->get($this->orderParameterName);

// symfony > 5.1
if (class_exists(InputBag::class)) {
return $request->query->all($this->orderParameterName);
}

$properties = $request->query->get($this->orderParameterName);
/* @phpstan-ignore-next-line */
return \is_array($properties) ? $properties : [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use Symfony\Component\Config\Resource\DirectoryResource;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
Expand Down Expand Up @@ -147,6 +148,19 @@ private function registerCommonConfiguration(ContainerBuilder $container, array
$loader->load('data_provider.xml');
$loader->load('filter.xml');

$container->getDefinition('api_platform.operation_method_resolver')
->setDeprecated(...$this->buildDeprecationArgs('2.5', 'The "%service_id%" service is deprecated since API Platform 2.5.'));
$container->getDefinition('api_platform.formats_provider')
->setDeprecated(...$this->buildDeprecationArgs('2.5', 'The "%service_id%" service is deprecated since API Platform 2.5.'));
$container->getAlias('ApiPlatform\Core\Api\OperationAwareFormatsProviderInterface')
->setDeprecated(...$this->buildDeprecationArgs('2.5', 'The "%alias_id%" alias is deprecated since API Platform 2.5.'));
$container->getDefinition('api_platform.operation_path_resolver.underscore')
->setDeprecated(...$this->buildDeprecationArgs('2.1', 'The "%service_id%" service is deprecated since API Platform 2.1 and will be removed in 3.0. Use "api_platform.path_segment_name_generator.underscore" instead.'));
$container->getDefinition('api_platform.operation_path_resolver.dash')
->setDeprecated(...$this->buildDeprecationArgs('2.1', 'The "%service_id%" service is deprecated since API Platform 2.1 and will be removed in 3.0. Use "api_platform.path_segment_name_generator.dash" instead.'));
$container->getDefinition('api_platform.filters')
->setDeprecated(...$this->buildDeprecationArgs('2.1', 'The "%service_id%" service is deprecated since 2.1 and will be removed in 3.0. Use the "api_platform.filter_locator" service instead.'));

if (class_exists(Uuid::class)) {
$loader->load('ramsey_uuid.xml');
}
Expand Down Expand Up @@ -460,6 +474,11 @@ private function registerLegacyBundlesConfiguration(ContainerBuilder $container,

if (isset($bundles['NelmioApiDocBundle']) && $config['enable_nelmio_api_doc']) {
$loader->load('nelmio_api_doc.xml');

$container->getDefinition('api_platform.nelmio_api_doc.annotations_provider')
->setDeprecated(...$this->buildDeprecationArgs('2.2', 'The "%service_id%" service is deprecated since API Platform 2.2 and will be removed in 3.0. NelmioApiDocBundle 3 has native support for API Platform.'));
$container->getDefinition('api_platform.nelmio_api_doc.parser')
->setDeprecated(...$this->buildDeprecationArgs('2.2', 'The "%service_id%" service is deprecated since API Platform 2.2 and will be removed in 3.0. NelmioApiDocBundle 3 has native support for API Platform.'));
}
}

Expand Down Expand Up @@ -668,4 +687,11 @@ private function registerSecurityConfiguration(ContainerBuilder $container, XmlF
$loader->load('security.xml');
}
}

private function buildDeprecationArgs(string $version, string $message): array
{
return method_exists(Definition::class, 'getDeprecation')
? ['api-platform/core', $version, $message]
: [true, $message];
}
}
12 changes: 10 additions & 2 deletions src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Symfony\Bundle\FullStack;
use Symfony\Bundle\MercureBundle\MercureBundle;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Config\Definition\BaseNode;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
Expand Down Expand Up @@ -87,7 +88,7 @@ public function getConfigTreeBuilder()
->booleanNode('show_webby')->defaultTrue()->info('If true, show Webby on the documentation page')->end()
->scalarNode('default_operation_path_resolver')
->defaultValue('api_platform.operation_path_resolver.underscore')
->setDeprecated('The use of the `default_operation_path_resolver` has been deprecated in 2.1 and will be removed in 3.0. Use `path_segment_name_generator` instead.')
->setDeprecated(...$this->buildDeprecationArgs('2.1', 'The use of the `default_operation_path_resolver` has been deprecated in 2.1 and will be removed in 3.0. Use `path_segment_name_generator` instead.'))
->info('Specify the default operation path resolver to use for generating resources operations path.')
->end()
->scalarNode('name_converter')->defaultNull()->info('Specify a name converter to use.')->end()
Expand All @@ -111,7 +112,7 @@ public function getConfigTreeBuilder()
->booleanNode('enable_fos_user')->defaultValue(class_exists(FOSUserBundle::class))->info('Enable the FOSUserBundle integration.')->end()
->booleanNode('enable_nelmio_api_doc')
->defaultFalse()
->setDeprecated('Enabling the NelmioApiDocBundle integration has been deprecated in 2.2 and will be removed in 3.0. NelmioApiDocBundle 3 has native support for API Platform.')
->setDeprecated(...$this->buildDeprecationArgs('2.2', 'Enabling the NelmioApiDocBundle integration has been deprecated in 2.2 and will be removed in 3.0. NelmioApiDocBundle 3 has native support for API Platform.'))
->info('Enable the NelmioApiDocBundle integration.')
->end()
->booleanNode('enable_swagger')->defaultTrue()->info('Enable the Swagger documentation and export.')->end()
Expand Down Expand Up @@ -567,4 +568,11 @@ private function addDefaultsSection(ArrayNodeDefinition $rootNode): void
$defaultsNode->children()->variableNode($snakeCased);
}
}

private function buildDeprecationArgs(string $version, string $message): array
{
return method_exists(BaseNode::class, 'getDeprecation')
? ['api-platform/core', $version, $message]
: [$message];
}
}
11 changes: 2 additions & 9 deletions src/Bridge/Symfony/Bundle/Resources/config/api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<service id="api_platform.operation_method_resolver" class="ApiPlatform\Core\Bridge\Symfony\Routing\OperationMethodResolver" public="false">
<argument type="service" id="api_platform.router" />
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
<deprecated>The "%service_id%" service is deprecated since API Platform 2.5.</deprecated>
</service>

<service id="api_platform.route_name_resolver" class="ApiPlatform\Core\Bridge\Symfony\Routing\RouteNameResolver" public="false">
Expand Down Expand Up @@ -71,11 +70,9 @@
<service id="api_platform.formats_provider" class="ApiPlatform\Core\Api\FormatsProvider">
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
<argument>%api_platform.formats%</argument>
<deprecated>The "%service_id%" service is deprecated since API Platform 2.5.</deprecated>
</service>

<service id="ApiPlatform\Core\Api\OperationAwareFormatsProviderInterface" alias="api_platform.formats_provider">
<deprecated>The "%alias_id%" alias is deprecated since API Platform 2.5.</deprecated>
</service>

<!-- Serializer -->
Expand Down Expand Up @@ -139,13 +136,9 @@
<argument type="service" id="api_platform.path_segment_name_generator" />
</service>

<service id="api_platform.operation_path_resolver.underscore" class="ApiPlatform\Core\PathResolver\UnderscoreOperationPathResolver" public="false">
<deprecated>The "%service_id%" service is deprecated since API Platform 2.1 and will be removed in 3.0. Use "api_platform.path_segment_name_generator.underscore" instead.</deprecated>
</service>
<service id="api_platform.operation_path_resolver.underscore" class="ApiPlatform\Core\PathResolver\UnderscoreOperationPathResolver" public="false" />

<service id="api_platform.operation_path_resolver.dash" class="ApiPlatform\Core\PathResolver\DashOperationPathResolver" public="false">
<deprecated>The "%service_id%" service is deprecated since API Platform 2.1 and will be removed in 3.0. Use "api_platform.path_segment_name_generator.dash" instead.</deprecated>
</service>
<service id="api_platform.operation_path_resolver.dash" class="ApiPlatform\Core\PathResolver\DashOperationPathResolver" public="false" />

<!-- Path name generator -->

Expand Down
1 change: 0 additions & 1 deletion src/Bridge/Symfony/Bundle/Resources/config/filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<service id="api_platform.filter_collection_factory" class="ApiPlatform\Core\Api\FilterCollectionFactory" />

<service id="api_platform.filters" class="ApiPlatform\Core\Api\FilterCollection">
<deprecated>The "%service_id%" service is deprecated since 2.1 and will be removed in 3.0. Use the "api_platform.filter_locator" service instead.</deprecated>
<factory service="api_platform.filter_collection_factory" method="createFilterCollectionFromLocator" />
<argument type="service" id="api_platform.filter_locator" />
</service>
Expand Down
4 changes: 0 additions & 4 deletions src/Bridge/Symfony/Bundle/Resources/config/nelmio_api_doc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

<services>
<service id="api_platform.nelmio_api_doc.annotations_provider" class="ApiPlatform\Core\Bridge\NelmioApiDoc\Extractor\AnnotationsProvider\ApiPlatformProvider">
<deprecated>The "%service_id%" service is deprecated since API Platform 2.2 and will be removed in 3.0. NelmioApiDocBundle 3 has native support for API Platform.</deprecated>

<argument type="service" id="api_platform.metadata.resource.name_collection_factory" />
<argument type="service" id="api_platform.hydra.normalizer.documentation" />
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
Expand All @@ -18,8 +16,6 @@
</service>

<service id="api_platform.nelmio_api_doc.parser" class="ApiPlatform\Core\Bridge\NelmioApiDoc\Parser\ApiPlatformParser">
<deprecated>The "%service_id%" service is deprecated since API Platform 2.2 and will be removed in 3.0. NelmioApiDocBundle 3 has native support for API Platform.</deprecated>

<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
<argument type="service" id="api_platform.metadata.property.name_collection_factory" />
<argument type="service" id="api_platform.metadata.property.metadata_factory" />
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQl/Action/EntrypointAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private function parseRequest(Request $request): array
{
$query = $request->query->get('query');
$operationName = $request->query->get('operationName');
if ($variables = $request->query->get('variables', [])) {
if ($variables = $request->query->get('variables') ?: []) {
$variables = $this->decodeVariables($variables);
}

Expand Down
Loading