GRAPHQL V4
PRESENTED BY FRAN GARCIA-LINARES / 17 JULY 2019
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
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)
25 Minutes
Q: Is this request Drupal??
Q: Is this achievable via Drupal??
Schema will change if fields are removed / modified
Drupal updates could also alter schema
You know it’s Drupal
*SDL = Schema Definition Language
New feature(s): Support for SDL based schemas
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"
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 {
...
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
Code: SchemaPlugin
Atomic resolver plugins or DataProducers
Used within the SchemaPlugin
Code: DataProducer
Input / output helper plugins
Code: DataProducers
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
UI
Philipp Melab (pmelab)
https://drupal-graphql.gitbook.io/graphql/v/8.x-4.x/ - Joao Garin (https://github.com/joaogarin)
Sebastian Siemssen (fubhy)
https://slides.com/fjgarlin/
https://github.com/drupal-graphql/graphql/
drupal.slack.com #graphql