# STEP-7 GraphQL types, Helpers

[**STEP-7**](https://github.com/GAkim/SocialShareGraphQl/tree/STEP-7)

{% embed url="<https://www.youtube.com/watch?v=lRj6fDwyuGs>" %}

1. First of all, we going to modify our **schema.graphqls** to gain an understanding of our data structure

{% code title="ScandiPWA/SocialShareGraphQl/etc/schema.graphqls" %}

```graphql
type Query {
   socialShare: socialShareType @resolver(class:"\\ScandiPWA\\SocialShareGraphQl\\Model\\Resolver\\SocialShare")
}

type socialShareType {
   socialShareConfig: socialShareConfig
   providers: [ socialShareProvider ]
}

type socialShareConfig {
   enabled: Boolean
   rounded: Boolean
   size: String
   categoryPage: Boolean
   productPage: Boolean
   homePage: Boolean
}

type socialShareProvider {
   id: String
   counter: Boolean
   additional: String
}

```

{% endcode %}

Ok now we know how our data structure will look like, then we going to pass data through graphql, will create a Helper which will provide socialShareConfig and providers and map all fields.\
&#x20;2\. Create **Helper** folder in **\<MODULE ROOT>** and **DataProvider.php** in it

{% code title="ScandiPWA/SocialShareGraphQl/Helper/DataProvider.php" %}

```php
<?php
declare(strict_types=1);

namespace ScandiPWA\SocialShareGraphQl\Helper;

use Magento\Framework\App\Config\ScopeConfigInterface;
/**
* @package ScandiPWA\SocialShareGraphQl\Helper
*/
class DataProvider
{
   const SOCIALSHARE_CONFIG = 'socialshare/general/';

   const SOCIALSHARE = 'socialshare/';

   const ENABLE = 'enable';

   const ROUNDED = 'rounded';

   const SIZE = 'size';

   const HOME_PAGE = 'home_page';

   const CATEGORY_PAGE = 'category_page';

   const PRODUCT_PAGE = 'product_page';

   const COUNTER = 'enable_counter';

   const SUFFIX = 'suffix';

   const APP_ID = 'app_id';

   const FB_MSG = 'facebook_messenger';

   const EMAIL = 'email';

   const PROVIDERS = [
       'facebook',
       'facebook_messenger',
       'telegram',
       'whatsapp',
       'linkedin',
       'email',
   ];

   /**
    * @var ScopeConfigInterface
    */
   protected $scopeConfig;

   /**
    * DataProvider constructor.
    * @param ScopeConfigInterface $scopeConfig
    */
   public function __construct(
       ScopeConfigInterface $scopeConfig
   ) {
       $this->scopeConfig = $scopeConfig;
   }

   /**
    * @return array
    */
   public function getSocialShareConfig() {

       return [
           'enabled' => $this->getConfig(self::SOCIALSHARE_CONFIG. self::ENABLE),
           'rounded' => $this->getConfig(self::SOCIALSHARE_CONFIG. self::ROUNDED),
           'size' => $this->getConfig(self::SOCIALSHARE_CONFIG. self::SIZE),
           'categoryPage' => $this->getConfig(self::SOCIALSHARE_CONFIG. self::CATEGORY_PAGE),
           'productPage' => $this->getConfig(self::SOCIALSHARE_CONFIG. self::PRODUCT_PAGE),
           'homePage' => $this->getConfig(self::SOCIALSHARE_CONFIG. self::HOME_PAGE)
       ];
   }

   /**
    * @return array
    */
   public function getSocialShareProviders() {
       $result = [];

       foreach (self::PROVIDERS as $provider) {
           $data = [];

           switch ($provider) {
               case self::FB_MSG:
                   $data = $this->getFacebookMessengerData();
                   break;
               case self::EMAIL:
                   $data = $this->getEmailData();
                   break;
               default:
                   $data = $this->getData($provider);
           }

           if($data) {
               array_push($result, $data);
           }
       }

       return $result;
   }

   /**
    * @return array|false
    */
   protected function getFacebookMessengerData() {
       $enabled = $this->getProviderConfig(self::FB_MSG, self::ENABLE);

       if($enabled) {
           return [
               'id' => self::FB_MSG,
               'additional' => $this->getProviderConfig(self::FB_MSG, self::APP_ID)
           ];
       }

       return false;
   }

   /**
    * @param $provider
    * @return array|false
    */
   protected function getData($provider) {
       $enabled = $this->getProviderConfig($provider, self::ENABLE);

       if($enabled) {
           return [
               'id' => $provider,
               'counter' => $this->getProviderConfig($provider, self::COUNTER)
           ];
       }

       return false;
   }

   /**
    * @return array|false
    */
   protected function getEmailData() {
       $enabled = $this->getProviderConfig(self::EMAIL, self::ENABLE);

       if($enabled) {
           return [
               'id' => self::EMAIL,
               'additional' => $this->getProviderConfig(self::EMAIL, self::SUFFIX)
           ];
       }

       return false;
   }

   /**
    * @param $path
    * @return mixed
    */
   protected function getConfig($path) {
        return $this->scopeConfig->getValue($path);
   }

   /**
    * @param $provider
    * @param $config
    * @return mixed
    */
   protected function getProviderConfig($provider, $config) {
       return $this->scopeConfig->getValue(self::SOCIALSHARE. $provider. '/'. $config);
   }
}

```

{% endcode %}

3\. Now we going to modify our resolver and request data from **DataProvider**

{% code title="ScandiPWA/SocialShareGraphQl/Model/Resolver/SocialShare.php" %}

```php
<?php

declare(strict_types=1);

namespace ScandiPWA\SocialShareGraphQl\Model\Resolver;

use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use ScandiPWA\SocialShareGraphQl\Helper\DataProvider;

/**
* @package ScandiPWA\SocialShareGraphQl\Model\Resolver
*/
class SocialShare implements ResolverInterface
{
   /**
    * @var DataProvider
    */
   protected $dataProvider;

   /**
    * SocialShare constructor.
    * @param DataProvider $dataProvider
    */
   public function __construct(
       DataProvider $dataProvider
   ) {
       $this->dataProvider = $dataProvider;
   }
   /**
    * @param Field $field
    * @param ContextInterface $context
    * @param ResolveInfo $info
    * @param array|null $value
    * @param array|null $args
    * @return string[]
    */
   public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
   {
       $result = [
           'socialShareConfig' => $this->dataProvider->getSocialShareConfig(),
           'providers' => $this->dataProvider->getSocialShareProviders()
       ];

       return $result;
   }
}

```

{% endcode %}

4\. Now again using  [**Altair GraphQL Client**](https://chrome.google.com/webstore/detail/altair-graphql-client/flnheeellpciglgpaodhkhmapeljopja/related?utm_source=chrome-ntp-icon) we going to check if we did everything right

![](https://lh5.googleusercontent.com/cYfSnrx8mjvr8rRAi6DVcLm5fEMvp56WHjmIppYhRTqEyicTj2z3OsvvsUqsVHF8Ha5bpKwss93bz6jOUD8ReUJKPYszpSF3OjFo6RiRlSQY_Tu-KfVe1szx5m5R3-1996twoiK1)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.scandipwa.com/tutorials/scandipwa-social-share/step-7-graphql-types-helpers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
