Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
Fixed GraphQL duplicate schema issue
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Baker <[email protected]>
  • Loading branch information
joshuabaker committed May 19, 2021
1 parent f76f83e commit f491660
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.1 - 2021-05-19
### Fixed
- Fixed GraphQL duplicate schema issue

## 1.0.0 - 2021-05-18
### Added
- Initial release
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "augmentations/craft-json",
"description": "Field type for raw JSON editing.",
"type": "craft-plugin",
"version": "1.0.0",
"version": "1.0.1",
"keywords": [
"craft",
"cms",
Expand Down
19 changes: 18 additions & 1 deletion src/fields/JsonField.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Craft;
use craft\base\ElementInterface;
use craft\base\Field;
use craft\gql\GqlEntityRegistry;
use craft\gql\TypeLoader;
use craft\helpers\Html;
use craft\helpers\Json;
use craft\helpers\StringHelper;
Expand Down Expand Up @@ -62,7 +64,22 @@ public function getElementValidationRules(): array
*/
public function getContentGqlType(): Type
{
return new MixedScalar();
$typeName = "Mixed";

if ($type = GqlEntityRegistry::getEntity($typeName)) {
return $type;
}

$type = GqlEntityRegistry::createEntity(
$typeName,
new MixedScalar(["name" => $typeName])
);

TypeLoader::registerType($typeName, function () use ($type) {
return $type;
});

return $type;
}

/**
Expand Down

0 comments on commit f491660

Please sign in to comment.