added group querys to graphql
This commit is contained in:
parent
a1a4d84ab0
commit
2fbdc274b7
|
@ -47,6 +47,32 @@ type Static implements NodeInterface {
|
||||||
texte: String
|
texte: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Group {
|
||||||
|
id: Int!
|
||||||
|
uuid: String!
|
||||||
|
name: String!
|
||||||
|
path: String!
|
||||||
|
description: String
|
||||||
|
owner: User
|
||||||
|
members: [User]
|
||||||
|
}
|
||||||
|
|
||||||
|
# type GroupMember {
|
||||||
|
# id: Int!
|
||||||
|
# user: User
|
||||||
|
# }
|
||||||
|
|
||||||
|
type User {
|
||||||
|
id: Int!
|
||||||
|
email: String
|
||||||
|
username: String
|
||||||
|
roles: [String]
|
||||||
|
}
|
||||||
|
|
||||||
|
# type Role {
|
||||||
|
# name: String!
|
||||||
|
# }
|
||||||
|
|
||||||
type Filefield {
|
type Filefield {
|
||||||
file: File!
|
file: File!
|
||||||
description: String
|
description: String
|
||||||
|
|
|
@ -39,10 +39,14 @@ extend type Query {
|
||||||
static(id: Int!): Static
|
static(id: Int!): Static
|
||||||
}
|
}
|
||||||
|
|
||||||
# extend type Query {
|
extend type Query {
|
||||||
# alltags: [Taxoterm]
|
allgroups: [Group]
|
||||||
# }
|
}
|
||||||
|
|
||||||
# extend type Query {
|
extend type Query {
|
||||||
# tag(id: Int!): Taxoterm
|
groups(ids: [Int]): [Group]
|
||||||
# }
|
}
|
||||||
|
|
||||||
|
extend type Query {
|
||||||
|
group(id: Int!): Group
|
||||||
|
}
|
||||||
|
|
|
@ -37,6 +37,10 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||||
//
|
//
|
||||||
$this->addStatic($registry, $builder);
|
$this->addStatic($registry, $builder);
|
||||||
//
|
//
|
||||||
|
$this->addGroup($registry, $builder);
|
||||||
|
//
|
||||||
|
$this->addUser($registry, $builder);
|
||||||
|
//
|
||||||
$this->addFilefield($registry, $builder);
|
$this->addFilefield($registry, $builder);
|
||||||
//
|
//
|
||||||
$this->addFile($registry, $builder);
|
$this->addFile($registry, $builder);
|
||||||
|
@ -445,6 +449,152 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ______
|
||||||
|
// / ____/________ __ ______
|
||||||
|
// / / __/ ___/ __ \/ / / / __ \
|
||||||
|
// / /_/ / / / /_/ / /_/ / /_/ /
|
||||||
|
// \____/_/ \____/\__,_/ .___/
|
||||||
|
// /_/
|
||||||
|
protected function addGroup(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
|
||||||
|
|
||||||
|
$registry->addFieldResolver('Query', 'allgroups',
|
||||||
|
$builder->compose(
|
||||||
|
$builder->callback(function($parent, $arg){
|
||||||
|
$entity_storage = \Drupal::entityTypeManager()->getStorage('group');
|
||||||
|
$query = $entity_storage->getQuery()
|
||||||
|
// ->condition('type', ['static'], 'IN')
|
||||||
|
->accessCheck(TRUE);
|
||||||
|
$results = $query->execute();
|
||||||
|
return $results;
|
||||||
|
}),
|
||||||
|
$builder->produce('entity_load_multiple')
|
||||||
|
->map('type', $builder->fromValue('group'))
|
||||||
|
->map('ids', $builder->fromParent())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$registry->addFieldResolver('Query', 'groups',
|
||||||
|
$builder->produce('entity_load_multiple')
|
||||||
|
->map('type', $builder->fromValue('group'))
|
||||||
|
->map('ids', $builder->fromArgument('ids'))
|
||||||
|
);
|
||||||
|
|
||||||
|
$registry->addFieldResolver('Query', 'group',
|
||||||
|
$builder->produce('entity_load')
|
||||||
|
->map('type', $builder->fromValue('group'))
|
||||||
|
// ->map('bundles', $builder->fromValue(['static']))
|
||||||
|
->map('id', $builder->fromArgument('id'))
|
||||||
|
);
|
||||||
|
|
||||||
|
$registry->addFieldResolver('Group', 'id',
|
||||||
|
$builder->produce('entity_id')
|
||||||
|
->map('entity', $builder->fromParent())
|
||||||
|
);
|
||||||
|
|
||||||
|
$registry->addFieldResolver('Group', 'uuid',
|
||||||
|
$builder->produce('entity_uuid')
|
||||||
|
->map('entity', $builder->fromParent())
|
||||||
|
);
|
||||||
|
|
||||||
|
$registry->addFieldResolver('Group', 'name',
|
||||||
|
$builder->compose(
|
||||||
|
$builder->produce('entity_label')
|
||||||
|
->map('entity', $builder->fromParent())
|
||||||
|
));
|
||||||
|
|
||||||
|
$registry->addFieldResolver('Group', 'description',
|
||||||
|
$builder->produce('property_path')
|
||||||
|
->map('type', $builder->fromValue('entity:node'))
|
||||||
|
->map('value', $builder->fromParent())
|
||||||
|
->map('path', $builder->fromValue('field_description.value'))
|
||||||
|
);
|
||||||
|
|
||||||
|
$registry->addFieldResolver('Group', 'path',
|
||||||
|
$builder->compose(
|
||||||
|
$builder->produce('entity_url')
|
||||||
|
->map('entity', $builder->fromParent()),
|
||||||
|
$builder->produce('url_path')
|
||||||
|
->map('url', $builder->fromParent())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$registry->addFieldResolver('Group', 'owner',
|
||||||
|
$builder->produce('entity_owner')
|
||||||
|
->map('entity', $builder->fromParent())
|
||||||
|
);
|
||||||
|
|
||||||
|
$registry->addFieldResolver('Group', 'members',
|
||||||
|
$builder->compose(
|
||||||
|
$builder->callback(function ($parent, $args) {
|
||||||
|
$memberships = $parent->getMembers();
|
||||||
|
$users = [];
|
||||||
|
foreach ($memberships as $member) {
|
||||||
|
$users[] = $member->getUser();
|
||||||
|
}
|
||||||
|
return $users;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// // GroupMembers
|
||||||
|
// $registry->addFieldResolver('GroupMember', 'id',
|
||||||
|
// $builder->produce('entity_id')
|
||||||
|
// ->map('entity', $builder->fromParent())
|
||||||
|
// );
|
||||||
|
|
||||||
|
// $registry->addFieldResolver('GroupMember', 'user',
|
||||||
|
// $builder->produce('entity_id')
|
||||||
|
// ->map('entity', $builder->fromParent())
|
||||||
|
// );
|
||||||
|
}
|
||||||
|
|
||||||
|
// __ __
|
||||||
|
// / / / /_______ _____
|
||||||
|
// / / / / ___/ _ \/ ___/
|
||||||
|
// / /_/ (__ ) __/ /
|
||||||
|
// \____/____/\___/_/
|
||||||
|
protected function addUser(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
|
||||||
|
|
||||||
|
$registry->addFieldResolver('User', 'id',
|
||||||
|
$builder->produce('entity_id')
|
||||||
|
->map('entity', $builder->fromParent())
|
||||||
|
);
|
||||||
|
|
||||||
|
$registry->addFieldResolver('User', 'email',
|
||||||
|
$builder->produce('property_path')
|
||||||
|
->map('type', $builder->fromValue('entity:user'))
|
||||||
|
->map('value', $builder->fromParent())
|
||||||
|
->map('path', $builder->fromValue('mail.value'))
|
||||||
|
);
|
||||||
|
|
||||||
|
$registry->addFieldResolver('User', 'username',
|
||||||
|
$builder->produce('property_path')
|
||||||
|
->map('type', $builder->fromValue('entity:user'))
|
||||||
|
->map('value', $builder->fromParent())
|
||||||
|
->map('path', $builder->fromValue('name.value'))
|
||||||
|
);
|
||||||
|
|
||||||
|
$registry->addFieldResolver('User', 'roles',
|
||||||
|
$builder->callback(function ($parent, $args) {
|
||||||
|
return $roles_ids = $parent->getRoles();
|
||||||
|
// $entity_storage = \Drupal::entityTypeManager()->getStorage('user_role');
|
||||||
|
// $roles = $entity_storage->loadMultiple($roles_ids);
|
||||||
|
// return $roles;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
// ROLE
|
||||||
|
// type Role {
|
||||||
|
// name: String!
|
||||||
|
// }
|
||||||
|
// $registry->addFieldResolver('Role', 'name',
|
||||||
|
// $builder->produce('entity_label')
|
||||||
|
// ->map('entity', $builder->fromParent())
|
||||||
|
// );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// ___ _
|
// ___ _
|
||||||
// | \ __ _| |_ ___
|
// | \ __ _| |_ ___
|
||||||
// | |) / _` | _/ -_)
|
// | |) / _` | _/ -_)
|
||||||
|
|
Loading…
Reference in New Issue