add queries mapitems(ids) & allmapitemsof(familyId)

This commit is contained in:
axolotle
2021-07-01 13:14:07 +02:00
parent 82366fe431
commit 9eb4584930
2 changed files with 44 additions and 2 deletions
@@ -3,12 +3,21 @@
# } # }
extend type Query { extend type Query {
mapitems: [MapItemInterface] allmapitems: [MapItemInterface]
} }
extend type Query {
mapitems(ids: [Int]): [MapItemInterface]
}
extend type Query { extend type Query {
mapitem(id: Int!): MapItemInterface mapitem(id: Int!): MapItemInterface
} }
extend type Query {
allmapitemsof(familyId: Int!): [MapItemInterface]
}
extend type Query { extend type Query {
texts: [TextInterface] texts: [TextInterface]
} }
@@ -168,7 +168,7 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
throw new Error('Could not resolve content type.'); throw new Error('Could not resolve content type.');
}); });
$registry->addFieldResolver('Query', 'mapitems', $registry->addFieldResolver('Query', 'allmapitems',
$builder->compose( $builder->compose(
$builder->callback(function($parent, $arg){ $builder->callback(function($parent, $arg){
$entity_storage = \Drupal::entityTypeManager()->getStorage('node'); $entity_storage = \Drupal::entityTypeManager()->getStorage('node');
@@ -184,11 +184,44 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
) )
); );
$registry->addFieldResolver('Query', 'mapitems',
$builder->compose(
$builder->callback(function($parent, $arg){
$entity_storage = \Drupal::entityTypeManager()->getStorage('node');
$query = $entity_storage->getQuery()
->condition('type', ['texte', 'texte_prod', 'creation'], 'IN')
->accessCheck(TRUE);
$results = $query->execute();
return $results;
}),
$builder->produce('entity_load_multiple')
->map('type', $builder->fromValue('node'))
->map('ids', $builder->fromArgument('ids'))
)
);
$registry->addFieldResolver('Query', 'mapitem', $registry->addFieldResolver('Query', 'mapitem',
$builder->produce('entity_load') $builder->produce('entity_load')
->map('type', $builder->fromValue('node')) ->map('type', $builder->fromValue('node'))
->map('id', $builder->fromArgument('id')) ->map('id', $builder->fromArgument('id'))
); );
$registry->addFieldResolver('Query', 'allmapitemsof',
$builder->compose(
$builder->callback(function($parent, $arg){
$entity_storage = \Drupal::entityTypeManager()->getStorage('node');
$query = $entity_storage->getQuery()
->condition('type', ['texte', 'texte_prod'], 'IN')
->condition('field_famille', $arg)
->accessCheck(TRUE);
$results = $query->execute();
return $results;
}),
$builder->produce('entity_load_multiple')
->map('type', $builder->fromValue('node'))
->map('ids', $builder->fromParent())
)
);
} }
// _____ _ ___ _ // _____ _ ___ _