From 88765ce6cb6849c787408fb333b64e7d10c0072d Mon Sep 17 00:00:00 2001 From: Peter Berryman Date: Wed, 5 Oct 2022 15:07:49 +0100 Subject: [PATCH 1/6] Add verbose debug so we can se what's happening in graphql --- src/Controller/GraphqlController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Controller/GraphqlController.php b/src/Controller/GraphqlController.php index fc298f6..f0479b0 100644 --- a/src/Controller/GraphqlController.php +++ b/src/Controller/GraphqlController.php @@ -72,6 +72,11 @@ public function graphql(string $schema, ServerRequestInterface $request) { if (stripos($request->getHeaderLine("content-type"), "application/json") !== false) { $input = Json::decode($request->getBody()->getContents()); // $this->persistQueries($input); + if (\Drupal::state()->get('debug') === 'verbose') { + \Drupal::logger('simple_graphql') + ->info('
' . print_r($input, 1) . '
'); + } + $request = $request->withParsedBody($input); } From 00d882675ce7714b83846cc6ad9c6a3e0e3548e2 Mon Sep 17 00:00:00 2001 From: Peter Berryman Date: Wed, 5 Oct 2022 15:12:02 +0100 Subject: [PATCH 2/6] Namespace state param --- src/Controller/GraphqlController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/GraphqlController.php b/src/Controller/GraphqlController.php index f0479b0..e8edfbd 100644 --- a/src/Controller/GraphqlController.php +++ b/src/Controller/GraphqlController.php @@ -72,7 +72,7 @@ public function graphql(string $schema, ServerRequestInterface $request) { if (stripos($request->getHeaderLine("content-type"), "application/json") !== false) { $input = Json::decode($request->getBody()->getContents()); // $this->persistQueries($input); - if (\Drupal::state()->get('debug') === 'verbose') { + if (\Drupal::state()->get('simple_graphql_debug') === 'verbose') { \Drupal::logger('simple_graphql') ->info('
' . print_r($input, 1) . '
'); } From 407ccfed4af8730f2cd09303c93dcffd9079464f Mon Sep 17 00:00:00 2001 From: Peter Berryman Date: Wed, 27 Sep 2023 14:17:56 +0100 Subject: [PATCH 3/6] D10 updates --- simple_graphql.info.yml | 2 +- src/Controller/GraphqlController.php | 2 +- src/Graphql/FieldResolver/TextFieldResolver.php | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/simple_graphql.info.yml b/simple_graphql.info.yml index 2830f76..aa1af1f 100644 --- a/simple_graphql.info.yml +++ b/simple_graphql.info.yml @@ -1,7 +1,7 @@ name: Simple GraphQL description: Exposes your Drupal data model through a GraphQL schema. package: graphql -core_version_requirement: ^8.8 || ^9 +core_version_requirement: ^9 || ^10 type: module version: 1.0 diff --git a/src/Controller/GraphqlController.php b/src/Controller/GraphqlController.php index e8edfbd..f31528e 100644 --- a/src/Controller/GraphqlController.php +++ b/src/Controller/GraphqlController.php @@ -102,7 +102,7 @@ public function getSchema($pluginId, $definition, $plugin) { if ($c = $this->cache->get($key)) { $doc = AST::fromArray($c->data); } else { - $path = DRUPAL_ROOT . "/" . drupal_get_path("module", $definition["provider"]) . "/" . $definition["schemaFile"]; + $path = DRUPAL_ROOT . "/" . \Drupal::service('extension.list.module')->getPathname('node') . "/" . $definition["schemaFile"]; $doc = Parser::parse(file_get_contents($path)); $this->cache->set($key, AST::toArray($doc)); } diff --git a/src/Graphql/FieldResolver/TextFieldResolver.php b/src/Graphql/FieldResolver/TextFieldResolver.php index 391edfd..49557de 100644 --- a/src/Graphql/FieldResolver/TextFieldResolver.php +++ b/src/Graphql/FieldResolver/TextFieldResolver.php @@ -6,6 +6,7 @@ use Drupal\Core\TypedData\TypedDataInterface; use Drupal\text\Plugin\Field\FieldType\TextItemBase; use Drupal\text\Plugin\Field\FieldType\TextWithSummaryItem; +use Drupal\Core\Render\RendererInterface; use GraphQL\Type\Definition\ResolveInfo; class TextFieldResolver extends FieldResolverBase { @@ -26,7 +27,7 @@ public function resolveRow(TypedDataInterface $item, $definition, $args, $contex "value" => $item->value, "format" => $item->format, "processed" => $item->processed, - "summary_computed" => (string) render($viewVar), + "summary_computed" => (string) RendererInterface::render($viewVar), ]; } From d1f5b1e57f6f7df92adcbbb52637f3ab9c024bc3 Mon Sep 17 00:00:00 2001 From: Peter Berryman Date: Thu, 28 Sep 2023 14:22:59 +0100 Subject: [PATCH 4/6] D10 fixes --- src/Controller/GraphqlController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/GraphqlController.php b/src/Controller/GraphqlController.php index f31528e..9b1ced7 100644 --- a/src/Controller/GraphqlController.php +++ b/src/Controller/GraphqlController.php @@ -102,7 +102,7 @@ public function getSchema($pluginId, $definition, $plugin) { if ($c = $this->cache->get($key)) { $doc = AST::fromArray($c->data); } else { - $path = DRUPAL_ROOT . "/" . \Drupal::service('extension.list.module')->getPathname('node') . "/" . $definition["schemaFile"]; + $path = DRUPAL_ROOT . "/" . \Drupal::service('extension.list.module')->getPath($definition["provider"]) . "/" . $definition["schemaFile"]; $doc = Parser::parse(file_get_contents($path)); $this->cache->set($key, AST::toArray($doc)); } From b9df15966bf911bff12bbb4aa68286d1f462b054 Mon Sep 17 00:00:00 2001 From: Dan James Date: Mon, 25 Mar 2024 21:17:01 +0000 Subject: [PATCH 5/6] fix "Attempt to read property "data" on bool in Drupal\simple_graphql\Plugin\DrupalSchemaDecorator->entityTypeMap()" --- src/Plugin/DrupalSchemaDecorator.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Plugin/DrupalSchemaDecorator.php b/src/Plugin/DrupalSchemaDecorator.php index 03828b0..3099665 100644 --- a/src/Plugin/DrupalSchemaDecorator.php +++ b/src/Plugin/DrupalSchemaDecorator.php @@ -41,6 +41,7 @@ public function getTypeConfigDecorator(array $fieldResolvers) { if ($typeDefinitionNode instanceof ObjectTypeDefinitionNode) { foreach ($typeDefinitionNode->directives as $d) { if ($d->name->value === "entity") { + // todo we can also have a "isTypeOf" function which might enable us to remove the resolveEntityType, and the map. $typeConfig["resolveField"] = $resolveEntityField; break; } @@ -82,11 +83,12 @@ public function withDrupal(ServerConfig $config): ServerConfig { } public function entityTypeMap(Schema $schema, string $pluginId) { + // TODO is it worth caching? If so, then we should add the missing cache->set $entityTypeMapCache = $this->cache->get("simple_graphql.entityTypeMap." . $pluginId); $entityTypeMap = []; - if ($entityTypeMapCache->data) { + if ($entityTypeMapCache) { $entityTypeMap = $entityTypeMapCache->data; } else { $typeMap = $schema->getTypeMap(); From 66cab0da66c7671720da17993567e5f82ac9166e Mon Sep 17 00:00:00 2001 From: Dan James Date: Mon, 25 Mar 2024 21:20:56 +0000 Subject: [PATCH 6/6] fix Attempt to read property directives on null in Drupal\simple_graphql\Plugin\DrupalSchemaDecorator->entityTypeMap() and foreach() argument must be of type array|object, null given in Drupal\simple_graphql\Plugin\DrupalSchemaDecorator->entityTypeMap() --- src/Plugin/DrupalSchemaDecorator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin/DrupalSchemaDecorator.php b/src/Plugin/DrupalSchemaDecorator.php index 3099665..e2ce186 100644 --- a/src/Plugin/DrupalSchemaDecorator.php +++ b/src/Plugin/DrupalSchemaDecorator.php @@ -94,7 +94,7 @@ public function entityTypeMap(Schema $schema, string $pluginId) { $typeMap = $schema->getTypeMap(); foreach ($typeMap as $type) { - if ($type instanceof ObjectType) { + if ($type instanceof ObjectType && $type->astNode) { foreach ($type->astNode->directives as $d) { if ($d->name->value === "entity") { $info = [