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

Implement the Relay specification for mutations #1597

Merged
merged 2 commits into from Dec 22, 2017

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Dec 22, 2017

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

Implement the Relay Input Object Mutations Specification.

When this PR will be merged, we'll respect 100% of the Relay spec!

if ($input) {
$shortName .= 'Input';
} elseif (null !== $mutationName) {
$shortName .= 'Payload';
}
Copy link
Member

Choose a reason for hiding this comment

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

May this be shorter using sprintf?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure it will be more clear as $shortName is built from conditions

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, sprinf doesn't help.

@@ -326,9 +328,13 @@ private function getResourceObjectTypeFields(string $resource, bool $input = fal
{
$fields = [];
$idField = ['type' => GraphQLType::id()];
$clientMutationId = GraphQLType::nonNull(GraphQLType::string());
Copy link
Member

Choose a reason for hiding this comment

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

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 can also be not null:

That input object type may contain an argument named clientMutationId. If provided, that argument must be a String. That argument may be non‐null.

And it is in their official examples: https://facebook.github.io/relay/docs/en/graphql-server-specification.html#mutations

I propose to be strict by default (= to keep this as is).

@@ -27,21 +27,22 @@ Feature: GraphQL mutation support
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.__type.fields[0].name" should contain "delete"
And the JSON node "data.__type.fields[0].description" should contain "Deletes "
And the JSON node "data.__type.fields[0].type.name" should contain "DeleteMutation"
And the JSON node "data.__type.fields[0].description" should match '/^Deletes a [a-zA-Z]+\.$/'
Copy link
Contributor

Choose a reason for hiding this comment

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

Regex could be optimized as [A-z]

Copy link
Member Author

Choose a reason for hiding this comment

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

done

if (isset($this->graphqlTypes[$resourceClass][$mutationName][$input])) {
return $this->graphqlTypes[$resourceClass][$mutationName][$input];
if ($input) {
$shortName .= 'Input';
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 $mutationName is null but $input is true? You will concatenate a string on a non-existing variable. But could this situation happen?

Copy link
Member Author

Choose a reason for hiding this comment

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

$shortName always exists.

@dunglas dunglas merged commit 414f297 into api-platform:master Dec 22, 2017
@dunglas dunglas deleted the relay-mutations branch December 22, 2017 16:14
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

5 participants