Skip to content

[WIP] GraphQL Mutation support #1460

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 11 commits into from
Nov 29, 2017

Conversation

alanpoulain
Copy link
Member

@alanpoulain alanpoulain commented Oct 25, 2017

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

TODO:

  • delete mutation (item)
  • put mutation (item)
  • post mutation (collection)
  • custom mutation (item / collection)

@alanpoulain alanpoulain force-pushed the feature/graphql-mutations branch from ca6200a to 5167847 Compare October 25, 2017 06:16
$request = Request::create($uri, $operation['method']);
$request->headers->set('Accept', 'application/json');

$response = $this->httpKernel->handle($request, HttpKernelInterface::SUB_REQUEST);
Copy link
Member

@dunglas dunglas Oct 25, 2017

Choose a reason for hiding this comment

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

This is weird but I get it, we don't actually have anything to handle object deletion, we just call remove() from Doctrine in the Doctrine's WriteListener: https://github.com/api-platform/core/blob/master/src/Bridge/Doctrine/EventListener/WriteListener.php#L62

It was OK for REST until now but it doesn't scale to GraphQL. Injecting HttpKernel here is bad design.

I suggest to do the following:

  • Introduce a new ObjectManagerInterface in API Platform with delete() and persist() methods
  • Implement this interface in the Doctrine bridge to delegate to Doctrine's Object Manager (it will just be a proxy class)
  • Use this new interface here and in WriteListener

WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok so you want to modify API Platform to avoid this issue then. Your suggestion seems good to me.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it's a tiny, non-breaking change IMO.

Copy link
Member

Choose a reason for hiding this comment

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

The existing Bridge\Doctrine\EventListener\WriteListener should be deprecated (and not registered anymore) and a new one (EventListener\WriteListener) using the new interface should be added.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please do this in another PR?

Copy link
Member

Choose a reason for hiding this comment

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

Why not but this other PR must be merged before this one :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Obsly :)

@@ -335,6 +373,10 @@ private function getOperations(ResourceMetadata $resourceMetadata, bool $isQuery
continue;
}

if (Request::METHOD_PATCH === $operation['method']) {
Copy link
Member

Choose a reason for hiding this comment

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

You should probably whitelist methods here instead of blacklisting them, some other can be problematic (HEAD, OPTIONS...)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure.

@Simperfit Simperfit self-requested a review October 29, 2017 08:25
@meyerbaptiste meyerbaptiste force-pushed the feature/graphql-mutations branch from 5167847 to bbf5047 Compare October 30, 2017 13:30
@dunglas
Copy link
Member

dunglas commented Nov 15, 2017

Can we merge this one?

@alanpoulain
Copy link
Member Author

I think @meyerbaptiste was working on a better way to do this, doesn't he?

@dunglas
Copy link
Member

dunglas commented Nov 15, 2017

It's merged #1464, but it's lower level system. This PR can now be updated to use this new service.

@alanpoulain
Copy link
Member Author

OK maybe I'll do that this weekend.

@alanpoulain alanpoulain force-pushed the feature/graphql-mutations branch 4 times, most recently from a7909e1 to 645a270 Compare November 19, 2017 19:32
@dunglas dunglas force-pushed the feature/graphql-mutations branch from 645a270 to a840669 Compare November 27, 2017 15:51
@dunglas dunglas force-pushed the feature/graphql-mutations branch from a52c25e to 8205168 Compare November 28, 2017 10:37
@dunglas dunglas merged commit 996a6bd into api-platform:master Nov 29, 2017
@dunglas
Copy link
Member

dunglas commented Nov 29, 2017

Thanks @alanpoulain! This is still a WIP, but it's a big first step!

@alanpoulain alanpoulain deleted the feature/graphql-mutations branch December 29, 2017 14:17
hoangnd25 pushed a commit to hoangnd25/core that referenced this pull request Feb 23, 2018
* Delete mutation for an item

* Put mutation for an item

* Use object_to_populate

* Basic create support

* Fix and test create support

* wip

* Don't test composite identifiers support for now

* Fix CS

* Fix some tests

* Fix CS

* Fix tests
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.

3 participants