graphql Article donne

This commit is contained in:
Bachir Soussi Chiadmi 2020-12-16 16:53:07 +01:00
parent 2739df96e2
commit 1dcd627cab
3 changed files with 183 additions and 21 deletions

View File

@ -19,23 +19,44 @@ type Article {
linked_materials: [Materiau]
images: [Image]
videos: [VideoLink]
# date: [String]
# showroom: [Showroom]
# source: Link
# tags: []
# thesaurus: []
source: Link
showroom: Showroom
tags: [Tag]
thesaurus: [Thesaurus]
date: Date
}
# type Showroom {
# id: Int!
# uuid: String!
# }
#
#
# type Link {
# url: String!
# title: String
# }
type Link {
url: String
title: String
}
type Showroom {
id: Int!
uuid: String!
name: String!
images: [Image]
# email: String
# address: Adress
# phone: String
}
type Tag {
id: Int!
uuid: String!
name: String!
}
type Thesaurus {
id: Int!
uuid: String!
name: String!
}
type Date {
start: String
end: String
}
type VideoLink {
url: String

View File

@ -5,3 +5,15 @@ extend type Query {
extend type Query {
article(id: Int!): Article
}
extend type Query {
showroom(id: Int!): Showroom
}
extend type Query {
tag(id: Int!): Tag
}
extend type Query {
thesaurus(id: Int!): Thesaurus
}

View File

@ -31,7 +31,7 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('bundles', $builder->fromValue(['materiau']))
->map('id', $builder->fromArgument('id'))
);
$registry->addFieldResolver('Materiau', 'id',
$builder->produce('entity_id')
->map('entity', $builder->fromParent())
@ -131,11 +131,9 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
// https://github.com/drupal-graphql/graphql/blob/8.x-4.x/doc/SUMMARY.md
// https://blog.chrismitchellonline.com/posts/custom_graphql_data/
$registry->addFieldResolver('Article', 'linked_materials',
$builder->compose(
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_linked_materials'))
)
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_linked_materials'))
);
$registry->addFieldResolver('Article', 'images',
@ -151,6 +149,137 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('path', $builder->fromValue('field_video'))
);
$registry->addFieldResolver('Article', 'tags',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_tags'))
);
$registry->addFieldResolver('Article', 'thesaurus',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_thesaurus'))
);
$registry->addFieldResolver('Article', 'showroom',
$builder->compose(
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_showroom')),
$builder->callback(function ($items) {
return $items[0];
})
)
);
$registry->addFieldResolver('Article', 'source',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_source'))
);
$registry->addFieldResolver('Article', 'date',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_date'))
);
// Date
$registry->addFieldResolver('Date', 'start',
$builder->callback(function ($parent, $args) {
return $parent[0]['value'];
})
);
$registry->addFieldResolver('Date', 'end',
$builder->callback(function ($parent, $args) {
return $parent[0]['end_value'];
})
);
// Link
$registry->addFieldResolver('Link', 'url',
$builder->callback(function ($parent, $args) {
return $parent[0]['uri'];
})
);
$registry->addFieldResolver('Link', 'title',
$builder->callback(function ($parent, $args) {
return $parent[0]['title'];
})
);
// Showroom
$registry->addFieldResolver('Query', 'showroom',
$builder->produce('entity_load')
->map('type', $builder->fromValue('taxonomy_term'))
->map('bundles', $builder->fromValue(['showroom']))
->map('id', $builder->fromArgument('id'))
);
$registry->addFieldResolver('Showroom', 'id',
$builder->produce('entity_id')
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Showroom', 'uuid',
$builder->produce('entity_uuid')
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Showroom', 'name',
$builder->produce('entity_label')
->map('entity', $builder->fromParent())
);
// Tag
$registry->addFieldResolver('Query', 'tag',
$builder->produce('entity_load')
->map('type', $builder->fromValue('taxonomy_term'))
->map('bundles', $builder->fromValue(['tags']))
->map('id', $builder->fromArgument('id'))
);
$registry->addFieldResolver('Tag', 'id',
$builder->produce('entity_id')
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Tag', 'uuid',
$builder->produce('entity_uuid')
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Tag', 'name',
$builder->produce('entity_label')
->map('entity', $builder->fromParent())
);
// Thesaurus
$registry->addFieldResolver('Query', 'thesaurus',
$builder->produce('entity_load')
->map('type', $builder->fromValue('taxonomy_term'))
->map('bundles', $builder->fromValue(['thesaurus']))
->map('id', $builder->fromArgument('id'))
);
$registry->addFieldResolver('Thesaurus', 'id',
$builder->produce('entity_id')
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Thesaurus', 'uuid',
$builder->produce('entity_uuid')
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Thesaurus', 'name',
$builder->produce('entity_label')
->map('entity', $builder->fromParent())
);
// VideoLink
$registry->addFieldResolver('VideoLink', 'url',
$builder->produce('property_path')