GRAPHQL V4

 

WHAT'S NEW?

 

PRESENTED BY FRAN GARCIA-LINARES / 17 JULY 2019

ABOUT ME

fran.garcia@amazeelabs.com

Fran García-Linares, Drupal web developer

fjgarlin@gmail.com

https://www.drupal.org/u/fjgarlin

...linkedin, github, slides.com, strava  fjgarlin

We are

HIRING

Intro (2 min)

GraphQL: what it really is (3 min)

Drupal GraphQL v3 (5 min)

Drupal GraphQL v4 (10 min)

Credits (2 min)

Q & A (3 min)

AGENDA

25 Minutes

 

  • Query language for your data
  • Ask for what you need, get just that
  • Many resources in a single request

 

 

Q: Is this request Drupal??

GraphQL: what it really is

  • What's under a GraphQL endpoint?
  • Full control of what's exposed

GraphQL: what it really is 

Q: Is this achievable via Drupal??

Drupal GraphQL v3

  • Schema will change if fields are removed / modified

  • Drupal updates could also alter schema

  • You know it’s Drupal

Drupal GraphQL v4

  • Instead of just exposing everything Drupal has to offer, it allows us to create a tailored schema.
  • This contract is not imposed by Drupal, but by the business needs.
  • From here on the team could be decoupled based on this contract.
  • Actual decoupling (replaceable back-end!)

​*SDL = Schema Definition Language

New feature(s): Support for SDL based schemas

 

Drupal GraphQL v4

New feature(s): Support for SDL based schemas

 

Now it’s part of the main v4 GraphQL repo

Compare branches: https://github.com/drupal-graphql/graphql/compare/8.x-3.x...8.x-4.x

 

 

It all began here: https://github.com/drupal-graphql/graphql-sdl 

Archived, but perfect for initial "reading"

Drupal GraphQL v4

Code: The beginnings...

...
  protected function getSchemaDefinition() {
    return file_get_contents(
        drupal_get_path('module', 'my_graphql') . 
        '/schema.graphql'
    );
  }
...
  protected function getSchemaDefinition() {
    return <<<GQL
      schema {
        query: Query
      }
      type Query {
        article(id: Int!): Article
...
namespace Drupal\graphql\Plugin\GraphQL\Schema;

/**
 * @Schema(
 *   id = "test",
 *   name = "My schema"
 * )
 */
class SdlSchemaTest extends SdlSchemaPluginBase {
...

Drupal GraphQL v4

Code: SchemaPlugin

protected function getResolverRegistry() {
    $builder = new ResolverBuilder();
    $registry = new ResolverRegistry([
      'Article' => ContextDefinition::create('entity:node')
        ->addConstraint('Bundle', 'article'),
      'Page' => ContextDefinition::create('entity:node')
        ->addConstraint('Bundle', 'page'),
    ]);
    $registry->addFieldResolver('Query', 'node',
      $builder->produce('entity_load', ['mapping' => [
        'entity_type' => $builder->fromValue('node'),
        'entity_id' => $builder->fromArgument('id'),
      ]])
    );
    $registry->addFieldResolver(...
...

This can be replaced by an UI eventually

Drupal GraphQL v4

Code: SchemaPlugin

Atomic resolver plugins or DataProducers

 

 

Used within the SchemaPlugin

Drupal GraphQL v4

Code: DataProducer

  • Input / output helper plugins

    • ie: uppercase, url
    • Used in SchemaPlugin

Drupal GraphQL v4

Code: DataProducers

  • Schema.graphql
  • MySchema.php
    (SdlSchemaPluginBase)
  • Markdown.php
    (DataProducerPluginBase)

Drupal GraphQL v4

Code: Put everything together

  • Already possible to create multiple schema’s from the UI

    • ​Just that, the rest happens in code.

  • More powerful UI coming soon

    • Think rules UI

    • Goal: have a list of generic data producer plugins and  combine them to build the schema

      • Currently on code: getResolverRegistry

Drupal GraphQL v4

UI

Philipp Melab (pmelab)                                                

CREDITS

 

Sebastian Siemssen (fubhy)

Q&A

https://slides.com/fjgarlin/

 

 

 

 

 

 

 

 

 

 

 

https://github.com/drupal-graphql/graphql/

drupal.slack.com #graphql

 

THANK YOU

 
Made with Slides.com