CT static gql ok

This commit is contained in:
2021-05-19 14:51:23 +02:00
parent 5e71280cbb
commit 59ac63f160
3 changed files with 131 additions and 0 deletions
@@ -80,6 +80,19 @@ type Creation implements NodeInterface {
texte_de_depart: [Textref] # field_texte_de_depart
}
type Static implements NodeInterface {
id: Int!
uuid: String!
bundle: String!
title: String!
path: String!
author: String
texte: String
notes: [Noteprod]
fichiers: [File]
poid: Int
}
interface NoteInterface {
note: String
numero: Int
@@ -42,6 +42,18 @@ extend type Query {
creation(id: Int!): Creation
}
extend type Query {
allstatics: [Static]
}
extend type Query {
statics(ids: [Int]): [Static]
}
extend type Query {
static(id: Int!): Static
}
extend type Query {
famille(id: Int!): Taxoterm
}
@@ -42,6 +42,8 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
$this->addNoteProd($registry, $builder);
$this->addCreation($registry, $builder);
$this->addStatic($registry, $builder);
//
$this->addFilefield($registry, $builder);
//
@@ -632,6 +634,110 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
);
}
// ___ _ _ _
// / __| |_ __ _| |_(_)__ ___
// \__ \ _/ _` | _| / _(_-<
// |___/\__\__,_|\__|_\__/__/
protected function addStatic(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
$registry->addFieldResolver('Query', 'allstatics',
$builder->compose(
$builder->callback(function($parent, $arg){
$entity_storage = \Drupal::entityTypeManager()->getStorage('node');
$query = $entity_storage->getQuery()
->condition('type', ['static'], 'IN')
->accessCheck(TRUE);
$results = $query->execute();
return $results;
}),
$builder->produce('entity_load_multiple')
->map('type', $builder->fromValue('node'))
->map('ids', $builder->fromParent())
)
);
$registry->addFieldResolver('Query', 'statics',
$builder->produce('entity_load_multiple')
->map('type', $builder->fromValue('node'))
->map('ids', $builder->fromArgument('ids'))
);
$registry->addFieldResolver('Query', 'static',
$builder->produce('entity_load')
->map('type', $builder->fromValue('node'))
->map('bundles', $builder->fromValue(['static']))
->map('id', $builder->fromArgument('id'))
);
$registry->addFieldResolver('Static', 'id',
$builder->produce('entity_id')
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Static', 'uuid',
$builder->produce('entity_uuid')
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Static', 'path',
$builder->compose(
$builder->produce('entity_url')
->map('entity', $builder->fromParent()),
$builder->produce('url_path')
->map('url', $builder->fromParent())
)
);
$registry->addFieldResolver('Static', 'title',
$builder->compose(
$builder->produce('entity_label')
->map('entity', $builder->fromParent())
));
$registry->addFieldResolver('Static', 'bundle',
$builder->compose(
$builder->produce('entity_bundle')
->map('entity', $builder->fromParent())
));
$registry->addFieldResolver('Static', 'texte',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('body.value'))
);
$registry->addFieldResolver('Static', 'author',
$builder->compose(
$builder->produce('entity_owner')
->map('entity', $builder->fromParent()),
$builder->produce('entity_label')
->map('entity', $builder->fromParent())
));
$registry->addFieldResolver('Static', 'fichiers',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_fichier'))
);
$registry->addFieldResolver('Static', 'notes',
$builder->produce('entity_reference_revisions')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_notes'))
);
$registry->addFieldResolver('Static', 'poid',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_poid.value'))
);
}
// ___ _
// | \ __ _| |_ ___
// | |) / _` | _/ -_)