|
@@ 164-207 (lines=44) @@
|
| 161 |
|
* @param Endpoint $endpoint |
| 162 |
|
* @param string $bundleNamespace |
| 163 |
|
*/ |
| 164 |
|
protected function createAddOperation(ObjectDefinitionInterface $definition, Annotation\Mutation $mutation, Endpoint $endpoint, $bundleNamespace) |
| 165 |
|
{ |
| 166 |
|
$mutation->name = $mutation->name ?? 'add'.ucfirst($definition->getName()); |
| 167 |
|
$mutation->payload = $mutation->payload ?? null; |
| 168 |
|
if (!$mutation->payload) { |
| 169 |
|
//deep cloning |
| 170 |
|
/** @var ObjectDefinitionInterface $payload */ |
| 171 |
|
$payload = unserialize(serialize($endpoint->getType(AddNodePayload::class)), [DefinitionInterface::class]); |
| 172 |
|
$payload->setName(ucfirst($mutation->name.'Payload')); |
| 173 |
|
|
| 174 |
|
if (!$endpoint->hasType($payload->getName())) { |
| 175 |
|
$payload->getField('node')->setType($definition->getName()); |
| 176 |
|
$endpoint->add($payload); |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
$mutation->payload = $payload->getName(); |
| 180 |
|
} |
| 181 |
|
$mutation->node = $mutation->node ?? $definition->getName(); |
| 182 |
|
|
| 183 |
|
if ($endpoint->hasTypeForClass($mutation->node)) { |
| 184 |
|
$mutation->node = $endpoint->getTypeForClass($mutation->node); |
| 185 |
|
} |
| 186 |
|
|
| 187 |
|
$formType = true; |
| 188 |
|
$options = []; |
| 189 |
|
$generalForm = ClassUtils::applyNamingConvention($bundleNamespace, 'Form\Input', $mutation->node, $mutation->node, 'Input'); |
| 190 |
|
$specificForm = ClassUtils::applyNamingConvention($bundleNamespace, 'Form\Input', $mutation->node, $mutation->name, 'Input'); |
| 191 |
|
if (class_exists($specificForm)) { |
| 192 |
|
$formType = $specificForm; |
| 193 |
|
} elseif (class_exists($generalForm)) { |
| 194 |
|
$formType = $generalForm; |
| 195 |
|
$options['operation'] = $mutation->name; |
| 196 |
|
} |
| 197 |
|
|
| 198 |
|
$mutation->options = array_merge(['form' => ['type' => $formType, 'options' => $options]], $mutation->options); |
| 199 |
|
$resolverReflection = new \ReflectionClass(AddNode::class); |
| 200 |
|
|
| 201 |
|
$resolver = ClassUtils::applyNamingConvention($bundleNamespace, 'Mutation', $definition->getName(), $mutation->name); |
| 202 |
|
if (class_exists($resolver)) { |
| 203 |
|
$mutation->resolver = $resolver; |
| 204 |
|
} |
| 205 |
|
|
| 206 |
|
$this->mutationParser->parse($mutation, $resolverReflection, $endpoint); |
| 207 |
|
} |
| 208 |
|
|
| 209 |
|
/** |
| 210 |
|
* @param ObjectDefinitionInterface $definition |
|
@@ 215-258 (lines=44) @@
|
| 212 |
|
* @param Endpoint $endpoint |
| 213 |
|
* @param string $bundleNamespace |
| 214 |
|
*/ |
| 215 |
|
protected function createUpdateOperation(ObjectDefinitionInterface $definition, Annotation\Mutation $mutation, Endpoint $endpoint, $bundleNamespace) |
| 216 |
|
{ |
| 217 |
|
$mutation->name = $mutation->name ?? 'update'.ucfirst($definition->getName()); |
| 218 |
|
$mutation->payload = $mutation->payload ?? null; |
| 219 |
|
if (!$mutation->payload) { |
| 220 |
|
//deep cloning |
| 221 |
|
/** @var ObjectDefinitionInterface $payload */ |
| 222 |
|
$payload = unserialize(serialize($endpoint->getType(UpdateNodePayload::class)), [DefinitionInterface::class]); |
| 223 |
|
$payload->setName(ucfirst($mutation->name.'Payload')); |
| 224 |
|
|
| 225 |
|
if (!$endpoint->hasType($payload->getName())) { |
| 226 |
|
$payload->getField('node')->setType($definition->getName()); |
| 227 |
|
$endpoint->add($payload); |
| 228 |
|
} |
| 229 |
|
|
| 230 |
|
$mutation->payload = $payload->getName(); |
| 231 |
|
} |
| 232 |
|
$mutation->node = $mutation->node ?? $definition->getName(); |
| 233 |
|
|
| 234 |
|
if ($endpoint->hasTypeForClass($mutation->node)) { |
| 235 |
|
$mutation->node = $endpoint->getTypeForClass($mutation->node); |
| 236 |
|
} |
| 237 |
|
|
| 238 |
|
$formType = true; |
| 239 |
|
$options = []; |
| 240 |
|
$generalForm = ClassUtils::applyNamingConvention($bundleNamespace, 'Form\Input', $mutation->node, $mutation->node, 'Input'); |
| 241 |
|
$specificForm = ClassUtils::applyNamingConvention($bundleNamespace, 'Form\Input', $mutation->node, $mutation->name, 'Input'); |
| 242 |
|
if (class_exists($specificForm)) { |
| 243 |
|
$formType = $specificForm; |
| 244 |
|
} elseif (class_exists($generalForm)) { |
| 245 |
|
$formType = $generalForm; |
| 246 |
|
$options['operation'] = $mutation->name; |
| 247 |
|
} |
| 248 |
|
|
| 249 |
|
$mutation->options = array_merge(['form' => ['type' => $formType, 'options' => $options]], $mutation->options); |
| 250 |
|
$resolverReflection = new \ReflectionClass(UpdateNode::class); |
| 251 |
|
|
| 252 |
|
$resolver = ClassUtils::applyNamingConvention($bundleNamespace, 'Mutation', $definition->getName(), $mutation->name); |
| 253 |
|
if (class_exists($resolver)) { |
| 254 |
|
$mutation->resolver = $resolver; |
| 255 |
|
} |
| 256 |
|
|
| 257 |
|
$this->mutationParser->parse($mutation, $resolverReflection, $endpoint); |
| 258 |
|
} |
| 259 |
|
|
| 260 |
|
/** |
| 261 |
|
* @param ObjectDefinitionInterface $definition |