improving graphql defs

This commit is contained in:
Bachir Soussi Chiadmi 2020-12-22 22:00:12 +01:00
parent 2175e7ae2d
commit 665a550748
2 changed files with 112 additions and 25 deletions

View File

@ -17,10 +17,10 @@ type Materiau {
attachments: [Filefield]
distributor: [Company]
manufacturer: [Company]
# famille:
# index:
# reference:
# samples:
# famille: String
# index: Int
reference: String
samples: [Sample]
}
type Article {
@ -40,6 +40,11 @@ type Article {
memo: String
}
type Sample {
showroom: Showroom
location: String
}
type Filefield {
file: File!
description: String
@ -64,15 +69,16 @@ type Showroom {
uuid: String!
name: String!
images: [Image]
# email: String
# address: Adress
# phone: String
email: String
address: Address
phone: String
}
type Company {
id: Int!
uuid: String!
name: String!
description: String
attachments: [Filefield]
memo: String
note: Int
@ -80,8 +86,8 @@ type Company {
departement: String
email: String
address: Address
# infos
# phone
phone: String
infos: String
}
type Tag {

View File

@ -26,6 +26,8 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
$this->addMateriau($registry, $builder);
$this->addSample($registry, $builder);
$this->addArticle($registry, $builder);
$this->addCompany($registry, $builder);
@ -175,14 +177,55 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('field', $builder->fromValue('field_distributor'))
);
// field_famille
// field_index
// field_reference
// field_samples
// $registry->addFieldResolver('Materiau', 'famille',
// $builder->produce('property_path')
// ->map('type', $builder->fromValue('entity:node'))
// ->map('value', $builder->fromParent())
// ->map('path', $builder->fromValue('field_famille.value'))
// );
//
// $registry->addFieldResolver('Materiau', 'index',
// $builder->produce('property_path')
// ->map('type', $builder->fromValue('entity:node'))
// ->map('value', $builder->fromParent())
// ->map('path', $builder->fromValue('field_index.value'))
// );
$registry->addFieldResolver('Materiau', 'reference',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_reference.value'))
);
$registry->addFieldResolver('Materiau', 'samples',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_samples'))
);
}
// ___ _
// / __| __ _ _ __ _ __| |___
// \__ \/ _` | ' \| '_ \ / -_)
// |___/\__,_|_|_|_| .__/_\___|
// |_|
protected function addSample(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
$registry->addFieldResolver('Sample', 'showroom',
$builder->callback(function($parent, $args){
return \Drupal\taxonomy\Entity\Term::load($parent['target_id']);
})
);
$registry->addFieldResolver('Sample', 'location',
$builder->callback(function($parent, $args){
return $parent['location'];
})
);
}
// _ _ _ _
// /_\ _ _| |_(_)__| |___
// / _ \| '_| _| / _| / -_)
@ -435,6 +478,28 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
$builder->produce('entity_label')
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Showroom', 'email',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:taxonomy_term'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_public_email.value'))
);
$registry->addFieldResolver('Showroom', 'address',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:taxonomy_term'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_public_address'))
);
$registry->addFieldResolver('Showroom', 'phone',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:taxonomy_term'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_public_phone.value'))
);
}
// _ _ _
@ -626,7 +691,6 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
);
}
// ___
// / __|___ _ __ _ __ __ _ _ _ _ _
// | (__/ _ \ ' \| '_ \/ _` | ' \ || |
@ -641,19 +705,25 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
);
$registry->addFieldResolver('Company', 'id',
$builder->produce('entity_id')
->map('entity', $builder->fromParent())
);
$builder->produce('entity_id')
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Company', 'uuid',
$builder->produce('entity_uuid')
->map('entity', $builder->fromParent())
);
$builder->produce('entity_uuid')
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Company', 'name',
$builder->produce('entity_label')
->map('entity', $builder->fromParent())
);
$builder->produce('entity_label')
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Company', 'description',
$builder->callback(function($parent, $args){
return $parent->getDescription();
})
);
// TODO: property_path helper
// $props = [
@ -721,8 +791,19 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('path', $builder->fromValue('field_public_address'))
);
// field_infos_from_company
// field_public_phone
$registry->addFieldResolver('Company', 'phone',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:taxonomy_term'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_public_phone.value'))
);
$registry->addFieldResolver('Company', 'infos',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:taxonomy_term'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_infos_from_company.value'))
);
}
/**