Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion simple_graphql.info.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion src/Controller/GraphqlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<pre>' . print_r($input, 1) . '</pre>');
}

$request = $request->withParsedBody($input);
}

Expand All @@ -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));
}
Expand Down
3 changes: 2 additions & 1 deletion src/Graphql/FieldResolver/TextFieldResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
];
}

Expand Down
6 changes: 4 additions & 2 deletions src/Plugin/DrupalSchemaDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 = [
Expand Down