Giter Club home page Giter Club logo

Comments (15)

peterkeppert avatar peterkeppert commented on July 30, 2024

I have been playing with configuration entities support and I have two questions.

I see there is EntityUuid field in graphql_core module. However other fields which make use of EntityInterface (which is common to both content and configuration entities) are located in graphql_content instead of graphql_core module, namely: EntityLabel, EntityLanguage, EntityTranslation, EntityBundle, EntityType, EntityUrl. Is there a specific reason to it or can they be moved (as I tested, they work fine without graphql_content module)?

EntityId field is also located in graphql_content module. In my opinion, it could be moved to graphql_core too, however field type and resolver need to change, since currently the field is Int and resolver is using intval on entity ID, causing the configuration entity ID's (which are strings) to be displayed as 0. Was there a reason for allowing only integer value?

from graphql.

pmelab avatar pmelab commented on July 30, 2024

You are right. graphql_core is supposed to handle entities in general and graphql_content content entities. We should move them.

You are right with your second suggestion too. But this is a breaking change if somebody uses a strictly typed client. Although I'm not sure entityId is used too often.
@fubhy Any thoughts?

from graphql.

fubhy avatar fubhy commented on July 30, 2024

I agree and I consider it a minor Breaking change. In fact, entity ids are not specifically enforced as ints. Not even for Content entities. Lets move it all to Core and change ids to Strings. We use string args for entityById already anyways by the way and its the right Thing to do. We are in Alpha so this change is fine for me. Can you submit a PR?

from graphql.

peterkeppert avatar peterkeppert commented on July 30, 2024

PR created: #235

from graphql.

weitzman avatar weitzman commented on July 30, 2024

has anyone thought about a schema for plain config? I'm going to need some field api info (the set of values for a list field).

from graphql.

pmelab avatar pmelab commented on July 30, 2024

This ticket is about exposing plain config entities with typed data. It's just lacking a proper description.

from graphql.

pmelab avatar pmelab commented on July 30, 2024

The main problem is that we can't just add all config entity types because it will blow the schema out into space. We need some way to restrict what to expose.

from graphql.

fubhy avatar fubhy commented on July 30, 2024

This can continue now that we have got #235 merged. Do you want to work on this @peterkeppert?

from graphql.

peterkeppert avatar peterkeppert commented on July 30, 2024

Yes, I will create graphql_config module with basic fields and "Exposed config" screen to restrict which configuration entities will be in the schema.

from graphql.

fubhy avatar fubhy commented on July 30, 2024

@peterkeppert Awesome! By the way, do you want to join us in the Drupal Slack and the #graphql channel? Philipp and me are both in there and can provide assistance easily whenever needed.

Maybe we should also schedule a call to discuss the architecture for the config support?

from graphql.

peterkeppert avatar peterkeppert commented on July 30, 2024

I have created PR #299 with a very basic module, which:

  • Introduces support for configuration entities (with fields defined by grahql_core module).
  • Adds Exposed configuration table, where admin can decide which config entities to expose.
  • Allows to retrieve config entity information by ID.
  • Ships with basic tests.

Example:

{
  nodeTypeById(id: "page") {
    entityLabel
    entityType
    entityUuid
    entityId
  }
}

There are two issues/questions:

  • Only part of configuration is stored as configuration entities and at this moment, module handles only configuration entities. Should module handle both types of configuration?
  • Config entities are not fieldable, so data on configuration entities are stored as arrays or attached like standardized objects (e.g. plugins). However GraphQL is strictly typed, which conflicts with the generic array-based storage + the information which is stored differs per entity type, which in my view prevents reasonable generalization. Should we add all the additional fields as entity type-specific?

from graphql.

wimleers avatar wimleers commented on July 30, 2024

When you add support for this, take https://www.drupal.org/node/2653358 into account, which https://www.drupal.org/node/2915539 did for the jsonapi module and https://www.drupal.org/node/2915414 for core's rest module.

from graphql.

 avatar commented on July 30, 2024

This is my config field deriver(maybe it has something useful):

<?php

namespace Drupal\foo\Plugin\Deriver;

use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\graphql\Utility\StringHelper;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Derives content entity fields as GraphQL fields.
 */
class ConfigFieldDeriver extends DeriverBase implements ContainerDeriverInterface {

  /**
   * Typed config manager.
   *
   * @var \Drupal\Core\Config\TypedConfigManagerInterface
   */
  protected $typedConfigManager;

  /**
   * ConfigFieldDeriver constructor.
   *
   * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config
   */
  public function __construct(TypedConfigManagerInterface $typed_config) {
    $this->typedConfigManager = $typed_config;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $basePluginId) {
    return new static(
      $container->get('config.typed')
    );
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($basePluginDefinition) {
    $this->derivatives = [];
    $types = foo_field_types();

    foreach (foo_exposed_config_entities(TRUE) AS $entity_type_id => $entity_type) {
      /** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type */
      $exportable = array_diff_key(
        $entity_type->getPropertiesToExport() ?? [],
        array_fill_keys(['dependencies', 'third_party_settings', '_core'], '')
      );
      $config_id = $entity_type->getConfigPrefix() . '.*';
      $fields = $this->typedConfigManager->getDefinition($config_id)['mapping'];
      foreach ($fields AS $field_name => $field_definition) {
        $derived_id = $entity_type_id . ':' . $field_name;
        if (isset($types[$field_definition['type']]) && in_array($field_name, $exportable)) {
          $this->derivatives[$derived_id] = [
            'name' => StringHelper::propCase(isset($field_definition['label']) ? foo_untranslated_string($field_definition['label']) : $field_name),
            'type' => $types[$field_definition['type']],
            'parents' => [foo_get_entity_type_name($entity_type_id)],
            'field_name' => $field_name
          ] + $basePluginDefinition;
        }
      }
    }

    return parent::getDerivativeDefinitions($basePluginDefinition);
  }

}

from graphql.

sebkamil avatar sebkamil commented on July 30, 2024

Does expose field types (email, entity reference, text long, list, etc.) and if a field is a required or would I need to keep using the below? Thanks

{
    __type(name:"NodeArticle") {
        fields {
            name
          type {
            name
          }
        }
    }
}

from graphql.

fubhy avatar fubhy commented on July 30, 2024

@sebkamil I don't understand your question. Can you open a new issue?

from graphql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.