Skip to content
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

GraphQL + data provider refactoring: automatically add SQL join clauses #1619

Merged
merged 5 commits into from Dec 29, 2017

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Dec 28, 2017

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

This PR is mainly a refactoring of the Data Providers to get rid of the dependency to HttpFoundation (it will also allow to simplify the JSONAPI support, and maybe to support PSR-7 later).
Thanks to this new decoupling, it's now possible to automatically add appropriate JOIN SQL clauses according to the selected fields in a GraphQL query.

TODO:

  • Fix tests and bugs

@dunglas dunglas requested a review from soyuka December 28, 2017 17:27
*/
public function __construct(ManagerRegistry $managerRegistry, array $collectionExtensions = [])
{
$this->managerRegistry = $managerRegistry;
$this->collectionExtensions = $collectionExtensions;
}

public function supports(string $resourceClass, string $operationName = null): bool
public function supports(string $resourceClass, string $operationName = null, array $conext = []): bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't you mean $context?

{
$options = null === $operationName ? [] : ['collection_operation_name' => $operationName];
if (null === $resourceClass) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if $resourceClass is an empty string? I would prefer if (empty($resourceClass))
Same in all PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be a BC break ('' is currently allowed).

@@ -53,6 +54,10 @@
*/
public function __construct(PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, int $maxJoins = 30, bool $forceEager = true, RequestStack $requestStack = null, SerializerContextBuilderInterface $serializerContextBuilder = null, bool $fetchPartial = false, ClassMetadataFactoryInterface $classMetadataFactory = null)
{
if (null !== $this->serializerContextBuilder) {
@trigger_error('Passing an instance of "%s" is deprecated since version 2.2 and will be removed in 3.0. Use the "normalization_context" of the data provider\'s context instead.', E_USER_DEPRECATED);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing sprintf & argument

Copy link
Member

@soyuka soyuka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactor 👍

@@ -53,6 +54,10 @@
*/
public function __construct(PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, int $maxJoins = 30, bool $forceEager = true, RequestStack $requestStack = null, SerializerContextBuilderInterface $serializerContextBuilder = null, bool $fetchPartial = false, ClassMetadataFactoryInterface $classMetadataFactory = null)
{
//if (null !== $this->serializerContextBuilder) {
// @trigger_error('Passing an instance of "%s" is deprecated since version 2.2 and will be removed in 3.0. Use the "normalization_context" of the data provider\'s context instead.', E_USER_DEPRECATED);
//}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want to keep this dead code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I'll drop it, I try to debug something.

{
if (null === $resourceClass) {
throw new InvalidArgumentException('The "$resourceClass" parameter must not be null');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird no? How is this possible and why do we change the interface to allow null? Especially if supports method does require this argument can't it be mandatory?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only possible to defined optional parameters when overriding the signature of method defined in a parent interface. It's why.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Once the parent interface argument becomes mandatory we will remove this test right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, but I'm not sure it is worth it to make the argument mandatory in a future version (pain to upgrade for almost no gain).

@dunglas dunglas merged commit d2a6729 into api-platform:master Dec 29, 2017
@dunglas dunglas deleted the graphql-join branch December 29, 2017 18:10
hoangnd25 pushed a commit to hoangnd25/core that referenced this pull request Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants