Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

GraphQL API

givanzfc89580ab740
diff --git a/config/graphql-routes.php b/config/graphql-routes.php
new file mode 100644
index 0000000..7f6c734
--- /dev/null
+++ b/config/graphql-routes.php
@@ -0,0 +1,27 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+return [
+ '/' => ['module' => 'index'],
+ '/graphql' => ['module' => 'index'],
+ '/graphql/schema' => ['module' => 'schema/index'],
+];
diff --git a/config/graphql.php b/config/graphql.php
new file mode 100644
index 0000000..d658246
--- /dev/null
+++ b/config/graphql.php
@@ -0,0 +1,41 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+ return [
+ 'auth' => [
+ 'mode' => 'http',
+ ],
+ 'session' => [
+ 'driver' => 'request',,//stateless, handle session externally if needed. Change to php for session management if php session cookie can be sent with the request.
+ ],
+ 'email' => [
+ 'driver' => 'mail',
+ ],
+ 'cache' => [
+ 'driver' => 'file',
+ 'servers' => [
+ ],
+ 'options' => [
+ ],
+ ],
+ 'key' => 'Q8qJ6CVpUW4msSM8pHmdGwyXIkSvT6Lo',
+ ];
diff --git a/graphql/controller/base.php b/graphql/controller/base.php
new file mode 100644
index 0000000..ddffd0c
--- /dev/null
+++ b/graphql/controller/base.php
@@ -0,0 +1,135 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Vvveb\Controller;
+
+use \Vvveb\System\Core\FrontController;
+use function Vvveb\__;
+use function Vvveb\config;
+use function Vvveb\siteSettings;
+use Vvveb\System\Core\Request;
+use Vvveb\System\Core\Response;
+use Vvveb\System\Event;
+use Vvveb\System\Extensions\Plugins;
+use Vvveb\System\Session;
+use Vvveb\System\Traits\Permission;
+use Vvveb\System\User\Admin;
+
+#[\AllowDynamicProperties]
+class Base {
+ use Permission;
+
+ protected $global = [];
+
+ function auth() {
+ $admin = Admin::current();
+
+ if (! $admin) {
+ $authMode = config(APP . '.auth.mode');
+
+ if ($authMode == 'http') {
+ if (isset($_SERVER['PHP_AUTH_USER'])) {
+ $user = $_SERVER['PHP_AUTH_USER'];
+ $password = $_SERVER['PHP_AUTH_PW'] ?? '';
+ $loginData = compact('user', 'password');
+
+ if ($userInfo = Admin::login($loginData)) {
+ } else {
+ $this->response->addHeader('WWW-Authenticate', 'Basic realm="REST Api"');
+ $this->response->addHeader('HTTP/1.0 401 Unauthorized');
+ FrontController::notFound(false, __('Auth failed!'), 403);
+ }
+ } else {
+ $this->response->addHeader('WWW-Authenticate', 'Basic realm="REST Api"');
+ $this->response->addHeader('HTTP/1.0 401 Unauthorized');
+ FrontController::notFound(false, __('Auth failed!'), 403);
+ }
+ }
+ }
+ }
+
+ protected function initEcommerce($countryId, $regionId) {
+ $tax = \Vvveb\System\Cart\Tax::getInstance();
+ $tax->setRegionRules($countryId, $regionId, 'store');
+ }
+
+ function init() {
+ $this->response = Response::getInstance();
+ $this->request = Request::getInstance();
+ $this->session = Session::getInstance();
+
+ $this->response->setType('json');
+
+ if (! GRAPHQL) {
+ die($this->notFound(__('GRAPHQL is disabled!'), 404));
+ }
+
+ $this->auth();
+
+ $method = $this->request->getMethod();
+
+ Plugins :: loadPlugins();
+ $site = siteSettings();
+
+ list($site) = Event::trigger(__CLASS__, __FUNCTION__, $site);
+
+ $this->global['site_id'] = SITE_ID ?? 1;
+ $this->global['language_id'] = $this->session->get('language_id') ?? $site['language_id'] ?? 1;
+ $this->global['default_language_id'] = $this->session->get('default_language_id') ?? $site['language_id'] ?? 1;
+ $this->global['limit'] = 10;
+ $this->global['start'] = 0;
+ $this->global['user_id'] = $user['user_id'] ?? false;
+ $this->global['user_group_id'] = $user['user_group_id'] ?? 1;
+ $this->global['site'] = &$site;
+ $this->global['user'] = $user ?? [];
+
+ $language_id = $this->global['language_id'];
+
+ if (isset($site['description'][$language_id])) {
+ $site['description'] = $site['description'][$language_id];
+ }
+
+ if (isset($site['country_id'])) {
+ $this->initEcommerce($site['country_id'], $site['region_id']);
+ }
+
+ $this->global['site'] = &$site;
+
+ list($this->global) = Event::trigger(__CLASS__, __FUNCTION__ . ':after', $this->global);
+ }
+
+ /**
+ * Call this function if the requeste information was not found, for example if the specifed news, image, profile etc is not found then call this function.
+ * It shows a "Not found" page and it also send 404 http status code, this is usefull for search engines etc.
+ *
+ * @param unknown_type $code
+ * @param mixed $service
+ * @param mixed $statusCode
+ * @param null|mixed $message
+ */
+ protected function notFound($message = null, $statusCode = 404, $service = false) {
+ $response = Response::getInstance();
+ http_response_code($statusCode);
+
+ return $response->output(['errors' => is_array($message) ? $message : ['message' => $message]]);
+ }
+}
diff --git a/graphql/controller/cart.php b/graphql/controller/cart.php
new file mode 100644
index 0000000..3a0a7b6
--- /dev/null
+++ b/graphql/controller/cart.php
@@ -0,0 +1,149 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Vvveb\Controller;
+
+include DIR_ROOT . 'app' . DS . 'controller' . DS . 'cart' . DS . 'coupon-trait.php';
+
+use Vvveb\System\Cart\Cart as ShoppingCart;
+use Vvveb\System\Payment;
+use Vvveb\System\Shipping;
+
+class Cart extends Base {
+// use CartTrait;
+ use Cart\CouponTrait;
+
+ private $cart;
+
+ private $payment;
+
+ private $shipping;
+
+ private function cart($cart_id = null) {
+ $this->init();
+
+ $options = array_intersect_key($this->global['site'],
+ array_flip(['weight_type_id', 'length_type_id', 'currency_id', 'country_id']));
+
+ $options['cart_id'] = $cart_id;
+
+ $this->cart = ShoppingCart::getInstance($this->global + $options);
+ }
+
+ function index($args) {
+ $cart_id = $args['cart_id'] ?? null;
+
+ if (! $this->cart) {
+ $this->cart($cart_id);
+ }
+
+ $payment = Payment::getInstance();
+ $shipping = Shipping::getInstance();
+
+ $this->payment = $payment->getMethods([]);
+ $this->shipping = $shipping->getMethods([]);
+
+ $cart = [
+ 'cart_id' => $this->cart->getId(),
+ 'encrypted_cart_id' => $this->cart->getEncryptedId(),
+ 'products' => $this->cart->getAll(),
+ 'totals' => $this->cart->getTotals(),
+ 'total_items' => $this->cart->getNoProducts(),
+ 'total_weight' => $this->cart->getWeight(),
+ 'total_price' => $this->cart->getGrandTotal(),
+ 'total' => $this->cart->getGrandTotal(),
+ 'total_tax' => $this->cart->getTaxTotal(),
+ 'coupons' => $this->cart->getCoupons(),
+ 'total_formatted' => $this->cart->getGrandTotalFormatted(),
+ 'checkout_url' => $this->cart->getCheckoutUrl(),
+ 'weight_unit' => $this->global['site']['weight_type'],
+ 'length_unit' => $this->global['site']['length_type'],
+ ];
+
+ return $cart;
+ }
+
+ function add($args) {
+ $cart_id = $args['cart_id'] ?? null;
+
+ if (! $this->cart) {
+ $this->cart($cart_id);
+ }
+
+ $productId = $args['product_id'] ?? false;
+ $quantity = $args['quantity'] ?? 1;
+ $options = $args['options'] ?? [];
+ $subscriptionPlanId = $args['subscription_plan_id'] ?? false;
+ $productVariantId = $args['product_variant_id'] ?? false;
+
+ if ($productId) {
+ if ($options && is_string($options)) {
+ if ($options[0] != '{') {
+ $options = '{' . $options . '}';
+ }
+ $options = json_decode($options, true);
+ }
+ $this->cart->add($productId, $quantity, $options, $productVariantId, $subscriptionPlanId);
+
+ return $this->index($args);
+ }
+ }
+
+ function create($args) {
+ if (! $this->cart) {
+ $this->cart();
+ $args['cart_id'] = $this->cart->create();
+ }
+
+ $cart = $this->index($args);
+
+ return $cart;
+ }
+
+ function update($args) {
+ $cart_id = $args['cart_id'] ?? null;
+
+ if (! $this->cart) {
+ $this->cart($cart_id);
+ }
+
+ if (($key = ($args['key'] ?? $args['product_id'] ?? false)) && ($quantity = ($args['quantity'] ?? false))) {
+ $this->cart->update($key, $quantity);
+
+ return $this->index($args);
+ }
+ }
+
+ function remove($args) {
+ $cart_id = $args['cart_id'] ?? null;
+
+ if (! $this->cart) {
+ $this->cart($cart_id);
+ }
+
+ if ($key = ($args['key'] ?? $args['product_id'] ?? false)) {
+ $this->cart->remove($key);
+
+ return $this->index($args);
+ }
+ }
+}
diff --git a/graphql/controller/error403.php b/graphql/controller/error403.php
new file mode 100644
index 0000000..50fabcb
--- /dev/null
+++ b/graphql/controller/error403.php
@@ -0,0 +1,32 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Vvveb\Controller;
+
+#[\AllowDynamicProperties]
+class Error403 extends Base {
+ function index() {
+ $this->response->setType('json');
+
+ return ['errors' => ['message' => $this->view->message, 'code' => $this->view->code ?? 403]];
+ }
+}
diff --git a/graphql/controller/error404.php b/graphql/controller/error404.php
new file mode 100644
index 0000000..6497267
--- /dev/null
+++ b/graphql/controller/error404.php
@@ -0,0 +1,32 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Vvveb\Controller;
+
+#[\AllowDynamicProperties]
+class Error404 extends Base {
+ function index() {
+ $this->response->setType('json');
+
+ return ['errors' => ['message' => $this->view->message ?? '', 'code' => $this->view->code ?? 404]];
+ }
+}
diff --git a/graphql/controller/error500.php b/graphql/controller/error500.php
new file mode 100644
index 0000000..5481956
--- /dev/null
+++ b/graphql/controller/error500.php
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Vvveb\Controller;
+
+#[\AllowDynamicProperties]
+class Error500 extends Base {
+ function index() {
+ $this->response->setType('json');
+
+ if (DEBUG) {
+ return [
+ 'message' => $this->view->message,
+ 'file' => $this->view->file,
+ 'line_no' => $this->view->line_no,
+ 'line' => $this->view->line,
+ 'lines' => $this->view->lines,
+ 'trace' => $this->view->trace,
+ 'codeLines' => $this->view->code,
+ 'code' => 500,
+ ];
+ } else {
+ return ['message' => 'Internal server error!', 'code' => 500];
+ }
+ }
+}
diff --git a/graphql/controller/index.php b/graphql/controller/index.php
new file mode 100644
index 0000000..d2a1575
--- /dev/null
+++ b/graphql/controller/index.php
@@ -0,0 +1,447 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Vvveb\Controller;
+
+use function \Vvveb\arrayKeysToCamelCase;
+use function \Vvveb\arrayKeysToUnderscore;
+use function \Vvveb\camelToUnderscore;
+use function \Vvveb\controller;
+use function \Vvveb\isController;
+use function \Vvveb\isModel;
+use function \Vvveb\model;
+use GraphQL\Error\DebugFlag;
+use GraphQL\GraphQL;
+use GraphQL\Language\Parser;
+use GraphQL\Type\Definition\ObjectType;
+use GraphQL\Type\Definition\ResolveInfo;
+use GraphQL\Type\Definition\Type;
+use GraphQL\Utils\AST;
+use GraphQL\Utils\BuildSchema;
+use Vvveb\System\Event;
+
+class PostConnection {
+ public $nodes;
+
+ public $PageInfo = [];
+}
+
+#[\AllowDynamicProperties]
+class Index extends Base {
+ protected $stack = [];
+
+ protected $queryIndex = -1;
+
+ //protected $currentQuery = -1;
+ protected $stackIndex = 0;
+
+ protected $schema = [];
+
+ protected $args = [];
+
+ protected $returnIsList = false;
+
+ protected $queries = [];
+
+ protected $mutations = [];
+
+ protected $types = [];
+
+ protected $transforms = [
+ 'post' => 'Vvveb\Transform\Post',
+ 'product' => 'Vvveb\Transform\Product',
+ ];
+
+ function queries() {
+ list($this->queries) = Event::trigger(__CLASS__, __FUNCTION__, $this->queries);
+ }
+
+ function mutations() {
+ list($this->mutations) = Event::trigger(__CLASS__, __FUNCTION__, $this->mutations);
+ }
+
+ function types() {
+ list($this->types) = Event::trigger(__CLASS__, __FUNCTION__, $this->types);
+ }
+
+ function transforms() {
+ list($this->transforms) = Event::trigger(__CLASS__, __FUNCTION__, $this->transforms);
+ }
+
+ function init() {
+ $this->types();
+ $this->queries();
+ $this->mutations();
+ $this->transforms();
+
+ return parent::init();
+ }
+
+ function cascadeOptions() {
+ }
+
+ function model($typeName, $isConnection = false) {
+ $page = 1;
+ $limit = 10;
+ $data = [];
+ $typeName = camelToUnderscore($typeName, '_');
+ $options = $this->args + $this->global;
+
+ if (! isModel($typeName, 'admin')) {
+ return $data;
+ }
+
+ $type = model($typeName);
+
+ if ($type) {
+ $transform = null;
+
+ if (isset($this->transforms[$typeName])) {
+ $class = $this->transforms[$typeName];
+ $transform = new $class();
+ }
+
+ if ($this->returnIsList || $isConnection) {
+ $data = $type->getAll($options);
+ $data = $data[$typeName] ?? [];
+
+ if ($transform) {
+ error_log(print_r($options, 1));
+ $data = $transform->getAll($data, $options);
+ }
+ } else {
+ $data = $type->get($options);
+
+ if ($transform) {
+ $data = $transform->get($data, $options);
+ }
+ }
+ } else {
+ throw new \Exception('Model does not exist!');
+ }
+
+ if ($isConnection) {
+ $pageInfo = [
+ 'count' => $return['count'] ?? 0,
+ 'page' => $page,
+ 'limit' => $limit,
+ 'hasNextPage' => true,
+ 'hasPreviousPage' => true,
+ 'startCursor' => 1,
+ ];
+
+ $data = ['nodes' => $data, 'pageInfo' => $pageInfo];
+ }
+
+ return $data;
+ }
+
+ function controller($typeName, $args, $rootType = 'mutation') {
+ //check if has method
+ if (preg_match('/^(\w+)([A-Z]\w+)/', $typeName, $matches)) {
+ $method = $matches[1];
+ $class = $matches[2];
+ } else {
+ $method = 'index';
+ $class = $typeName;
+ }
+
+ $classFile = $rootType . '/' . $class;
+ $className = $rootType . '\\' . $class;
+
+ $data = [];
+
+ if (isController($classFile)) {
+ $controller = controller($className);
+
+ if ($controller) {
+ if (method_exists($controller, $method)) {
+ $data = $controller->$method($args + $this->global);
+ } else {
+ throw new \Exception('Controller method does not exist!');
+ }
+ } else {
+ throw new \Exception('Controller can\'t be loaded!');
+ }
+ } else {
+ $class = strtolower(camelToUnderscore($class,'_'));
+
+ if (isModel($class)) {
+ $class = model($class);
+
+ if ($class) {
+ if (method_exists($class, $method)) {
+ $data = $class->$method($args + ['site_id' => 1]);
+ } else {
+ throw new \Exception('Model method does not exist!');
+ }
+ } else {
+ throw new \Exception('Model can\'t be loaded!');
+ }
+ } else {
+ //throw new \Exception('Model does not exist!');
+ }
+ }
+
+ return $data;
+ }
+
+ function defaultFieldResolver($objectValue, $args, $context, ResolveInfo $info) {
+ $fieldName = $info->fieldName;
+
+ if (is_null($fieldName)) {
+ throw new \Exception('Could not get $fieldName from ResolveInfo');
+ }
+
+ if (is_null($info->parentType)) {
+ throw new \Exception('Could not get $parentType from ResolveInfo');
+ }
+
+ $parentTypeName = $info->parentType->name; //MutationType
+ $typeName = $info->fieldDefinition->config['type']->name ?? '';
+
+ $returnType = '';
+ $this->returnIsList = false;
+ $isConnection = false;
+ $this->args = $args;
+
+ if (is_array($objectValue)) {
+ $this->args += $objectValue;
+ }
+
+ if (GRAPHQL_CAMELCASE && is_array($this->args)) {
+ $this->args = arrayKeysToUnderscore($this->args, '_');
+ }
+
+ if ($info->returnType) {
+ //method_exists($info->returnType, 'getInnermostType')
+ if (is_a($info->returnType, 'GraphQL\Type\Definition\ListOfType')) {
+ $returnType = $info->returnType->getInnermostType()->name;
+ $this->returnIsList = true;
+ } else {
+ $returnType = $info->returnType->name ?? '';
+ }
+ }
+ /*
+ error_log('$returnType = ' . $returnType);
+ error_log('$objectValue = ' . print_r($objectValue, 1));
+ error_log('$fieldName = ' . $fieldName);
+ error_log('$parentTypeName = ' . $parentTypeName);
+ error_log('$typeName = ' . $typeName);
+ error_log('$args = ' . print_r($this->args, 1));
+ */
+ $method = '';
+ $type = '';
+ $permission = $fieldName;
+
+ if (preg_match('/^([a-z]+)([A-Z]\w+)/', $fieldName, $matches)) {
+ $method = $matches[1];
+ $type = strtolower(camelToUnderscore($matches[2],'_'));
+ $permission = "$type/$method";
+ }
+
+ $this->permission($permission);
+ $data = [];
+
+ //if previous controller or model call already has the data then don't try to retrive it again
+ if (isset($this->stack[$this->queryIndex][$this->stackIndex - 1]['data'][$fieldName])) {
+ $data = $this->stack[$this->queryIndex][$this->stackIndex - 1]['data'][$fieldName];
+ }
+
+ //if object already has the data then don't try to retrive it again
+ if (isset($objectValue[$fieldName])) {
+ $data = $objectValue[$fieldName];
+ }
+
+ if ($parentTypeName == 'RootQueryType') {
+ $this->queryIndex++;
+
+ if (isset($this->queries[$type])) {
+ $fn = $this->queries[$type];
+ $data = $fn($parentTypeName, $fieldName, $this->args, $this->returnIsList, $isConnection);
+ } else {
+ $data = $this->controller($fieldName, $this->args, 'query');
+ }
+ } else {
+ if ($parentTypeName == 'MutationType') {
+ $data = [];
+
+ if (isset($this->mutations[$type])) {
+ $fn = $this->mutations[$type];
+ $data = $fn($parentTypeName, $fieldName, $this->args, $this->returnIsList, $isConnection);
+ } else {
+ //crud
+ //if (preg_match('/^(get|add|edit|delete)([A-Z]\w+)/', $typeName, $matches)) {
+ $data = $this->controller($fieldName, $this->args, 'mutation');
+ }
+ }
+ }
+
+ if (! $data) {
+ foreach ([$typeName, $returnType] as $type) {
+ if (substr_compare($type, 'Type', -4 ,4) === 0) {
+ //$typeName = strtolower(preg_replace('/Type$/', '', $typeName));
+ $type = substr($type, 0, -4);
+
+ if (isset($this->types[$type])) {
+ $fn = $this->types[$type];
+ $data = $fn($parentTypeName, $typeName, $this->args, $this->returnIsList, $isConnection);
+ } else {
+ $data = $this->model($type);
+ }
+
+ break;
+ } else {
+ if (substr_compare($type, 'Connection', -10 ,10) === 0) {
+ //$typeName = strtolower(preg_replace('/Type$/', '', $typeName));
+ $isConnection = true;
+ $type = substr($type, 0, -10);
+
+ if (isset($this->types[$type])) {
+ $fn = $this->types[$type];
+ $data = $fn($parentTypeName, $typeName, $this->args, $this->returnIsList, $isConnection);
+ } else {
+ $data = $this->model($type, true);
+ }
+
+ break;
+ }
+ }
+ }
+ }
+
+ if (GRAPHQL_CAMELCASE && is_array($data)) {
+ $data = arrayKeysToCamelCase($data);
+ }
+
+ $this->stack[$this->queryIndex][$this->stackIndex++] = [
+ 'model' => $typeName,
+ 'method' => $method,
+ //'args' => $this->args,
+ 'data' => $data,
+ 'objectValue' => $objectValue,
+ ];
+
+ if ($data) {
+ if ($isConnection) {
+ return $data;
+ } else {
+ return $data;
+ }
+ }
+
+ $property = null;
+
+ if (is_array($objectValue) || $objectValue instanceof ArrayAccess) {
+ if (isset($objectValue[$fieldName])) {
+ $property = $objectValue[$fieldName];
+ }
+ } elseif (is_object($objectValue)) {
+ if (isset($objectValue->{$fieldName})) {
+ $property = $objectValue->{$fieldName};
+ }
+ }
+ //error_log(print_r($property, 1));
+ return $property instanceof Closure
+ ? $property($objectValue, $args, $contextValue, $info)
+ : $property;
+ }
+
+ function index() {
+ $rawInput = file_get_contents('php://input');
+
+ $typeConfigDecorator = function (array $typeConfig, $typeDefinitionNode) : array {
+ $name = $typeConfig['name'];
+ //error_log($name . ' $typeConfigDecorator');
+ if ($name == 'ObjectType') {
+ //error_log(print_r($typeDefinitionNode, 1));
+
+/*
+$typeDefinitionNode = new ObjectType([
+ 'name' => 'PostConnection',
+ 'fields' => [
+ 'nodes' => [
+ 'type' => Type::listOf('PostType'),
+ 'resolve' => fn () => $data['nodes']
+ ],
+ 'pageInfo' => [
+ 'type' => 'PageInfo',
+ 'resolve' => fn () => $data['pageInfo']
+ ]
+ ]
+]);
+ */
+ }
+ // ... add missing options to $typeConfig based on type $name
+ return $typeConfig;
+ };
+
+ $cacheFilename = DIR_STORAGE . 'model' . DS . 'cached_schema.php';
+
+ if (! file_exists($cacheFilename)) {
+ $schemaController = new Schema();
+ $schema = $schemaController->schema(); //file_get_contents(DIR_APP . 'schema.gql');
+ $document = Parser::parse($schema);
+ file_put_contents($cacheFilename, "<?php\nreturn " . var_export(AST::toArray($document), true) . ";\n");
+ } else {
+ $document = AST::fromArray(require $cacheFilename); // fromArray() is a lazy operation as well
+ }
+
+ //$typeConfigDecorator = function () {};
+ //$schema = BuildSchema::build($document);//, $typeConfigDecorator);
+ $this->schema = BuildSchema::build($document, $typeConfigDecorator);
+
+ $input = json_decode($rawInput, true);
+ $query = $input['query'] ?? '';
+ $variableValues = $input['variables'] ?? null;
+
+ try {
+ $result = GraphQL::executeQuery($this->schema, $query, null, null, $variableValues, null, [$this, 'defaultFieldResolver'] /*'Vvveb\Controller\defaultFieldResolver'*/);
+ $flags = 0;
+
+ if (DEBUG) {
+ $flags = DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE;
+ }
+ $output = $result->toArray($flags);
+
+ //error_log(print_r($this->stack, 1));
+ } catch (\Exception $e) {
+ $message = $e->getMessage();
+
+ if (DEBUG) {
+ $message .= ' - ' . $e->getFile();
+ $message .= ':' . $e->getLine();
+ $message .= "\n" . $e->getTraceAsString();
+ }
+
+ $output = [
+ 'errors' => [
+ [
+ 'message' => $message,
+ ],
+ ],
+ ];
+ }
+
+ return $output;
+ }
+}
diff --git a/graphql/controller/mutation/cart.php b/graphql/controller/mutation/cart.php
new file mode 100644
index 0000000..580dcda
--- /dev/null
+++ b/graphql/controller/mutation/cart.php
@@ -0,0 +1,28 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Vvveb\Controller\Mutation;
+
+use Vvveb\Controller\Cart as CartBase;
+
+class Cart extends CartBase {
+}
diff --git a/graphql/controller/query/cart.php b/graphql/controller/query/cart.php
new file mode 100644
index 0000000..49b6761
--- /dev/null
+++ b/graphql/controller/query/cart.php
@@ -0,0 +1,28 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Vvveb\Controller\Query;
+
+use Vvveb\Controller\Cart as CartBase;
+
+class Cart extends CartBase {
+}
diff --git a/graphql/controller/schema.php b/graphql/controller/schema.php
new file mode 100644
index 0000000..a4cdb5e
--- /dev/null
+++ b/graphql/controller/schema.php
@@ -0,0 +1,362 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Vvveb\Controller;
+
+use function Vvveb\dashesToCamelCase;
+use function Vvveb\humanReadable;
+use function Vvveb\siteSettings;
+use Vvveb\System\Cache;
+use Vvveb\System\Event;
+use Vvveb\System\Functions\Plural;
+use Vvveb\System\Sites;
+use Vvveb\System\Sqlp\Sqlp;
+
+#[\AllowDynamicProperties]
+class Schema extends Base {
+ private $models = [];
+
+ private $tables = [];
+
+ private $tableNames = [];
+
+ function type($type) {
+ $compare = strtolower($type);
+
+ switch ($compare) {
+ case 'int':
+ case 'tinyint':
+ case 'smallint':
+ case 'double':
+ case 'array':
+ $type = 'Int';
+
+ break;
+
+ case 'decimal':
+ $type = 'Float';
+
+ break;
+
+ case 'array':
+ $type = '[Int]';
+
+ break;
+
+ case 'varchar':
+ case 'char':
+ case 'text':
+ case 'enum':
+ case 'date':
+ case 'datetime':
+ case 'timestamp':
+ case 'longtext':
+ case 'tinytext':
+ $type = 'String';
+
+ break;
+ }
+
+ return $type;
+ }
+
+ function types() {
+ $db = \Vvveb\System\Db::getInstance();
+
+ $tables = $db->getTableNames(DB_NAME);
+ $types = include(DIR_APP . 'types.php') ?? [];
+
+ foreach ($tables as $table) {
+ //skip cart table
+ if ($table == 'cart') {
+ continue;
+ }
+ $meta = $db->getColumnsMeta($table, true);
+ $cols = [];
+
+ foreach ($meta as $column) {
+ $name = $column['name'] ?? '';
+ $col = [];
+ $col['name'] = $name;
+ $col['description'] = $column['c'] ?? '';
+
+ //column is id (input) type
+ if (substr_compare($name, '_id', -3 ,3) === 0) {
+ $type = 'ID';
+ $relation = substr($name,0, -3);
+
+ if ($relation != $table && strpos($table, $relation) === 0) {
+ $relationType = dashesToCamelCase($table, '_') . 'Type';
+ $typeTable = $table;
+ $pos = strpos($typeTable, $relation . '_');
+
+ if ($pos === 0) {
+ $typeTable = substr_replace($typeTable, '', $pos, strlen($relation . '_'));
+
+ $pos = strpos($typeTable, 'to_');
+
+ if ($pos === 0) {
+ $typeTable = substr_replace($typeTable, '', $pos, 3);
+ $relationType = dashesToCamelCase($typeTable, '_') . 'Type';
+ }
+
+ $typeTable = Plural::tablePlural($typeTable);
+ }
+
+ if (! isset($types[$relation]['properties'][$typeTable])) {
+ $types[$relation]['properties'][$typeTable] = ['name' => $table, 'type' => "[$relationType]"];
+ }
+ }
+ } else {
+ if (in_array($name, $tables)) {
+ $type = dashesToCamelCase($name, '_') . 'Type'; //. 'Input';
+ } else {
+ $type = $this->type($column['t'] ?? 'Int');
+ }
+ }
+
+ $col['type'] = $type;
+
+ $cols[$column['name']] = $col;
+ }
+
+ if ($table == 'product_option' || $table == 'product_option_value') {
+ $cols += [
+ 'name' => ['name' => 'name', 'type' => 'string'],
+ ];
+ }
+
+ $data = [
+ 'name' => $table,
+ 'properties' => $cols,
+ ];
+
+ //$types[$table] = isset($types[$table]) ? array_replace_recursive($types[$table], $data) : $data;
+ if (isset($types[$table]['properties'])) {
+ $data['properties'] += $types[$table]['properties'];
+ }
+
+ $types[$table] = $data;
+
+ //for content table also add name and content columns to relation
+ if (substr_compare($table, '_content', -8 ,8) === 0) {
+ $relation = substr($table, 0, -8);
+ $types[$relation]['properties']['name'] = ['type' => 'char', 'name' => 'name'];
+ $types[$relation]['properties']['content'] = ['type' => 'char', 'name' => 'content'];
+ $types[$relation]['properties']['slug'] = ['type' => 'char', 'name' => 'slug'];
+ }
+ }
+
+ //$types = array_replace($types, include(DIR_APP . 'types.php'));
+
+ list($types) = Event :: trigger(__CLASS__,__FUNCTION__, $types);
+
+ return $types;
+ }
+
+ function models() {
+ $dirSQL = DIR_ROOT . 'admin' . DS . 'sql' . DS . DB_ENGINE . DS;
+ $sqlp = new Sqlp();
+ $models = [];
+
+ $files = glob("$dirSQL*.sql");
+
+ foreach ($files as $file) {
+ $sqlp->parseSqlPfile($file);
+ $tree = $sqlp->getModel();
+ $model = basename($file, '.sql');
+ //skip cart table
+ if ($model == 'cart') {
+ continue;
+ }
+
+ foreach ($tree as $method => $options) {
+ $models[$model][$method] = $options['params'];
+ }
+ }
+
+ list($models) = Event :: trigger(__CLASS__,__FUNCTION__, $models);
+
+ return $models;
+ }
+
+ function schema() {
+ $typesText = '';
+ $types = $this->types();
+
+ foreach ($types as $table => $attrs) {
+ $properties = '';
+
+ foreach ($attrs['properties'] as $name => $property) {
+ if (substr_compare($name, '_id', -3 ,3) === 0) {
+ $type = 'ID';
+ } else {
+ $type = $this->type($property['type'] ?? 'Int');
+ }
+
+ if (GRAPHQL_CAMELCASE) {
+ $name = lcfirst(dashesToCamelCase($name, '_'));
+ $type = dashesToCamelCase($type, '_');
+ }
+
+ $properties .= " $name: $type\n";
+ }
+
+ $tableName = dashesToCamelCase($table, '_');
+ $typesText .= "type {$tableName}Type {\n$properties}\n\n";
+ }
+
+ $models = $this->models();
+ $queries = [];
+ $mutations = [];
+
+ $queriesText = '';
+ $mutationsText = '';
+ $connectionsText = '';
+
+ foreach ($models as $model => $methods) {
+ $modelComment = "\n\n # " . humanReadable($model) . "\n";
+ $mutationsText .= $modelComment;
+ $queriesText .= $modelComment;
+
+ if ($model == 'category' || $model == 'filter' || $model == 'stat') {
+ continue;
+ }
+
+ foreach ($methods as $method => $params) {
+ $methodName = lcfirst(dashesToCamelCase($method . '_' . $model, '_'));
+ $parameters = '';
+
+ foreach ($params as $name => $param) {
+ if ($param['in_out'] == 'IN') {
+ $name = $param['name'];
+ $type = $this->type($param['type'] ?? 'Int');
+
+ if (substr_compare($name, '_id', -3 ,3) === 0) {
+ if ($param['type'] == 'ARRAY') {
+ $type = '[ID]';
+ } else {
+ $type = 'ID';
+ }
+ }
+
+ if (GRAPHQL_CAMELCASE) {
+ $name = lcfirst(dashesToCamelCase($name, '_'));
+ $type = dashesToCamelCase($type, '_');
+ }
+
+ $parameters .= "$name: $type, ";
+ }
+ }
+
+ $parameters = rtrim($parameters, ', ');
+ $type = dashesToCamelCase($model, '_');
+
+ if (strpos($method, 'get') === 0) {
+ if ($model == 'category' || $model == 'filter' || $model == 'stat') {
+ //$type = 'Taxonomy';
+ }
+
+ $return = $type . 'Type';
+ $methodText = " $methodName($parameters):{$return}\n";
+
+ if (strpos($method, 'getAll') === 0) {
+ $return = "[{$type}Type]";
+ $modelPlural = lcfirst(dashesToCamelCase(Plural::tablePlural($model), '_'));
+ $methodText = " $modelPlural($parameters):{$type}Connection\n";
+
+ $connectionsText .= $modelComment .
+ "type {$type}Connection {\n nodes:[{$type}Type!]!\n pageInfo:PageInfo!\n}\n";
+ }
+
+ if ($method == 'get') {
+ $modelName = lcfirst(dashesToCamelCase($model, '_'));
+ $methodText = " $modelName($parameters):{$return}\n";
+ }
+
+ $queriesText .= $methodText;
+ } else {
+ $methodText = " $methodName($parameters):ID\n";
+
+ $mutationsText .= $methodText;
+ }
+ }
+ }
+
+ $cache = Cache::getInstance();
+ $json = $cache->cache(APP,'graphql-schema',function () {
+ $site = siteSettings();
+ $data = Sites :: getSiteData();
+
+ $json = [];
+ $json['types'] = $this->types();
+
+ return $json;
+ }, 259200);
+
+ $text = <<<GQL
+type PageInfo {
+ count: Int
+ page: Int
+ limit: Int
+ endCursor: String
+ hasNextPage: Boolean!
+ hasPreviousPage: Boolean!
+ startCursor: String
+}
+
+$connectionsText
+
+$typesText
+
+type RootQueryType {
+
+ cart(cartId:ID!):CartType
+
+$queriesText
+}
+
+type MutationType {
+
+ createCart:CartType
+ addCart(cartId:ID!, productId:ID!, quantity:Int, options:String, productVariantId:ID, subscriptionPlanId:ID):CartType
+ updateCart(cartId:ID!, key:String!, quantity:Int!, options:String, productVariantId:ID, subscriptionPlanId:ID):CartType
+ removeCart(cartId:ID!, key:[String!]!):CartType
+
+$mutationsText
+}
+
+schema {
+ query:RootQueryType
+ mutation:MutationType
+}
+GQL;
+
+ return $text;
+ }
+
+ function index() {
+ $text = $this->schema();
+ $this->response->setType('text');
+ $this->response->output($text);
+ }
+}
diff --git a/graphql/index.php b/graphql/index.php
new file mode 100644
index 0000000..cfe181e
--- /dev/null
+++ b/graphql/index.php
@@ -0,0 +1,26 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+define('APP', 'graphql');
+//define('DISABLE_PLUGIN_ON_ERORR', true);
+
+return include __DIR__ . '/../index.php';
diff --git a/graphql/transform/post.php b/graphql/transform/post.php
new file mode 100644
index 0000000..b5175fd
--- /dev/null
+++ b/graphql/transform/post.php
@@ -0,0 +1,34 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Vvveb\Transform;
+
+use Vvveb\Controller\Base;
+use Vvveb\System\Traits\Post as PostTrait;
+
+#[\AllowDynamicProperties]
+class Post extends Base {
+ use PostTrait {
+ post as get;
+ posts as getAll;
+ }
+}
diff --git a/graphql/transform/product.php b/graphql/transform/product.php
new file mode 100644
index 0000000..7e3a780
--- /dev/null
+++ b/graphql/transform/product.php
@@ -0,0 +1,35 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Vvveb\Transform;
+
+use Vvveb\Controller\Base;
+use Vvveb\System\Traits\Product as ProductTrait;
+
+#[\AllowDynamicProperties]
+class Product extends Base {
+ //use ProductTrait;
+ use ProductTrait {
+ product as get;
+ products as getAll;
+ }
+}
diff --git a/graphql/types.php b/graphql/types.php
new file mode 100644
index 0000000..26003b7
--- /dev/null
+++ b/graphql/types.php
@@ -0,0 +1,340 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+return
+ [
+ 'product' => [
+ 'name' => 'total',
+ 'properties' => [
+ 'price_currency' => [
+ 'name' => 'price_currency',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ ],
+ ],
+ 'total' => [
+ 'name' => 'total',
+ 'properties' => [
+ 'key' => [
+ 'name' => 'key',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'title' => [
+ 'name' => 'title',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'value' => [
+ 'name' => 'value',
+ 'description' => '',
+ 'type' => 'Float',
+ ],
+ 'value_formatted' => [
+ 'name' => 'value_formatted',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'text' => [
+ 'name' => 'text',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ ],
+ ],
+ 'cartOptionValue' => [
+ 'name' => 'cartOptionValue',
+ 'properties' => [
+ 'product_option_value_id' => [
+ 'name' => 'product_option_value_id',
+ 'description' => '',
+ 'type' => 'Id',
+ ],
+ 'product_option_id' => [
+ 'name' => 'product_option_id',
+ 'description' => '',
+ 'type' => 'Id',
+ ],
+ 'product_id' => [
+ 'name' => 'product_id',
+ 'description' => '',
+ 'type' => 'Id',
+ ],
+ 'option_id' => [
+ 'name' => 'option_id',
+ 'description' => '',
+ 'type' => 'Id',
+ ],
+ 'option_value_id' => [
+ 'name' => 'option_value_id',
+ 'description' => '',
+ 'type' => 'Id',
+ ],
+ 'quantity' => [
+ 'name' => 'quantity',
+ 'description' => '',
+ 'type' => 'Int',
+ ],
+ 'subtract' => [
+ 'name' => 'subtract',
+ 'description' => '',
+ 'type' => 'Int',
+ ],
+ 'price_operator' => [
+ 'name' => 'price_operator',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'price' => [
+ 'name' => 'price',
+ 'description' => '',
+ 'type' => 'Float',
+ ],
+ 'points' => [
+ 'name' => 'points',
+ 'description' => '',
+ 'type' => 'Int',
+ ],
+ 'points_operator' => [
+ 'name' => 'points_operator',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'weight_operator' => [
+ 'name' => 'weight_operator',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'weight' => [
+ 'name' => 'weight',
+ 'description' => '',
+ 'type' => 'Float',
+ ],
+ 'image' => [
+ 'name' => 'image',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'name' => [
+ 'name' => 'name',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'option' => [
+ 'name' => 'option',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'price_tax' => [
+ 'name' => 'price_tax',
+ 'description' => '',
+ 'type' => 'Float',
+ ],
+ 'price_formatted' => [
+ 'name' => 'price_formatted',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'price_currency' => [
+ 'name' => 'price_currency',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'weight_formatted' => [
+ 'name' => 'price_tax',
+ 'description' => '',
+ 'type' => 'Float',
+ ],
+ ],
+ ],
+ 'cartProduct' => [
+ 'name' => 'cartProduct',
+ 'properties' => [
+ 'name' => [
+ 'name' => 'name',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'key' => [
+ 'name' => 'key',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'product_id' => [
+ 'name' => 'product_id',
+ 'description' => '',
+ 'type' => 'Id',
+ ],
+ 'product_variant_id' => [
+ 'name' => 'product_variant_id',
+ 'description' => '',
+ 'type' => 'Int',
+ ],
+ 'price' => [
+ 'name' => 'price',
+ 'description' => '',
+ 'type' => 'Float',
+ ],
+ 'price_tax' => [
+ 'name' => 'price_tax',
+ 'description' => '',
+ 'type' => 'Float',
+ ],
+ 'price_currency' => [
+ 'name' => 'price_currency',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'total' => [
+ 'name' => 'total',
+ 'description' => '',
+ 'type' => 'Float',
+ ],
+ 'total_tax' => [
+ 'name' => 'total_tax',
+ 'description' => '',
+ 'type' => 'Float',
+ ],
+ 'price_tax_formatted' => [
+ 'name' => 'price_tax_formatted',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'price_formatted' => [
+ 'name' => 'price_formatted',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'total_formatted' => [
+ 'name' => 'total_formatted',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'total_tax_formatted' => [
+ 'name' => 'total_tax_formatted',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'slug' => [
+ 'name' => 'slug',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'url' => [
+ 'name' => 'url',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'image' => [
+ 'name' => 'image',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'quantity' => [
+ 'name' => 'quantity',
+ 'description' => '',
+ 'type' => 'Int',
+ ],
+ 'option_value' => [
+ 'name' => 'option_value',
+ 'description' => '',
+ 'type' => '[CartOptionValueType]',
+ ],
+ ],
+ ],
+ 'cart' => [
+ 'name' => 'cart',
+ 'properties' => [
+ 'cart_id' => [
+ 'name' => 'cart_id',
+ 'description' => '',
+ 'type' => 'Id',
+ ],
+ 'encrypted_cart_id' => [
+ 'name' => 'encrypted_cart_id',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'products' => [
+ 'name' => 'products',
+ 'description' => '',
+ 'type' => '[CartProductType]',
+ ],
+ 'totals' => [
+ 'name' => 'totals',
+ 'description' => '',
+ 'type' => '[TotalType]',
+ ],
+ 'total_items' => [
+ 'name' => 'total_items',
+ 'description' => '',
+ 'type' => 'Int',
+ ],
+ 'total_price' => [
+ 'name' => 'total_price',
+ 'description' => '',
+ 'type' => 'Float',
+ ],
+ 'total_tax' => [
+ 'name' => 'total_tax',
+ 'description' => '',
+ 'type' => 'Float',
+ ],
+ 'total' => [
+ 'name' => 'total',
+ 'description' => '',
+ 'type' => 'Float',
+ ],
+ 'total_formatted' => [
+ 'name' => 'total_formatted',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'price_currency' => [
+ 'name' => 'price_currency',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'weight_unit' => [
+ 'name' => 'weight_unit',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'length_unit' => [
+ 'name' => 'length_unit',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'cart_url' => [
+ 'name' => 'cart_url',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ 'checkout_url' => [
+ 'name' => 'checkout_url',
+ 'description' => '',
+ 'type' => 'String',
+ ],
+ ],
+ ],
+ ];