From 263a3bdecefa01784cb8ec5390d94268de6eb867 Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Thu, 14 Nov 2024 11:47:01 +0100 Subject: [PATCH] Add node query to GraphQl schema --- .../graphql/thunder_pages.extension.graphqls | 1 + .../ThunderPagesSchemaExtension.php | 2 + .../tests/examples/node.query.graphql | 51 ++++++++++++++ .../tests/examples/node.response.json | 69 +++++++++++++++++++ .../tests/examples/node.variables.json | 3 + 5 files changed, 126 insertions(+) create mode 100644 modules/thunder_gqls/tests/examples/node.query.graphql create mode 100644 modules/thunder_gqls/tests/examples/node.response.json create mode 100644 modules/thunder_gqls/tests/examples/node.variables.json diff --git a/modules/thunder_gqls/graphql/thunder_pages.extension.graphqls b/modules/thunder_gqls/graphql/thunder_pages.extension.graphqls index 0f0c42c12..e1ac11f9c 100644 --- a/modules/thunder_gqls/graphql/thunder_pages.extension.graphqls +++ b/modules/thunder_gqls/graphql/thunder_pages.extension.graphqls @@ -5,4 +5,5 @@ extend type Query { channel(uuid: String!): Channel user(uuid: String!): User page(path: String!): Page + node(uuid: String!): Page } diff --git a/modules/thunder_gqls/src/Plugin/GraphQL/SchemaExtension/ThunderPagesSchemaExtension.php b/modules/thunder_gqls/src/Plugin/GraphQL/SchemaExtension/ThunderPagesSchemaExtension.php index cdcd5e66c..0dc426453 100644 --- a/modules/thunder_gqls/src/Plugin/GraphQL/SchemaExtension/ThunderPagesSchemaExtension.php +++ b/modules/thunder_gqls/src/Plugin/GraphQL/SchemaExtension/ThunderPagesSchemaExtension.php @@ -43,6 +43,8 @@ protected function resolveFields(): void { $this->fromRoute($this->builder->fromArgument('path')) ); + $this->resolvePageInterfaceQueryFields('node', 'node'); + // Teaser. $this->addSimpleCallbackFields('Teaser', ['image', 'text']); diff --git a/modules/thunder_gqls/tests/examples/node.query.graphql b/modules/thunder_gqls/tests/examples/node.query.graphql new file mode 100644 index 000000000..82f1a3c0b --- /dev/null +++ b/modules/thunder_gqls/tests/examples/node.query.graphql @@ -0,0 +1,51 @@ +query ($uuid: String!) { + node(uuid: $uuid) { + uuid + url + name + entity + language + entityLinks { + canonical + } + ... on Article { + published + author { + uuid + name + mail + entity + language + } + channel { + uuid + published + name + url + parent { + name + id + url + } + } + tags { + uuid + name + url + } + seoTitle + content { + __typename + } + teaser { + text + image { + uuid + derivative(style: "medium") { + width + } + } + } + } + } +} diff --git a/modules/thunder_gqls/tests/examples/node.response.json b/modules/thunder_gqls/tests/examples/node.response.json new file mode 100644 index 000000000..3572fd50b --- /dev/null +++ b/modules/thunder_gqls/tests/examples/node.response.json @@ -0,0 +1,69 @@ +{ + "data": { + "node": { + "uuid": "36b2e2b2-3df0-43eb-a282-d792b0999c07", + "url": "/come-drupalcon-new-orleans", + "name": "Come to DrupalCon New Orleans", + "entity": "node", + "language": "en", + "entityLinks": { + "canonical": "/come-drupalcon-new-orleans" + }, + "published": true, + "author": { + "uuid": "be8e7a25-8a41-4bda-a854-b4b9bb1b0a02", + "name": "test-seo", + "mail": null, + "entity": "user", + "language": "en" + }, + "channel": { + "uuid": "0bb70443-8172-4d8e-9335-2876bc32e356", + "published": true, + "name": "Events", + "url": "/events", + "parent": null + }, + "tags": [ + { + "uuid": "35bdba6e-9b45-472a-8fda-11e7e69de71b", + "name": "Drupal", + "url": "/drupal" + } + ], + "seoTitle": "Come to DrupalCon New Orleans", + "content": [ + { + "__typename": "ParagraphGallery" + }, + { + "__typename": "ParagraphText" + }, + { + "__typename": "ParagraphTwitter" + }, + { + "__typename": "ParagraphLink" + }, + { + "__typename": "ParagraphQuote" + }, + { + "__typename": "ParagraphVideo" + }, + { + "__typename": "ParagraphPinterest" + } + ], + "teaser": { + "text": "The Drupal community is one of the largest open source communities in the world. We're developers, designers, strategists, coordinators, editors, translators, and more. Each year, we meet at DrupalCamps, meetups, and other events in more than 200 countries. But once a year, our community comes together at the biggest Drupal event in the world: DrupalCon North America. This year, from May 9-13, we'll be in New Orleans.", + "image": { + "uuid": "a4c1035a-5b27-4713-8ba3-40ba5942486d", + "derivative": { + "width": 220 + } + } + } + } + } +} diff --git a/modules/thunder_gqls/tests/examples/node.variables.json b/modules/thunder_gqls/tests/examples/node.variables.json new file mode 100644 index 000000000..6860c9fba --- /dev/null +++ b/modules/thunder_gqls/tests/examples/node.variables.json @@ -0,0 +1,3 @@ +{ + "uuid": "36b2e2b2-3df0-43eb-a282-d792b0999c07" +}