com.adobe.cq.commerce.magento.graphql.Query Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of magento-graphql Show documentation
Show all versions of magento-graphql Show documentation
AEM bundle for the Magento GraphQL data models and query builders
/*******************************************************************************
*
* Copyright 2019 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
******************************************************************************/
package com.adobe.cq.commerce.magento.graphql;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.shopify.graphql.support.AbstractResponse;
import com.shopify.graphql.support.SchemaViolationError;
/**
*
*/
public class Query extends AbstractResponse {
public Query() {
}
public Query(JsonObject fields) throws SchemaViolationError {
for (Map.Entry field : fields.entrySet()) {
String key = field.getKey();
String fieldName = getFieldName(key);
switch (fieldName) {
case "category": {
CategoryTree optional1 = null;
if (!field.getValue().isJsonNull()) {
optional1 = new CategoryTree(jsonAsObject(field.getValue(), key));
}
responseData.put(key, optional1);
break;
}
case "cmsBlocks": {
CmsBlocks optional1 = null;
if (!field.getValue().isJsonNull()) {
optional1 = new CmsBlocks(jsonAsObject(field.getValue(), key));
}
responseData.put(key, optional1);
break;
}
case "cmsPage": {
CmsPage optional1 = null;
if (!field.getValue().isJsonNull()) {
optional1 = new CmsPage(jsonAsObject(field.getValue(), key));
}
responseData.put(key, optional1);
break;
}
case "countries": {
List optional1 = null;
if (!field.getValue().isJsonNull()) {
List list1 = new ArrayList<>();
for (JsonElement element1 : jsonAsArray(field.getValue(), key)) {
Country optional2 = null;
if (!element1.isJsonNull()) {
optional2 = new Country(jsonAsObject(element1, key));
}
list1.add(optional2);
}
optional1 = list1;
}
responseData.put(key, optional1);
break;
}
case "country": {
Country optional1 = null;
if (!field.getValue().isJsonNull()) {
optional1 = new Country(jsonAsObject(field.getValue(), key));
}
responseData.put(key, optional1);
break;
}
case "currency": {
Currency optional1 = null;
if (!field.getValue().isJsonNull()) {
optional1 = new Currency(jsonAsObject(field.getValue(), key));
}
responseData.put(key, optional1);
break;
}
case "customAttributeMetadata": {
CustomAttributeMetadata optional1 = null;
if (!field.getValue().isJsonNull()) {
optional1 = new CustomAttributeMetadata(jsonAsObject(field.getValue(), key));
}
responseData.put(key, optional1);
break;
}
case "customer": {
Customer optional1 = null;
if (!field.getValue().isJsonNull()) {
optional1 = new Customer(jsonAsObject(field.getValue(), key));
}
responseData.put(key, optional1);
break;
}
case "customerDownloadableProducts": {
CustomerDownloadableProducts optional1 = null;
if (!field.getValue().isJsonNull()) {
optional1 = new CustomerDownloadableProducts(jsonAsObject(field.getValue(), key));
}
responseData.put(key, optional1);
break;
}
case "customerOrders": {
CustomerOrders optional1 = null;
if (!field.getValue().isJsonNull()) {
optional1 = new CustomerOrders(jsonAsObject(field.getValue(), key));
}
responseData.put(key, optional1);
break;
}
case "products": {
Products optional1 = null;
if (!field.getValue().isJsonNull()) {
optional1 = new Products(jsonAsObject(field.getValue(), key));
}
responseData.put(key, optional1);
break;
}
case "storeConfig": {
StoreConfig optional1 = null;
if (!field.getValue().isJsonNull()) {
optional1 = new StoreConfig(jsonAsObject(field.getValue(), key));
}
responseData.put(key, optional1);
break;
}
case "urlResolver": {
EntityUrl optional1 = null;
if (!field.getValue().isJsonNull()) {
optional1 = new EntityUrl(jsonAsObject(field.getValue(), key));
}
responseData.put(key, optional1);
break;
}
case "wishlist": {
WishlistOutput optional1 = null;
if (!field.getValue().isJsonNull()) {
optional1 = new WishlistOutput(jsonAsObject(field.getValue(), key));
}
responseData.put(key, optional1);
break;
}
case "__typename": {
responseData.put(key, jsonAsString(field.getValue(), key));
break;
}
default: {
throw new SchemaViolationError(this, key, field.getValue());
}
}
}
}
public String getGraphQlTypeName() {
return "Query";
}
public CategoryTree getCategory() {
return (CategoryTree) get("category");
}
public Query setCategory(CategoryTree arg) {
optimisticData.put(getKey("category"), arg);
return this;
}
/**
* The CMS block query returns information about CMS blocks
*/
public CmsBlocks getCmsBlocks() {
return (CmsBlocks) get("cmsBlocks");
}
public Query setCmsBlocks(CmsBlocks arg) {
optimisticData.put(getKey("cmsBlocks"), arg);
return this;
}
/**
* The CMS page query returns information about a CMS page
*/
public CmsPage getCmsPage() {
return (CmsPage) get("cmsPage");
}
public Query setCmsPage(CmsPage arg) {
optimisticData.put(getKey("cmsPage"), arg);
return this;
}
/**
* The countries query provides information for all countries.
*/
public List getCountries() {
return (List) get("countries");
}
public Query setCountries(List arg) {
optimisticData.put(getKey("countries"), arg);
return this;
}
/**
* The countries query provides information for a single country.
*/
public Country getCountry() {
return (Country) get("country");
}
public Query setCountry(Country arg) {
optimisticData.put(getKey("country"), arg);
return this;
}
/**
* The currency query returns information about store currency.
*/
public Currency getCurrency() {
return (Currency) get("currency");
}
public Query setCurrency(Currency arg) {
optimisticData.put(getKey("currency"), arg);
return this;
}
/**
* The customAttributeMetadata query returns the attribute type, given an attribute code and entity
* type
*/
public CustomAttributeMetadata getCustomAttributeMetadata() {
return (CustomAttributeMetadata) get("customAttributeMetadata");
}
public Query setCustomAttributeMetadata(CustomAttributeMetadata arg) {
optimisticData.put(getKey("customAttributeMetadata"), arg);
return this;
}
/**
* The customer query returns information about a customer account
*/
public Customer getCustomer() {
return (Customer) get("customer");
}
public Query setCustomer(Customer arg) {
optimisticData.put(getKey("customer"), arg);
return this;
}
/**
* The query returns the contents of a customer's downloadable products
*/
public CustomerDownloadableProducts getCustomerDownloadableProducts() {
return (CustomerDownloadableProducts) get("customerDownloadableProducts");
}
public Query setCustomerDownloadableProducts(CustomerDownloadableProducts arg) {
optimisticData.put(getKey("customerDownloadableProducts"), arg);
return this;
}
/**
* List of customer orders
*/
public CustomerOrders getCustomerOrders() {
return (CustomerOrders) get("customerOrders");
}
public Query setCustomerOrders(CustomerOrders arg) {
optimisticData.put(getKey("customerOrders"), arg);
return this;
}
/**
* The products query searches for products that match the criteria specified in the search and filter
* attributes
*/
public Products getProducts() {
return (Products) get("products");
}
public Query setProducts(Products arg) {
optimisticData.put(getKey("products"), arg);
return this;
}
/**
* The store config query
*/
public StoreConfig getStoreConfig() {
return (StoreConfig) get("storeConfig");
}
public Query setStoreConfig(StoreConfig arg) {
optimisticData.put(getKey("storeConfig"), arg);
return this;
}
/**
* The urlResolver query returns the relative URL for a specified product, category or CMS page
*/
public EntityUrl getUrlResolver() {
return (EntityUrl) get("urlResolver");
}
public Query setUrlResolver(EntityUrl arg) {
optimisticData.put(getKey("urlResolver"), arg);
return this;
}
/**
* The wishlist query returns the contents of a customer's wish list
*/
public WishlistOutput getWishlist() {
return (WishlistOutput) get("wishlist");
}
public Query setWishlist(WishlistOutput arg) {
optimisticData.put(getKey("wishlist"), arg);
return this;
}
public boolean unwrapsToObject(String key) {
switch (getFieldName(key)) {
case "category": return true;
case "cmsBlocks": return true;
case "cmsPage": return true;
case "countries": return true;
case "country": return true;
case "currency": return true;
case "customAttributeMetadata": return true;
case "customer": return true;
case "customerDownloadableProducts": return true;
case "customerOrders": return true;
case "products": return true;
case "storeConfig": return true;
case "urlResolver": return true;
case "wishlist": return true;
default: return false;
}
}
}