-
-
Notifications
You must be signed in to change notification settings - Fork 921
Implement the Relay specification for mutations #1597
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -294,16 +294,18 @@ private function convertType(Type $type, bool $input = false, string $mutationNa | |
*/ | ||
private function getResourceObjectType(string $resourceClass, ResourceMetadata $resourceMetadata, bool $input = false, string $mutationName = null): GraphQLType | ||
{ | ||
$shortName = $resourceMetadata->getShortName(); | ||
if ($input) { | ||
$shortName .= 'Input'; | ||
if (isset($this->graphqlTypes[$resourceClass][$mutationName][$input])) { | ||
return $this->graphqlTypes[$resourceClass][$mutationName][$input]; | ||
} | ||
|
||
$shortName = $resourceMetadata->getShortName(); | ||
if (null !== $mutationName) { | ||
$shortName .= ucfirst($mutationName).'Mutation'; | ||
$shortName = $mutationName.ucfirst($shortName); | ||
} | ||
|
||
if (isset($this->graphqlTypes[$resourceClass][$mutationName][$input])) { | ||
return $this->graphqlTypes[$resourceClass][$mutationName][$input]; | ||
if ($input) { | ||
$shortName .= 'Input'; | ||
} elseif (null !== $mutationName) { | ||
$shortName .= 'Payload'; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May this be shorter using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure it will be more clear as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, |
||
|
||
$configuration = [ | ||
|
@@ -325,10 +327,14 @@ private function getResourceObjectType(string $resourceClass, ResourceMetadata $ | |
private function getResourceObjectTypeFields(string $resource, bool $input = false, string $mutationName = null): array | ||
{ | ||
$fields = []; | ||
$idField = ['type' => GraphQLType::id()]; | ||
$idField = ['type' => GraphQLType::nonNull(GraphQLType::id())]; | ||
$clientMutationId = GraphQLType::nonNull(GraphQLType::string()); | ||
|
||
if ('delete' === $mutationName) { | ||
return ['id' => $idField]; | ||
return [ | ||
'id' => $idField, | ||
'clientMutationId' => $clientMutationId, | ||
]; | ||
} | ||
|
||
if (!$input || 'create' !== $mutationName) { | ||
|
@@ -350,6 +356,10 @@ private function getResourceObjectTypeFields(string $resource, bool $input = fal | |
} | ||
} | ||
|
||
if (null !== $mutationName) { | ||
$fields['clientMutationId'] = $clientMutationId; | ||
} | ||
|
||
return $fields; | ||
} | ||
|
||
|
There was a problem hiding this comment.
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?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$shortName
always exists.