diff --git a/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.base.graphqls b/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.base.graphqls index ed33131..04b96d0 100644 --- a/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.base.graphqls +++ b/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.base.graphqls @@ -47,6 +47,32 @@ type Static implements NodeInterface { 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 { file: File! description: String diff --git a/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.extension.graphqls b/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.extension.graphqls index 2df9c2a..39c5aac 100644 --- a/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.extension.graphqls +++ b/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.extension.graphqls @@ -39,10 +39,14 @@ extend type Query { static(id: Int!): Static } -# extend type Query { -# alltags: [Taxoterm] -# } +extend type Query { + allgroups: [Group] +} -# extend type Query { -# tag(id: Int!): Taxoterm -# } +extend type Query { + groups(ids: [Int]): [Group] +} + +extend type Query { + group(id: Int!): Group +} diff --git a/src/web/modules/custom/ouatt_graphql/src/Plugin/GraphQL/SchemaExtension/OuattSchemaExtension.php b/src/web/modules/custom/ouatt_graphql/src/Plugin/GraphQL/SchemaExtension/OuattSchemaExtension.php index 811ca46..4ea92bc 100644 --- a/src/web/modules/custom/ouatt_graphql/src/Plugin/GraphQL/SchemaExtension/OuattSchemaExtension.php +++ b/src/web/modules/custom/ouatt_graphql/src/Plugin/GraphQL/SchemaExtension/OuattSchemaExtension.php @@ -36,6 +36,10 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase { $this->addEntites($registry, $builder); // $this->addStatic($registry, $builder); + // + $this->addGroup($registry, $builder); + // + $this->addUser($registry, $builder); // $this->addFilefield($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()) + // ); + + } + // ___ _ // | \ __ _| |_ ___ // | |) / _` | _/ -_)