Skip to content

Commit

Permalink
chore: release version 1.21.0
Browse files Browse the repository at this point in the history
  • Loading branch information
K.I.T.T committed Jun 2, 2022
1 parent 74def39 commit 1e224bc
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 21 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [1.21.0](https://github.com/AmazeeLabs/silverback-mono/compare/@-amazeelabs/silverback_gatsby@1.20.0...@-amazeelabs/silverback_gatsby@1.21.0) (2022-06-02)


### Features

* **gatsby:** introduce `__original_typename` field on each graphql type ([edbf247](https://github.com/AmazeeLabs/silverback-mono/commit/edbf2477c3c4de547e9600c6670d2175ced113c7))





# [1.20.0](https://github.com/AmazeeLabs/silverback-mono/compare/@-amazeelabs/silverback_gatsby@1.19.5...@-amazeelabs/silverback_gatsby@1.20.0) (2022-05-27)


Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "amazeelabs/silverback_gatsby",
"type": "drupal-module",
"version": "1.20.0",
"version": "1.21.0",
"description": "Bridge module between Gatsby and Drupal.",
"homepage": "https://silverback.netlify.app",
"license": "GPL-2.0+",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@-amazeelabs/silverback_gatsby",
"version": "1.20.0",
"version": "1.21.0",
"main": "index.js",
"scripts": {
"version": "sync-composer-version",
Expand All @@ -16,5 +16,5 @@
"repository": "git@github.com:AmazeeLabs/silverback_gatsby.git",
"branch": "main"
},
"gitHead": "78cebd6b4f85a05d86c2c924e6363bee4e603d06"
"gitHead": "8d54bdfbe0d6b243e676ffa1b5b2948e508f4f1f"
}
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ public function getExtensionDefinition() {
// Collect all active feeds and prepend their definitions to the schema.
$schema = array_map(fn (FeedInterface $feed) => $this->getSchemaDefinitions($feed), $this->getFeeds());
array_unshift($schema, parent::getExtensionDefinition());
array_unshift($schema, $this->getOriginalTypenameDefinitions());
return implode("\n", $schema);
}

Expand All @@ -312,6 +313,39 @@ public function registerResolvers(ResolverRegistryInterface $registry) {
$builder = new ResolverBuilder();
$this->addFieldResolvers($registry, $builder);
$this->addTypeResolvers($registry, $builder);
$this->addOriginalTypenameResolvers($registry, $builder);
}

/**
* Attach a _original_typename field to every type.
*
* To preserve the original type in cases where the types are namespaced and
* merged into a different graphql schema (e.g. Gatsby).
*
* @return string
*/
protected function getOriginalTypenameDefinitions() {
$types = [];
foreach ($this->parentAst->definitions->getIterator() as $definition) {
if ($definition instanceof ObjectTypeDefinitionNode) {
$name = $definition->name->value;
$types[] = "extend type {$name} { _original_typename: String! }";
}
}
return implode("\n", $types);
}

/**
* Attach a _original_typename resolvers.
*
* @return void
*/
protected function addOriginalTypenameResolvers(ResolverRegistry $registry, ResolverBuilder $builder) {
foreach ($this->parentAst->definitions->getIterator() as $definition) {
if ($definition instanceof ObjectTypeDefinitionNode) {
$registry->addFieldResolver($definition->name->value, '_original_typename', $builder->fromValue($definition->name->value));
}
}
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/queries/editor.gql
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ fragment BlockPage on Page {
content {
__typename
... on Text {
_original_typename
content
}
... on Figure {
_original_typename
caption
image {
alt
}
}
... on Columns {
_original_typename
columns {
__typename
}
Expand All @@ -21,10 +24,12 @@ fragment BlockPage on Page {

query {
en:loadPage(id: "1:en") {
_original_typename
...BlockPage
}

de:loadPage(id: "1:de") {
_original_typename
...BlockPage
}
}
56 changes: 38 additions & 18 deletions tests/src/Kernel/EditorBlocksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,44 +123,64 @@ function testEditorBlockResolution() {
'en' => [
'title' => 'Editor test',
'content' => [
['__typename' => 'Text', 'content' => '<p>A test paragraph</p><p>Another test paragraph</p>'],
[
'__typename' => 'Text',
'content' => '<p>A test paragraph</p><p>Another test paragraph</p>',
'_original_typename' => 'Text',
],
[
'__typename' => 'Figure',
'caption' => 'This is the caption',
'image' => [
'alt' => 'Screaming hairy armadillo'
]
],
['__typename' => 'Columns', 'columns' => [
[
'__typename' => 'Text',
],
[
'__typename' => 'Text',
'_original_typename' => 'Figure',
],
[
'__typename' => 'Columns',
'columns' => [
[
'__typename' => 'Text',
],
[
'__typename' => 'Text',
],
],
]],
'_original_typename' => 'Columns',
],
],
'_original_typename' => 'Page',
],
'de' => [
'title' => 'Editor test DE',
'content' => [
['__typename' => 'Text', 'content' => '<p>A test paragraph</p><p>Another test paragraph</p>'],
[
'__typename' => 'Text',
'content' => '<p>A test paragraph</p><p>Another test paragraph</p>',
'_original_typename' => 'Text',
],
[
'__typename' => 'Figure',
'caption' => 'This is the caption',
'image' => [
'alt' => 'Screaming hairy armadillo DE'
]
],
['__typename' => 'Columns', 'columns' => [
[
'__typename' => 'Text',
],
[
'__typename' => 'Text',
'_original_typename' => 'Figure',
],
[
'__typename' => 'Columns',
'columns' => [
[
'__typename' => 'Text',
],
[
'__typename' => 'Text',
],
],
]],
'_original_typename' => 'Columns'
],
],
'_original_typename' => 'Page',
],
], $metadata);
}
Expand Down

0 comments on commit 1e224bc

Please sign in to comment.