Skip to content

Commit 9019c7a

Browse files
authored
Merge pull request #3 from tmaass-umg/main
Better duplicate check
2 parents 365cd89 + a51c7c9 commit 9019c7a

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/Core/TypeBuilder.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,15 @@ private function isArrayAssociative($array)
132132

133133
/**
134134
* @param $field
135+
* @param mixed $index
135136
* @return bool
136137
*/
137-
protected function isDuplicate($field)
138+
protected function isDuplicate($field, $index = null)
138139
{
139-
foreach ($this->getSelect() as $item) {
140-
if ($item === $field) {
140+
foreach ($this->getSelect() as $itemIndex => $item) {
141+
$indexCheck = !is_null($index) && is_array($field);
142+
143+
if ((($indexCheck && $index === $itemIndex) || !$indexCheck) && $item === $field) {
141144
return true;
142145
}
143146
}

src/Types/Mutation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function addSelect($field)
3636
{
3737
if (is_array($field)) {
3838
foreach ($field as $index => $item) {
39-
if (!$this->isDuplicate($item)) {
39+
if (!$this->isDuplicate($item, $index)) {
4040
$this->select[$index] = $item;
4141
}
4242
}

src/Types/Query.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function addSelect($field)
3636
{
3737
if (is_array($field)) {
3838
foreach ($field as $index => $item) {
39-
if (!$this->isDuplicate($item)) {
39+
if (!$this->isDuplicate($item, $index)) {
4040
$this->select[$index] = $item;
4141
}
4242
}

0 commit comments

Comments
 (0)