Skip to content

Commit

Permalink
Fixed #5149
Browse files Browse the repository at this point in the history
  • Loading branch information
andris-sevcenko committed Oct 23, 2019
1 parent 16938ab commit 4381b1c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
### Fixed
- Fixed a bug where translation message parameters weren’t getting parsed correctly if the installed ICU library was less than version 4.8. ([#4995](https://github.com/craftcms/cms/issues/4995))
- Fixed a bug where GraphQL caches were not being invalidated on element save. ([#5148](https://github.com/craftcms/cms/issues/5148))
- Fixed a bug where GraphQL type generators provided by interfaces added by plugins would not get invoked when building introspection schema. ([#5149](https://github.com/craftcms/cms/issues/5149))

## 3.3.12 - 2019-10-22

Expand Down
49 changes: 17 additions & 32 deletions src/services/Gql.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function getSchemaDef(GqlSchema $schema = null, $prebuildSchema = false):

if (!$this->_schemaDef || $prebuildSchema) {
// Either cached version was not found or we need a pre-built schema.
$this->_registerGqlTypes();
$registeredTypes = $this->_registerGqlTypes();
$this->_registerGqlQueries();

$schemaConfig = [
Expand All @@ -225,32 +225,20 @@ public function getSchemaDef(GqlSchema $schema = null, $prebuildSchema = false):
// as the query is being resolved thanks to the magic of lazy-loading, so we needn't worry.
if (!$prebuildSchema) {
$this->_schemaDef = new Schema($schemaConfig);

return $this->_schemaDef;
}

// Create a pre-built schema if that's what they want.
$interfaces = [
EntryInterface::class,
MatrixBlockInterface::class,
AssetInterface::class,
UserInterface::class,
GlobalSetInterface::class,
ElementInterface::class,
CategoryInterface::class,
TagInterface::class,
];

foreach ($interfaces as $interfaceClass) {
if (!is_subclass_of($interfaceClass, InterfaceType::class)) {
throw new GqlException('Incorrectly defined interface ' . $interfaceClass);
}

/** @var GeneratorInterface $typeGeneratorClass */
$typeGeneratorClass = $interfaceClass::getTypeGenerator();

foreach ($typeGeneratorClass::generateTypes() as $type) {
$schemaConfig['types'][] = $type;
foreach ($registeredTypes as $registeredType) {
if (method_exists($registeredType, 'getTypeGenerator')) {
/** @var GeneratorInterface $typeGeneratorClass */
$typeGeneratorClass = $registeredType::getTypeGenerator();

// Make sure it's the method we're looking for.
if ($typeGeneratorClass instanceof GeneratorInterface) {
foreach ($typeGeneratorClass::generateTypes() as $type) {
$schemaConfig['types'][] = $type;
}
}
}
}

Expand Down Expand Up @@ -635,10 +623,10 @@ private function _getCacheKey(GqlSchema $schema, string $query, $rootValue, $con

/**
* Get GraphQL type definitions from a list of models that support GraphQL
*
* @return void
*
* @return array the list of registered types.
*/
private function _registerGqlTypes()
private function _registerGqlTypes(): array
{
$typeList = [
// Scalars
Expand All @@ -660,11 +648,8 @@ private function _registerGqlTypes()
]);

$this->trigger(self::EVENT_REGISTER_GQL_TYPES, $event);

foreach ($event->types as $type) {
/** @var InterfaceType $type */
TypeLoader::registerType($type::getName(), $type . '::getType');
}

return $event->types;
}

/**
Expand Down

0 comments on commit 4381b1c

Please sign in to comment.