diff --git a/CHANGELOG-v3.md b/CHANGELOG-v3.md index 0f6a50863c1..ee81ffd26fb 100644 --- a/CHANGELOG-v3.md +++ b/CHANGELOG-v3.md @@ -12,6 +12,7 @@ - Fixed a bug where the "Update all" button was missing on the updates page. ([#4938](https://github.com/craftcms/cms/issues/4938)) - Fixed a bug where the “Updating search indexes” job could fail when updating search indexes for a Matrix block that contained a relational field. - Fixed a bug where it was impossible to query for entries using author id with the GraphQL API. +- Fixed a bug where querying for Marix Blocks using the GraphQL API would not work. ## 3.3.3 - 2019-09-12 diff --git a/src/services/Gql.php b/src/services/Gql.php index f7001804ab6..dacb1382360 100644 --- a/src/services/Gql.php +++ b/src/services/Gql.php @@ -170,6 +170,17 @@ public function getSchemaDef(GqlSchema $schema = null, $prebuildSchema = false): 'directives' => $this->_loadGqlDirectives(), ]; + // For some reason, matrix types need to be explicitly defined, too, + // otherwise it will complain on querying matrix blocks + $typeGeneratorClass = MatrixBlockInterface::getTypeGenerator(); + + foreach ($typeGeneratorClass::generateTypes() as $type) { + $schemaConfig['types'][] = $type; + } + + // TODO fire an event to allow modifying the $schemConfig. + // At least one use-case being adding workaround like for Matrix above. + // If we're not required to pre-build the schema the relevant GraphQL types will be added to the Schema // as the query is being resolved thanks to the magic of lazy-loading, so we needn't worry. if (!$prebuildSchema) {