Class MagentoGraphqlClient
- java.lang.Object
-
- com.adobe.cq.commerce.core.components.client.MagentoGraphqlClient
-
public class MagentoGraphqlClient extends Object
This is a wrapper class forGraphqlClient
. The constructor adapts aResource
to the GraphqlClient class and also looks for themagentoStore
property on the resource path in order to set the MagentoStore
HTTP header. This wrapper also sets the custom Magento Gson deserializer fromQueryDeserializer
.
-
-
Field Summary
Fields Modifier and Type Field Description static String
CONFIGURATION_NAME
static String
STORE_CODE_PROPERTY
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static MagentoGraphqlClient
create(org.apache.sling.api.resource.Resource resource)
Deprecated.Usecreate(Resource, Page, SlingHttpServletRequest)
to be able to use the Timewarp feature to preview staged data.static MagentoGraphqlClient
create(org.apache.sling.api.resource.Resource resource, com.day.cq.wcm.api.Page page)
Deprecated.Usecreate(Resource, Page, SlingHttpServletRequest)
to be able to use the Timewarp feature to preview staged data.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.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.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.com.adobe.cq.commerce.graphql.client.GraphqlClientConfiguration
getConfiguration()
Returns the complete configuration of the GraphQL client.
-
-
-
Field Detail
-
STORE_CODE_PROPERTY
public static final String STORE_CODE_PROPERTY
- See Also:
- Constant Field Values
-
CONFIGURATION_NAME
public static final String CONFIGURATION_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
create
@Deprecated public static MagentoGraphqlClient create(org.apache.sling.api.resource.Resource resource)
Deprecated.Usecreate(Resource, Page, SlingHttpServletRequest)
to be able to use the Timewarp feature to preview staged data.Instantiates and returns a new MagentoGraphqlClient. This method returnsnull
if the client cannot be instantiated.
Important: components defined in a page template should usecreate(Resource, Page)
so the page can be used to adapt to the lower-levelGraphqlClient
, while the component resource can be used for caching purposes.- Parameters:
resource
- The JCR resource to use to adapt to the lower-levelGraphqlClient
. 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.Usecreate(Resource, Page, SlingHttpServletRequest)
to be able to use the Timewarp feature to preview staged data.Instantiates and returns a new MagentoGraphqlClient. This method returnsnull
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-levelGraphqlClient
. 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 returnsnull
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-levelGraphqlClient
. 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 underlyingGraphqlClient
. Useexecute(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 givenhttpMethod
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.
-
-