Class MagentoGraphqlClient


  • public class MagentoGraphqlClient
    extends Object
    This is a wrapper class for GraphqlClient. The constructor adapts a Resource to the GraphqlClient class and also looks for the magentoStore property on the resource path in order to set the Magento Store HTTP header. This wrapper also sets the custom Magento Gson deserializer from QueryDeserializer.
    • Method Detail

      • create

        @Deprecated
        public static MagentoGraphqlClient create​(org.apache.sling.api.resource.Resource resource)
        Deprecated.
        Use create(Resource, Page, SlingHttpServletRequest) to be able to use the Timewarp feature to preview staged data.
        Instantiates and returns a new MagentoGraphqlClient. This method returns null if the client cannot be instantiated.

        Important: components defined in a page template should use create(Resource, Page) so the page can be used to adapt to the lower-level GraphqlClient, while the component resource can be used for caching purposes.
        Parameters:
        resource - The JCR resource to use to adapt to the lower-level GraphqlClient. This is used for caching purposes, where the resource type is used as the cache key.
        Returns:
        A new MagentoGraphqlClient instance.
      • create

        @Deprecated
        public static MagentoGraphqlClient create​(org.apache.sling.api.resource.Resource resource,
                                                  com.day.cq.wcm.api.Page page)
        Deprecated.
        Use create(Resource, Page, SlingHttpServletRequest) to be able to use the Timewarp feature to preview staged data.
        Instantiates and returns a new MagentoGraphqlClient. This method returns null if the client cannot be instantiated.
        Parameters:
        resource - The JCR resource of the component being rendered. This is used for caching purposes, where the resource type is used as the cache key. An OSGi service should pass a synthetic resource, where the resource type should be set to the fully-qualified class name of the service.
        page - The current AEM page. This is used to adapt to the lower-level GraphqlClient. This is needed because it is not possible to get the current page for components added to the page template. If null, the resource will be used to adapt to the client, but this might fail for components defined on page templates.
        Returns:
        A new MagentoGraphqlClient instance.
      • create

        public static MagentoGraphqlClient create​(org.apache.sling.api.resource.Resource resource,
                                                  com.day.cq.wcm.api.Page page,
                                                  org.apache.sling.api.SlingHttpServletRequest request)
        Instantiates and returns a new MagentoGraphqlClient. This method returns null if the client cannot be instantiated.
        Parameters:
        resource - The JCR resource of the component being rendered. This is used for caching purposes, where the resource type is used as the cache key. An OSGi service should pass a synthetic resource, where the resource type should be set to the fully-qualified class name of the service.
        page - The current AEM page. This is used to adapt to the lower-level GraphqlClient. This is needed because it is not possible to get the current page for components added to the page template. If null, the resource will be used to adapt to the client, but this might fail for components defined on page templates.
        request - The current AEM Sling HTTP request. This is used to extract a possible TimeWarp timestamp from the request. If set and in the future, the client will use the TimeWarp timestamp to set Magento's Preview-Version header.
        Returns:
        A new MagentoGraphqlClient instance.
      • execute

        public com.adobe.cq.commerce.graphql.client.GraphqlResponse<com.adobe.cq.commerce.magento.graphql.Query,​com.adobe.cq.commerce.magento.graphql.gson.Error> execute​(String query)
        Executes the given Magento query and returns the response. This method will use the default HTTP method defined in the OSGi configuration of the underlying GraphqlClient. Use execute(String, HttpMethod) if you want to specify the HTTP method yourself.
        Parameters:
        query - The GraphQL query.
        Returns:
        The GraphQL response.
      • execute

        public com.adobe.cq.commerce.graphql.client.GraphqlResponse<com.adobe.cq.commerce.magento.graphql.Query,​com.adobe.cq.commerce.magento.graphql.gson.Error> execute​(String query,
                                                                                                                                                                                com.adobe.cq.commerce.graphql.client.HttpMethod httpMethod)
        Executes the given Magento query and returns the response. This method uses the given httpMethod to fetch the data.
        Parameters:
        query - The GraphQL query.
        httpMethod - The HTTP method that will be used to fetch the data.
        Returns:
        The GraphQL response.
      • getConfiguration

        public com.adobe.cq.commerce.graphql.client.GraphqlClientConfiguration getConfiguration()
        Returns the complete configuration of the GraphQL client.
        Returns:
        GraphQL client configuration.