graphql api for entités
This commit is contained in:
parent
e81913c2e1
commit
3467bc3f5f
|
@ -21,7 +21,7 @@ settings:
|
||||||
handler: 'default:file'
|
handler: 'default:file'
|
||||||
handler_settings: { }
|
handler_settings: { }
|
||||||
file_directory: '[date:custom:Y]-[date:custom:m]'
|
file_directory: '[date:custom:Y]-[date:custom:m]'
|
||||||
file_extensions: ogg
|
file_extensions: 'ogg mp3 flac'
|
||||||
max_filesize: ''
|
max_filesize: ''
|
||||||
description_field: true
|
description_field: true
|
||||||
field_type: file
|
field_type: file
|
||||||
|
|
|
@ -32,10 +32,19 @@ type Entite implements NodeInterface {
|
||||||
title: String!
|
title: String!
|
||||||
path: String!
|
path: String!
|
||||||
author: String
|
author: String
|
||||||
texte: String
|
action: String
|
||||||
|
menacemaintien: String
|
||||||
|
sources: [Source]
|
||||||
|
}
|
||||||
|
|
||||||
|
type Source {
|
||||||
|
audios: Filefield
|
||||||
|
date: Date
|
||||||
|
documents: [Filefield]
|
||||||
|
description: String
|
||||||
images: [Image]
|
images: [Image]
|
||||||
fichiers: [Filefield]
|
|
||||||
liens: [Link]
|
liens: [Link]
|
||||||
|
videos: [VideoLink]
|
||||||
}
|
}
|
||||||
|
|
||||||
type Static implements NodeInterface {
|
type Static implements NodeInterface {
|
||||||
|
|
|
@ -36,6 +36,8 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||||
//
|
//
|
||||||
$this->addEntites($registry, $builder);
|
$this->addEntites($registry, $builder);
|
||||||
//
|
//
|
||||||
|
$this->addSource($registry, $builder);
|
||||||
|
//
|
||||||
$this->addStatic($registry, $builder);
|
$this->addStatic($registry, $builder);
|
||||||
//
|
//
|
||||||
$this->addGroup($registry, $builder);
|
$this->addGroup($registry, $builder);
|
||||||
|
@ -259,7 +261,6 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||||
// | _| | '_ \| __| | __/ _ \/ __|
|
// | _| | '_ \| __| | __/ _ \/ __|
|
||||||
// | |___| | | | |_| | || __/\__ \
|
// | |___| | | | |_| | || __/\__ \
|
||||||
// |_____|_| |_|\__|_|\__\___||___/
|
// |_____|_| |_|\__|_|\__\___||___/
|
||||||
|
|
||||||
protected function addEntites(ResolverRegistryInterface $registry, ResolverBuilder $builder){
|
protected function addEntites(ResolverRegistryInterface $registry, ResolverBuilder $builder){
|
||||||
$registry->addFieldResolver('Query', 'allentites',
|
$registry->addFieldResolver('Query', 'allentites',
|
||||||
$builder->compose(
|
$builder->compose(
|
||||||
|
@ -330,11 +331,18 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||||
->map('entity', $builder->fromParent())
|
->map('entity', $builder->fromParent())
|
||||||
));
|
));
|
||||||
|
|
||||||
$registry->addFieldResolver('Entite', 'texte',
|
$registry->addFieldResolver('Entite', 'action',
|
||||||
$builder->produce('property_path')
|
$builder->produce('property_path')
|
||||||
->map('type', $builder->fromValue('entity:node'))
|
->map('type', $builder->fromValue('entity:node'))
|
||||||
->map('value', $builder->fromParent())
|
->map('value', $builder->fromParent())
|
||||||
->map('path', $builder->fromValue('body.value'))
|
->map('path', $builder->fromValue('field_action.value'))
|
||||||
|
);
|
||||||
|
|
||||||
|
$registry->addFieldResolver('Entite', 'menacemaintien',
|
||||||
|
$builder->produce('property_path')
|
||||||
|
->map('type', $builder->fromValue('entity:node'))
|
||||||
|
->map('value', $builder->fromParent())
|
||||||
|
->map('path', $builder->fromValue('field_menace_maintien.value'))
|
||||||
);
|
);
|
||||||
|
|
||||||
$registry->addFieldResolver('Entite', 'author',
|
$registry->addFieldResolver('Entite', 'author',
|
||||||
|
@ -345,34 +353,73 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||||
->map('entity', $builder->fromParent())
|
->map('entity', $builder->fromParent())
|
||||||
));
|
));
|
||||||
|
|
||||||
$registry->addFieldResolver('Entite', 'images',
|
|
||||||
|
$registry->addFieldResolver('Entite', 'sources',
|
||||||
|
$builder->produce('entity_reference_revisions')
|
||||||
|
->map('entity', $builder->fromParent())
|
||||||
|
->map('field', $builder->fromValue('field_sources'))
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// ____
|
||||||
|
// / ___| ___ _ _ _ __ ___ ___
|
||||||
|
// \___ \ / _ \| | | | '__/ __/ _ \
|
||||||
|
// ___) | (_) | |_| | | | (_| __/
|
||||||
|
// |____/ \___/ \__,_|_| \___\___|
|
||||||
|
protected function addSource(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
|
||||||
|
|
||||||
|
|
||||||
|
$registry->addFieldResolver('Source', 'description',
|
||||||
|
$builder->produce('property_path')
|
||||||
|
->map('type', $builder->fromValue('entity:paragraph'))
|
||||||
|
->map('value', $builder->fromParent())
|
||||||
|
->map('path', $builder->fromValue('field_description.value'))
|
||||||
|
);
|
||||||
|
|
||||||
|
$registry->addFieldResolver('Source', 'images',
|
||||||
$builder->produce('entity_reference')
|
$builder->produce('entity_reference')
|
||||||
->map('entity', $builder->fromParent())
|
->map('entity', $builder->fromParent())
|
||||||
->map('field', $builder->fromValue('field_images'))
|
->map('field', $builder->fromValue('field_images'))
|
||||||
);
|
);
|
||||||
|
|
||||||
$registry->addFieldResolver('Entite', 'videos',
|
$registry->addFieldResolver('Source', 'videos',
|
||||||
$builder->produce('property_path')
|
$builder->produce('property_path')
|
||||||
->map('type', $builder->fromValue('entity:node'))
|
->map('type', $builder->fromValue('entity:paragraph'))
|
||||||
->map('value', $builder->fromParent())
|
->map('value', $builder->fromParent())
|
||||||
->map('path', $builder->fromValue('field_videos'))
|
->map('path', $builder->fromValue('field_videos'))
|
||||||
);
|
);
|
||||||
|
|
||||||
$registry->addFieldResolver('Entite', 'fichiers',
|
$registry->addFieldResolver('Source', 'documents',
|
||||||
$builder->produce('entity_reference')
|
$builder->produce('property_path')
|
||||||
->map('entity', $builder->fromParent())
|
->map('type', $builder->fromValue('entity:paragraph'))
|
||||||
->map('field', $builder->fromValue('field_fichiers'))
|
->map('value', $builder->fromParent())
|
||||||
|
->map('path', $builder->fromValue('field_documents'))
|
||||||
);
|
);
|
||||||
|
|
||||||
$registry->addFieldResolver('Entite', 'liens',
|
$registry->addFieldResolver('Source', 'liens',
|
||||||
$builder->produce('property_path')
|
$builder->produce('property_path')
|
||||||
->map('type', $builder->fromValue('entity:node'))
|
->map('type', $builder->fromValue('entity:paragraph'))
|
||||||
->map('value', $builder->fromParent())
|
->map('value', $builder->fromParent())
|
||||||
->map('path', $builder->fromValue('field_liens'))
|
->map('path', $builder->fromValue('field_liens'))
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
$registry->addFieldResolver('Source', 'date',
|
||||||
|
$builder->produce('property_path')
|
||||||
|
->map('type', $builder->fromValue('entity:paragraph'))
|
||||||
|
->map('value', $builder->fromParent())
|
||||||
|
->map('path', $builder->fromValue('field_date'))
|
||||||
|
);
|
||||||
|
|
||||||
|
$registry->addFieldResolver('Source', 'audios',
|
||||||
|
$builder->produce('property_path')
|
||||||
|
->map('type', $builder->fromValue('entity:paragraph'))
|
||||||
|
->map('value', $builder->fromParent())
|
||||||
|
->map('path', $builder->fromValue('field_audio'))
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
// ___ _ _ _
|
// ___ _ _ _
|
||||||
// / __| |_ __ _| |_(_)__ ___
|
// / __| |_ __ _| |_(_)__ ___
|
||||||
// \__ \ _/ _` | _| / _(_-<
|
// \__ \ _/ _` | _| / _(_-<
|
||||||
|
@ -684,13 +731,25 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||||
|
|
||||||
$registry->addFieldResolver('Filefield', 'description',
|
$registry->addFieldResolver('Filefield', 'description',
|
||||||
$builder->callback(function ($parent, $args) {
|
$builder->callback(function ($parent, $args) {
|
||||||
return $parent['description'];
|
if (is_array($parent) && isset($parent['description'])) {
|
||||||
|
return $parent['description'];
|
||||||
|
} else if (is_array($parent) && isset($parent[0]['description'])) {
|
||||||
|
return $parent[0]['description'];
|
||||||
|
} else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
$registry->addFieldResolver('Filefield', 'file',
|
$registry->addFieldResolver('Filefield', 'file',
|
||||||
$builder->callback(function ($parent, $args) {
|
$builder->callback(function ($parent, $args) {
|
||||||
return \Drupal\file\Entity\File::load($parent['target_id']);
|
if (is_array($parent) && isset($parent['target_id'])) {
|
||||||
|
return \Drupal\file\Entity\File::load($parent['target_id']);
|
||||||
|
} else if (is_array($parent) && isset($parent[0]['target_id'])) {
|
||||||
|
return \Drupal\file\Entity\File::load($parent[0]['target_id']);
|
||||||
|
} else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -884,16 +943,24 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||||
protected function addLink(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
|
protected function addLink(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
|
||||||
$registry->addFieldResolver('Link', 'url',
|
$registry->addFieldResolver('Link', 'url',
|
||||||
$builder->callback(function ($parent, $args) {
|
$builder->callback(function ($parent, $args) {
|
||||||
return isset($parent[0]) ? $parent[0]['uri'] : null;
|
// return isset($parent[0]) ? $parent[0]['uri'] : null;
|
||||||
|
return $parent['uri'];
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
$registry->addFieldResolver('Link', 'title',
|
$registry->addFieldResolver('Link', 'title',
|
||||||
$builder->callback(function ($parent, $args) {
|
$builder->callback(function ($parent, $args) {
|
||||||
return isset($parent[0]) ? $parent[0]['title'] : null;
|
// return isset($parent[0]) ? $parent[0]['title'] : null;
|
||||||
|
return $parent['title'];
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// _____ _ _ _ ____ __ _ _ _ _
|
||||||
|
// | ____|_ __ | |_(_) |_ _ _ | _ \ ___ / _(_)_ __ (_) |_(_) ___ _ __
|
||||||
|
// | _| | '_ \| __| | __| | | | | | | |/ _ \ |_| | '_ \| | __| |/ _ \| '_ \
|
||||||
|
// | |___| | | | |_| | |_| |_| | | |_| | __/ _| | | | | | |_| | (_) | | | |
|
||||||
|
// |_____|_| |_|\__|_|\__|\__, | |____/ \___|_| |_|_| |_|_|\__|_|\___/|_| |_|
|
||||||
|
// |___/
|
||||||
protected function addEntityDefinition(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
|
protected function addEntityDefinition(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
|
||||||
$registry->addFieldResolver('Query', 'entitydef',
|
$registry->addFieldResolver('Query', 'entitydef',
|
||||||
$builder->compose(
|
$builder->compose(
|
||||||
|
@ -913,6 +980,11 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// _____ _ _ _ ____ __
|
||||||
|
// | ___(_) ___| | __| | | _ \ ___ / _|
|
||||||
|
// | |_ | |/ _ \ |/ _` | | | | |/ _ \ |_
|
||||||
|
// | _| | | __/ | (_| | | |_| | __/ _|
|
||||||
|
// |_| |_|\___|_|\__,_| |____/ \___|_|
|
||||||
protected function addFieldDef(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
|
protected function addFieldDef(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
|
||||||
|
|
||||||
$registry->addFieldResolver('FieldDef', 'type',
|
$registry->addFieldResolver('FieldDef', 'type',
|
||||||
|
|
Loading…
Reference in New Issue