graphqlix

This commit is contained in:
2026-05-22 11:36:39 +05:30
parent 805b465ae6
commit 8c58838726
3 changed files with 1016 additions and 30 deletions

View File

@@ -1,8 +1,9 @@
import { useMemo, useState } from 'react'
import { useMemo, useState, useEffect } from 'react'
import {
Play, Copy, Check, CheckCircle2, AlertCircle, Server, FileJson, Loader2
} from 'lucide-react'
import { highlightJSON } from '../lib/highlight'
import { normalizeAndGetMeta, getGraphQLKey } from '../data/graphqlMeta'
function safeDecode(v) {
try { return decodeURIComponent(v) } catch { return v }
@@ -20,8 +21,17 @@ function parseUrl(url) {
return { path, params }
}
export default function EndpointCard({ endpoint, baseUrl, onSend, result, loading }) {
const { path, params: parsedParams } = useMemo(() => parseUrl(endpoint.url), [endpoint.url])
export default function EndpointCard({ endpoint, baseUrl, isLegacy, onSend, result, loading }) {
const gqlKey = useMemo(() => {
return isLegacy ? getGraphQLKey(endpoint.name) : null
}, [endpoint.name, isLegacy])
const meta = useMemo(() => {
return gqlKey ? normalizeAndGetMeta(endpoint.name) : null
}, [endpoint.name, gqlKey])
const { path: originalPath, params: parsedParams } = useMemo(() => parseUrl(endpoint.url), [endpoint.url])
const path = isLegacy && gqlKey ? `/api/rest/${gqlKey}` : originalPath
const paramDefs = endpoint.params || parsedParams
const [values, setValues] = useState(() =>
@@ -30,6 +40,28 @@ export default function EndpointCard({ endpoint, baseUrl, onSend, result, loadin
const [copied, setCopied] = useState(false)
const [urlCopied, setUrlCopied] = useState(false)
const [queryText, setQueryText] = useState(() => meta?.query || '')
const [variablesText, setVariablesText] = useState(() => meta?.variables || '{}')
// Reset and sync state when metadata changes
useEffect(() => {
setQueryText(meta?.query || '')
setVariablesText(meta?.variables || '{}')
if (meta?.variables) {
try {
const parsed = JSON.parse(meta.variables)
setValues(v => {
const next = { ...v }
Object.keys(next).forEach(k => {
if (parsed[k] !== undefined) next[k] = String(parsed[k])
})
return next
})
} catch (err) {}
}
}, [meta])
const composedUrl = useMemo(() => {
if (paramDefs.length === 0) return baseUrl + path
const qs = paramDefs
@@ -38,7 +70,31 @@ export default function EndpointCard({ endpoint, baseUrl, onSend, result, loadin
return `${baseUrl}${path}?${qs}`
}, [path, paramDefs, values, baseUrl])
const handleSend = () => onSend(endpoint, composedUrl)
const handleSend = () => {
const useGraphql = endpoint.useGraphql || gqlKey === 'getinvoiceinsight' || gqlKey === 'getinvoices'
if (isLegacy && meta && (endpoint.method !== 'GET' || useGraphql)) {
const graphqlUrl = `${baseUrl}/v1/graphql`
let parsedVars = {}
try {
parsedVars = variablesText?.trim() ? JSON.parse(variablesText) : {}
} catch (err) {}
const overrideOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-hasura-admin-secret': 'nearle-admin-secret'
},
body: JSON.stringify({
query: queryText,
variables: parsedVars
})
}
onSend(endpoint, graphqlUrl, overrideOptions)
} else {
onSend(endpoint, composedUrl)
}
}
const copyResponse = async () => {
if (!result || result.kind !== 'response') return
@@ -116,9 +172,17 @@ export default function EndpointCard({ endpoint, baseUrl, onSend, result, loadin
className="w-full px-3.5 py-2.5 bg-white border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-brand-500/20 focus:border-brand-500 transition-all shadow-sm text-slate-700"
value={values[p.name] ?? ''}
placeholder={`Enter ${p.name}...`}
onChange={(e) =>
setValues((v) => ({ ...v, [p.name]: e.target.value }))
}
onChange={(e) => {
const newVal = e.target.value
setValues((v) => ({ ...v, [p.name]: newVal }))
if (isLegacy && meta) {
try {
const parsed = JSON.parse(variablesText || '{}')
const updatedValue = isNaN(newVal) || newVal.trim() === '' ? newVal : Number(newVal)
setVariablesText(JSON.stringify({ ...parsed, [p.name]: updatedValue }, null, 2))
} catch (err) {}
}
}}
/>
</div>
))}
@@ -140,7 +204,43 @@ export default function EndpointCard({ endpoint, baseUrl, onSend, result, loadin
</div>
{/* Payload body or composed URL preview */}
{endpoint.body ? (
{isLegacy && meta ? (
<div className="flex-1 grid grid-cols-1 md:grid-cols-2 divide-y md:divide-y-0 md:divide-x divide-white/5 min-h-[300px]">
<div className="p-5 flex flex-col group/pane relative">
<div className="text-[11px] font-bold text-slate-400 mb-3 uppercase tracking-wider flex items-center gap-2">
<FileJson size={14} className="text-brand-400" /> GraphQL Query
</div>
<textarea
className="flex-1 w-full bg-transparent text-slate-300 font-mono text-[13px] focus:outline-none resize-none leading-relaxed selection:bg-brand-500/30 scrollbar-hide min-h-[250px]"
value={queryText}
onChange={e => setQueryText(e.target.value)}
spellCheck="false"
/>
</div>
<div className="p-5 flex flex-col bg-white/[0.02]">
<div className="text-[11px] font-bold text-slate-400 mb-3 uppercase tracking-wider">Variables JSON</div>
<textarea
className="flex-1 w-full bg-transparent text-emerald-400 font-mono text-[13px] focus:outline-none resize-none leading-relaxed selection:bg-emerald-500/30 scrollbar-hide min-h-[250px]"
value={variablesText}
onChange={e => {
const txt = e.target.value
setVariablesText(txt)
try {
const parsed = JSON.parse(txt)
setValues(v => {
const next = { ...v }
Object.keys(next).forEach(k => {
if (parsed[k] !== undefined) next[k] = String(parsed[k])
})
return next
})
} catch (err) {}
}}
spellCheck="false"
/>
</div>
</div>
) : endpoint.body ? (
<div className="flex-1 p-5 flex flex-col">
<div className="text-[11px] font-bold text-slate-400 mb-3 uppercase tracking-wider flex items-center gap-2">
<FileJson size={14} className="text-brand-400" /> Request Body (JSON)

View File

@@ -33,7 +33,7 @@ export default function TopicView({ topic, searchQuery }) {
}
}, [topic.id])
const handleSend = async (endpoint, composedUrl) => {
const handleSend = async (endpoint, composedUrl, overrideOptions = null) => {
if (abortRef.current) abortRef.current.abort()
const controller = new AbortController()
abortRef.current = controller
@@ -42,34 +42,46 @@ export default function TopicView({ topic, searchQuery }) {
const start = Date.now()
try {
const headers = {}
if (endpoint.method !== 'GET') {
headers['Content-Type'] = 'application/json'
}
if (topic.type === 'legacy') {
headers['x-hasura-admin-secret'] = ADMIN_SECRET
}
const fetchOptions = {
method: endpoint.method,
headers,
let fetchUrl = composedUrl
let fetchOptions = {
signal: controller.signal
}
if (['POST', 'PUT', 'PATCH'].includes(endpoint.method) && endpoint.body) {
if (typeof endpoint.body === 'string') {
try {
// Re-stringify in case it's a badly formatted JSON string, but mostly it's just raw string
fetchOptions.body = JSON.stringify(JSON.parse(endpoint.body))
} catch {
fetchOptions.body = endpoint.body
if (overrideOptions) {
fetchOptions = {
...fetchOptions,
...overrideOptions,
headers: {
...overrideOptions.headers
}
}
} else {
const headers = {}
if (endpoint.method !== 'GET') {
headers['Content-Type'] = 'application/json'
}
if (topic.type === 'legacy') {
headers['x-hasura-admin-secret'] = ADMIN_SECRET
}
fetchOptions.method = endpoint.method
fetchOptions.headers = headers
if (['POST', 'PUT', 'PATCH'].includes(endpoint.method) && endpoint.body) {
if (typeof endpoint.body === 'string') {
try {
// Re-stringify in case it's a badly formatted JSON string, but mostly it's just raw string
fetchOptions.body = JSON.stringify(JSON.parse(endpoint.body))
} catch {
fetchOptions.body = endpoint.body
}
} else {
fetchOptions.body = JSON.stringify(endpoint.body)
}
} else {
fetchOptions.body = JSON.stringify(endpoint.body)
}
}
const res = await fetch(toProxyPath(composedUrl), fetchOptions)
const res = await fetch(toProxyPath(fetchUrl), fetchOptions)
const ms = Date.now() - start
const text = await res.text()
let body
@@ -124,6 +136,7 @@ export default function TopicView({ topic, searchQuery }) {
key={`${topic.uniqueId}/${e.name}`}
endpoint={e}
baseUrl={topic.baseUrl}
isLegacy={topic.type === 'legacy'}
onSend={handleSend}
result={isActive ? active.result : null}
loading={isActive ? active.loading : false}

873
src/data/graphqlMeta.js Normal file
View File

@@ -0,0 +1,873 @@
export const graphqlMeta = {
getsubcategory: {
query: /* GraphQL */ `
query GetSubCategory($moduleid: bigint!, $categoryid: bigint!) {
app_subcategory(
where: {
categoryid: { _eq: $categoryid }
category: { modules: { moduleid: { _eq: $moduleid } } }
}
) {
subcategoryid
categoryid
categorytypeid
subcategoryname
categoryname
sortorder
status
statuscode
}
}
`,
variables: `{\n "moduleid": 6,\n "categoryid": 1\n}`,
},
getorders: {
query: /* GraphQL */ `
query GetOrders(
$start: timestamptz!
$end: timestamptz!
$status: String!
$limit: Int!
$offset: Int!
) {
orders(
where: {
deliverytime: { _gte: $start, _lte: $end }
orderstatus: { _eq: $status }
}
limit: $limit
offset: $offset
) {
orderheaderid
orderid
orderstatus
deliverytime
orderamount
tenant {
tenantname
}
}
}
`,
variables: `{\n "start": "2026-01-01T00:00:00",\n "end": "2026-01-31T23:59:59",\n "status": "delivered",\n "limit": 10,\n "offset": 0\n}`,
},
gettenantlocations: {
query: /* GraphQL */ `
query GetTenantLocations($tenantid: bigint!) {
tenant_locations(where: { tenantid: { _eq: $tenantid } }) {
locationid
locationname
tenantid
}
}
`,
variables: `{\n "tenantid": 1\n}`,
},
getapplocations: {
query: /* GraphQL */ `
query GetAppLocations($userid: bigint!) {
details: app_location(
where: {
app_locationconfigs: {
status: { _eq: "Active" }
userid: { _eq: $userid }
}
}
) {
applocationid
locationname
}
}
`,
variables: `{\n "userid": 1\n}`,
},
getusers: {
query: /* GraphQL */ `
query GetUsers {
app_user {
userid
username
email
contactno
status
}
}
`,
variables: `{}`,
},
gettenantinfo: {
query: /* GraphQL */ `
query GetTenantInfo($tenantid: bigint!) {
tenants(where: { tenantid: { _eq: $tenantid } }) {
tenantid
tenantname
email
contactno
status
}
}
`,
variables: `{\n "tenantid": 1079,\n "configid": 1,\n "fromdate": "2025-07-24T00:00:00",\n "todate": "2025-07-24T23:59:59"\n}`,
},
getordersummary: {
query: /* GraphQL */ `
query GetOrderSummary(
$tenantid: bigint!
$configid: bigint!
$fromdate: timestamp!
$todate: timestamp!
) {
orders_aggregate(
where: {
tenantid: { _eq: $tenantid }
deliverytime: { _gte: $fromdate, _lte: $todate }
}
) {
aggregate {
count
}
}
orders(
where: {
tenantid: { _eq: $tenantid }
deliverytime: { _gte: $fromdate, _lte: $todate }
}
limit: 10
order_by: { deliverytime: desc }
) {
orderid
orderstatus
orderamount
deliverytime
}
}
`,
variables: `{\n "tenantid": 1079,\n "fromdate": "2025-07-24T00:00:00",\n "todate": "2025-07-24T23:59:59"\n}`,
},
getcustomersbytenant: {
query: /* GraphQL */ `
query GetCustomersByTenant(
$tenantid: bigint!
$limit: Int!
$offset: Int!
) {
tenantcustomers(
where: { tenantid: { _eq: $tenantid } }
limit: $limit
offset: $offset
order_by: { customer: { customerid: desc } }
) {
tenantlocationid: locationid
customer {
customerid
firstname
lastname
contactno
email
address
suburb
city
state
landmark
doorno
postcode
latitude
longitude
applocationid
status
}
}
}
`,
variables: `{\n "tenantid": 1079,\n "limit": 10,\n "offset": 0\n}`,
},
getapproles: {
query: /* GraphQL */ `
query GetAppRoles($configid: bigint!) {
app_roles(where: { configid: { _eq: $configid } }) {
roleid
rolename
configid
}
}
`,
variables: `{\n "configid": 1\n}`,
},
getactivelocationbyid: {
query: /* GraphQL */ `
query GetActiveLocationById {
app_locations(where: { status: { _eq: "Active" } }) {
locationid
locationname
}
}
`,
variables: `{}`,
},
getlocationsconfig: {
query: /* GraphQL */ `
query GetLocations {
details: app_location(where: {status: {_eq: "Active"}}) {
applocationid
locationname
image
city
state
postcode
latitude
longitude
opentime
closetime
radius
applocationadmins: app_locationconfigs(where: {notify: {_eq: "true"}}) {
applocationid
userid
notify
app_user {
userfcmtokem: userfcmtoken
}
}
}
}
`,
variables: `{}`,
},
getpartners: {
query: /* GraphQL */ `
query GetPartners(
$applocationid: bigint!
$partnerid: bigint!
$limit: Int!
$offset: Int!
) {
details: partnerinfo(
where: {
status: { _eq: "Active" }
_and: [
{
_or: [
{ applocationid: { _eq: $applocationid } }
{ applocationid: { _eq: 0 } }
]
}
{
_or: [
{ partnerid: { _eq: $partnerid } }
{ partnerid: { _eq: 0 } }
]
}
]
}
limit: $limit
offset: $offset
) {
partnerid
applocationid
partnertypeid
partnername
primarycontact
primaryemail
contactno
address
suburb
state
city
partnerimage
}
}
`,
variables: `{\n "applocationid": 1,\n "partnerid": 0,\n "limit": 10,\n "offset": 0\n}`,
},
getridershifts: {
query: /* GraphQL */ `
query GetRiderShifts($applocationid: bigint!) {
details: ridershifts(
where: { applocationid: { _eq: $applocationid } }
order_by: { shiftid: desc }
) {
shiftid
shiftdate
starttime
endtime
shifthours
basefare
additionalkm
additionalcharges
orders
fuelcharge
shiftname
}
}
`,
variables: `{\n "applocationid": 1\n}`,
},
getapptypes: {
query: /* GraphQL */ `
query GetTypes($tag: String!) {
app_types(where: { status: { _eq: "Active" }, tag: { _eq: $tag } }) {
apptypeid
typename
tag
status
description
mapid
created
updated
}
}
`,
variables: `{\n "tag": "partner"\n}`,
},
gettenantcustomers: {
query: /* GraphQL */ `
query GetTenantCustomers(
$tenantid: bigint!
$locationid: bigint!
$limit: Int!
$offset: Int!
) {
details: tenantcustomers(
where: {
tenantid: { _eq: $tenantid }
locationid: { _eq: $locationid }
customer: { customerid: { _is_null: false } }
}
limit: $limit
offset: $offset
order_by: { customer: { customerid: desc } }
) {
tenantlocationid: locationid
customer {
customerid
firstname
lastname
contactno
email
address
suburb
city
state
landmark
doorno
postcode
latitude
longitude
applocationid
status
}
}
}
`,
variables: `{\n "tenantid": 1079,\n "locationid": 1,\n "limit": 10,\n "offset": 0\n}`,
},
getproductcategories: {
query: /* GraphQL */ `
query GetProductCategories($moduleid: bigint!) {
productcategories(
where: { moduleid: { _eq: $moduleid }, status: { _eq: "Active" } }
order_by: { sortorder: asc }
) {
categoryid
moduleid
categorytypeid
categoryname
status
created
updated
}
}
`,
variables: `{\n "moduleid": 6\n}`,
},
getproductsubcategories: {
query: /* GraphQL */ `
query GetProductSubCategories($categoryid: bigint!) {
product_subcategories(where: { categoryid: { _eq: $categoryid } }) {
subcategoryid
categoryid
subcategoryname
status
}
}
`,
variables: `{\n "categoryid": 1\n}`,
},
getproductvariants: {
query: /* GraphQL */ `
query GetProductVariants($tenantid: bigint!, $subcategoryid: bigint!) {
productvariants(
where: {
tenantid: { _eq: $tenantid }
subcategoryid: { _eq: $subcategoryid }
}
) {
variantid
productid
tenantid
categoryid
subcategoryid
variantname
price
status
created
updated
category {
categoryname
}
}
}
`,
variables: `{\n "tenantid": 1079,\n "subcategoryid": 1\n}`,
},
getstockstatement: {
query: /* GraphQL */ `
query GetStockStatement(
$tenantid: bigint!
$locationid: bigint!
$subcategoryid: bigint
$keyword: String
$limit: Int
$offset: Int
) {
product_stock_statement(
where: {
tenantid: { _eq: $tenantid }
locationid: { _eq: $locationid }
subcategoryid: { _eq: $subcategoryid }
productname: { _ilike: $keyword }
}
limit: $limit
offset: $offset
order_by: { productid: desc }
) {
productid
productname
productimage
categoryid
subcategoryid
productunit
unitvalue
productcost
taxpercent
taxamount
retailprice
tenantid
locationid
opening
credit
debit
closing
}
}
`,
variables: `{\n "tenantid": 1079,\n "locationid": 1,\n "subcategoryid": null,\n "keyword": "%",\n "limit": 10,\n "offset": 0\n}`,
},
gettenantdeliveries: {
query: /* GraphQL */ `
query GetTenantDeliveriesFull(
$tenantid: bigint!
$status: String
$fromdate: timestamp
$todate: timestamp
$keyword: String
$limit: Int
$offset: Int
) {
deliveries(
where: {
tenantid: { _eq: $tenantid }
_and: [
{ orderstatus: { _eq: $status } }
{ deliverydate: { _gte: $fromdate } }
{ deliverydate: { _lte: $todate } }
{
_or: [
{ pickupcustomer: { _ilike: $keyword } }
{ deliverycustomer: { _ilike: $keyword } }
{ pickupcontactno: { _ilike: $keyword } }
{ deliverycontactno: { _ilike: $keyword } }
{ orderid: { _ilike: $keyword } }
]
}
]
}
limit: $limit
offset: $offset
order_by: { deliveryid: desc }
) {
deliveryid
orderid
deliverydate
orderstatus
pickupcustomer
pickupcontactno
pickupaddress
deliverycustomer
deliverycontactno
deliveryaddress
kms
customers {
customertoken
}
app_users {
firstname
contactno
}
tenants {
tenantname
primarycontact
}
}
}
`,
variables: `{\n "tenantid": 1079,\n "status": "delivered",\n "fromdate": "2026-01-01T00:00:00",\n "todate": "2026-01-31T23:59:59",\n "keyword": "%",\n "limit": 10,\n "offset": 0\n}`,
},
getinvoiceinsight: {
query: /* GraphQL */ `
query GetInvoiceInsight($tenantid: bigint!) {
invoice_insight(where: { tenantid: { _eq: $tenantid } }) {
totalcount
total
pendingcount
pending
pendingpercent
confirmedcount
confirmed
confirmedpercent
paidcount
paid
paidpercent
overduecount
overdue
overduepercent
}
}
`,
variables: `{\n "tenantid": 1079\n}`,
},
getproductscount: {
query: /* GraphQL */ `
query GetProductsCount(
$tenantid: bigint!
$categoryid: bigint!
$subcategoryid: bigint!
) {
total: products_aggregate(
where: {
tenantid: { _eq: $tenantid }
categoryid: { _eq: $categoryid }
subcategoryid: { _eq: $subcategoryid }
}
) {
aggregate {
count
}
}
available: products_aggregate(
where: {
tenantid: { _eq: $tenantid }
categoryid: { _eq: $categoryid }
subcategoryid: { _eq: $subcategoryid }
productstatus: { _eq: "available" }
}
) {
aggregate {
count
}
}
outofstock: products_aggregate(
where: {
tenantid: { _eq: $tenantid }
categoryid: { _eq: $categoryid }
subcategoryid: { _eq: $subcategoryid }
productstatus: { _eq: "outofstock" }
}
) {
aggregate {
count
}
}
}
`,
variables: `{\n "tenantid": 1079,\n "categoryid": 1,\n "subcategoryid": 1\n}`,
},
createproduct: {
query: /* GraphQL */ `
mutation CreateProduct($object: products_insert_input!) {
insert_products_one(object: $object) {
productid
applocationid
tenantid
categoryid
subcategoryid
productname
productimage
productdesc
productsku
productbrand
productunit
unitvalue
toppicks
productcost
taxamount
taxpercent
producttax
productstock
productcombo
variants
quantity
retailprice
diffprice
diffpercent
othercost
approve
productstatus
}
}
`,
variables: `{
"object": {
"applocationid": 1,
"tenantid": 1079,
"categoryid": 1,
"subcategoryid": 1,
"productname": "Sample Product",
"productimage": "",
"productdesc": "Sample description",
"productsku": "SKU123",
"productbrand": "BrandX",
"productunit": "kg",
"unitvalue": 1,
"toppicks": false,
"productcost": 50,
"taxamount": 5,
"taxpercent": 10,
"producttax": true,
"productstock": 100,
"productcombo": false,
"variants": false,
"quantity": 100,
"retailprice": 60,
"diffprice": 10,
"diffpercent": 20,
"othercost": 0,
"approve": true,
"productstatus": "available"
}
}`,
},
getinvoices: {
query: /* GraphQL */ `
query GetInvoices($tenantid: bigint!, $billstatus: bigint!) {
tenantsales(
where: {
tenantid: { _eq: $tenantid }
billstatus: { _eq: $billstatus }
}
order_by: { salesid: desc }
) {
salesid
tenantid
totalamount
billstatus
duedate
status
}
}
`,
variables: `{
"tenantid": 1079,
"billstatus": 1
}`,
},
getcustomerlocations: {
query: /* GraphQL */ `
query GetCustomerLocations($customerid: bigint!) {
customer_locations(where: { customerid: { _eq: $customerid } }) {
locationid
latitude
longitude
address
}
}
`,
variables: `{\n "customerid": 6060\n}`,
},
getcustomerordersv3: {
query: /* GraphQL */ `
query GetCustomerOrders($customerid: bigint!, $tenantid: bigint!, $moduleid: bigint!, $fromdate: timestamptz!, $todate: timestamptz!, $orderstatus: String!, $keyword: String, $limit: Int!, $offset: Int!) {
orders(
where: {
customerid: { _eq: $customerid }
tenantid: { _eq: $tenantid }
moduleid: { _eq: $moduleid }
orderstatus: { _eq: $orderstatus }
orderdate: { _gte: $fromdate, _lte: $todate }
_or: [{ orderid: { _ilike: $keyword } }]
}
limit: $limit
offset: $offset
) {
orderid
orderstatus
orderamount
}
}
`,
variables: `{\n "customerid": 6060,\n "tenantid": 1087,\n "moduleid": 2,\n "fromdate": "2026-01-01T00:00:00",\n "todate": "2026-12-31T23:59:59",\n "orderstatus": "delivered",\n "keyword": "%pizza%",\n "limit": 10,\n "offset": 0\n}`,
},
getcustomer: {
query: /* GraphQL */ `
query GetCustomer($customerid: bigint!) {
customers(where: { customerid: { _eq: $customerid } }) {
customerid
name
contactno
}
}
`,
variables: `{\n "customerid": 6060\n}`,
},
getcustomerrequests: {
query: /* GraphQL */ `
query GetCustomerRequests($customerid: bigint!, $limit: Int!, $offset: Int!) {
customer_requests(where: { customerid: { _eq: $customerid } }, limit: $limit, offset: $offset) {
requestid
status
}
}
`,
variables: `{\n "customerid": 6060,\n "limit": 10,\n "offset": 0\n}`,
},
getmobileproductsubcategories: {
query: /* GraphQL */ `
query GetProductSubcategories($categoryid: bigint!) {
app_subcategory(where: { categoryid: { _eq: $categoryid } }) {
subcategoryid
subcategoryname
}
}
`,
variables: `{\n "categoryid": 1001\n}`,
},
getmobileappcategories: {
query: /* GraphQL */ `
query GetAppCategories {
app_category {
categoryid
categoryname
}
}
`,
variables: `{}`,
},
getmobileproductvariants: {
query: /* GraphQL */ `
query GetProductVariants($tenantid: bigint!, $subcategoryid: bigint!) {
product_variants(where: { tenantid: { _eq: $tenantid }, subcategoryid: { _eq: $subcategoryid } }) {
variantid
productname
price
}
}
`,
variables: `{\n "tenantid": 1087,\n "subcategoryid": 14\n}`,
},
gettenantpromotions: {
query: /* GraphQL */ `
query GetTenantPromotions($tenantid: bigint!, $locationid: bigint!) {
promotions(where: { tenantid: { _eq: $tenantid }, locationid: { _eq: $locationid } }) {
promotionid
title
}
}
`,
variables: `{\n "tenantid": 1087,\n "locationid": 1\n}`,
},
getappconfig: {
query: /* GraphQL */ `
query GetAppConfig($configid: bigint!) {
app_config(where: { configid: { _eq: $configid } }) {
configkey
configvalue
}
}
`,
variables: `{\n "configid": 15\n}`,
},
searchcustomers: {
query: /* GraphQL */ `
query SearchCustomers($tenantid: bigint!, $keyword: String!) {
customers(where: { tenantid: { _eq: $tenantid }, name: { _ilike: $keyword } }) {
customerid
name
}
}
`,
variables: `{\n "tenantid": 1087,\n "keyword": "%john%"\n}`,
},
gettenantorders: {
query: /* GraphQL */ `
query GetTenantOrders {
orders {
orderid
tenantid
}
}
`,
variables: `{}`,
},
getstaff: {
query: /* GraphQL */ `
query GetStaff($tenantid: bigint!) {
staff(where: { tenantid: { _eq: $tenantid } }) {
staffid
name
}
}
`,
variables: `{\n "tenantid": 1087\n}`,
},
getmobileapplocations: {
query: /* GraphQL */ `
query GetAppLocations {
app_location {
applocationid
locationname
}
}
`,
variables: `{}`,
},
};
export function getGraphQLKey(endpointName) {
if (!endpointName) return '';
const name = endpointName.toLowerCase().replace(/\s+/g, '').replace(/[\(\)]/g, '');
const map = {
'getuserroles': 'getapproles',
'getsubcategories': 'getsubcategory',
'getallusers': 'getusers',
'getusersinfo': 'getusers',
'getlocationsbyuser': 'gettenantlocations',
'gettenantlocations': 'gettenantlocations',
'getalltenants': 'gettenantinfo',
'gettenants': 'gettenantinfo',
'gettenantsummary': 'getordersummary',
'getpricinglist': 'getallpricing',
'tenantsearch': 'searchcustomers',
'getallriders': 'getriderdetail',
'getallridersummary': 'getridershifts',
'getorderdetails': 'getorders',
'getlocationsummary': 'gettenantlocations',
'getpaymentrequest': 'getinvoices'
};
return map[name] || name;
}
export function normalizeAndGetMeta(endpointName) {
const key = getGraphQLKey(endpointName);
return graphqlMeta[key] || null;
}