getting revisions from graphql #2203

This commit is contained in:
Bachir Soussi Chiadmi 2023-07-13 12:40:00 +02:00
parent e602d6cb55
commit 26c80c8f27
3 changed files with 38 additions and 0 deletions

View File

@ -9,6 +9,7 @@ interface NodeInterface {
type Concernement implements NodeInterface {
id: Int!
revision_id: Int!
path: String!
uuid: String!
bundle: String!

View File

@ -15,6 +15,10 @@ extend type Query {
concernement(id: Int!): Concernement
}
extend type Query {
concernementrevisions(id: Int!): [Concernement]
}
extend type Query {
allentites: [Entite]
}

View File

@ -154,11 +154,36 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('id', $builder->fromArgument('id'))
);
$registry->addFieldResolver('Query', 'concernementrevisions',
$builder->compose(
$builder->produce('entity_load')
->map('type', $builder->fromValue('node'))
->map('id', $builder->fromArgument('id')),
$builder->callback(function($parent, $arg){
$vids = \Drupal::entityTypeManager()->getStorage('node')->revisionIds($parent);
$revisions = [];
foreach($vids as $vid){
$revisions[] = \Drupal::entityTypeManager()->getStorage('node')->loadRevision($vid);
}
return $revisions;
})
)
);
$registry->addFieldResolver('Concernement', 'id',
$builder->produce('entity_id')
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Concernement', 'revision_id',
$builder->compose(
$builder->callback(function($parent, $arg){
$revid = $parent->getRevisionId();
return $revid;
})
)
);
$registry->addFieldResolver('Concernement', 'uuid',
$builder->produce('entity_uuid')
->map('entity', $builder->fromParent())
@ -269,6 +294,14 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_doleancer'))
);
// revisions: [Concernement]
$registry->addFieldResolver('Concernement', 'revisions',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_doleancer'))
);
}
// _____ _ _ _ __ ___ _ __ __