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 fc298f6..9b1ced7 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('simple_graphql_debug') === 'verbose') { + \Drupal::logger('simple_graphql') + ->info('
' . print_r($input, 1) . ''); + } + $request = $request->withParsedBody($input); } @@ -97,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')->getPath($definition["provider"]) . "/" . $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), ]; } diff --git a/src/Plugin/DrupalSchemaDecorator.php b/src/Plugin/DrupalSchemaDecorator.php index 03828b0..e2ce186 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,17 +83,18 @@ 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(); 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 = [