@accounter-toolkit/green-invoice-graphql
Version:
Graphql proxy for Green Invoice API
636 lines (635 loc) • 16.8 kB
JavaScript
import { gql } from '@graphql-mesh/utils';
import { PubSub } from '@graphql-mesh/utils';
import { DefaultLogger } from '@graphql-mesh/utils';
import MeshCache from "@graphql-mesh/cache-localforage";
import { fetch as fetchFn } from '@whatwg-node/fetch';
import JsonSchemaHandler from "@graphql-mesh/json-schema";
import BareMerger from "@graphql-mesh/merger-bare";
import { createMeshHTTPHandler } from '@graphql-mesh/http';
import { getMesh } from '@graphql-mesh/runtime';
import { MeshStore, FsStoreStorageAdapter } from '@graphql-mesh/store';
import { path as pathModule } from '@graphql-mesh/cross-helpers';
import * as importedModule$0 from "./sources/GreenInvoice/schemaWithAnnotations.js";
import { fileURLToPath } from '@graphql-mesh/utils';
const baseDir = pathModule.join(pathModule.dirname(fileURLToPath(import.meta.url)), '..');
const importFn = (moduleId) => {
const relativeModuleId = (pathModule.isAbsolute(moduleId) ? pathModule.relative(baseDir, moduleId) : moduleId).split('\\').join('/').replace(baseDir + '/', '');
switch (relativeModuleId) {
case "mesh-artifacts/sources/GreenInvoice/schemaWithAnnotations.js":
return Promise.resolve(importedModule$0);
default:
return Promise.reject(new Error(`Cannot find module '${relativeModuleId}'.`));
}
};
const rootStore = new MeshStore('mesh-artifacts', new FsStoreStorageAdapter({
cwd: baseDir,
importFn,
fileType: "js",
}), {
readonly: true,
validate: false
});
export const rawServeConfig = { "browser": false };
export async function getMeshOptions() {
const pubsub = new PubSub();
const sourcesStore = rootStore.child('sources');
const logger = new DefaultLogger("🕸️ Mesh");
const cache = new MeshCache({
...{},
importFn,
store: rootStore.child('cache'),
pubsub,
logger,
});
const sources = [];
const transforms = [];
const additionalEnvelopPlugins = [];
const greenInvoiceTransforms = [];
const additionalTypeDefs = [];
const greenInvoiceHandler = new JsonSchemaHandler({
name: "GreenInvoice",
config: { "endpoint": "https://api.greeninvoice.co.il/api/v1", "operationHeaders": { "Authorization": "Bearer {context.authToken}", "Content-Type": "application/json" }, "operations": [{ "type": "Mutation", "field": "addExpense", "path": "/expenses", "method": "POST", "requestSchema": "../json-schemas/greenInvoice.json#/definitions/addExpenseRequest", "responseSchema": "../json-schemas/greenInvoice.json#/definitions/addExpenseResponse" }, { "type": "Query", "field": "getExpense", "path": "/expenses/{args.id}", "method": "GET", "argTypeMap": { "id": { "type": "string", "nullable": false } }, "responseSchema": "../json-schemas/greenInvoice.json#/definitions/getExpenseResponse" }, { "type": "Mutation", "field": "updateExpense", "path": "/expenses/{args.id}", "method": "PUT", "requestSchema": "../json-schemas/greenInvoice.json#/definitions/updateExpenseRequest", "responseSchema": "../json-schemas/greenInvoice.json#/definitions/updateExpenseResponse" }, { "type": "Query", "field": "searchExpenses", "path": "/expenses/search", "method": "POST", "requestSchema": "../json-schemas/greenInvoice.json#/definitions/searchExpensesRequest", "responseSchema": "../json-schemas/greenInvoice.json#/definitions/searchExpensesResponse" }, { "type": "Query", "field": "searchDocuments", "path": "/documents/search", "method": "POST", "requestSchema": "../json-schemas/greenInvoice.json#/definitions/searchDocumentsRequest", "responseSchema": "../json-schemas/greenInvoice.json#/definitions/searchDocumentsResponse" }, { "type": "Mutation", "field": "addExpenseDraftByFile", "path": "/expenses/file", "method": "POST", "requestSchema": "../json-schemas/greenInvoice.json#/definitions/addExpenseDraftByFileRequest", "responseByStatusCode": { "200": { "responseSchema": "../json-schemas/greenInvoice.json#/definitions/addExpenseDraftByFileResponse" }, "201": { "responseSchema": "../json-schemas/greenInvoice.json#/definitions/addExpenseDraftByFileResponse" }, "400": { "responseSchema": "../json-schemas/greenInvoice.json#/definitions/generalErrorResponse" }, "404": { "responseSchema": "../json-schemas/greenInvoice.json#/definitions/generalErrorResponse" } } }, { "type": "Query", "field": "searchExpenseDrafts", "path": "/expenses/drafts/search", "method": "POST", "requestSchema": "../json-schemas/greenInvoice.json#/definitions/searchExpenseDraftsRequest", "responseByStatusCode": { "200": { "responseSchema": "../json-schemas/greenInvoice.json#/definitions/searchExpenseDraftsResponse" }, "201": { "responseSchema": "../json-schemas/greenInvoice.json#/definitions/searchExpenseDraftsResponse" }, "404": { "responseSchema": "../json-schemas/greenInvoice.json#/definitions/generalErrorResponse" } } }] },
baseDir,
cache,
pubsub,
store: sourcesStore.child("GreenInvoice"),
logger: logger.child("GreenInvoice"),
importFn,
});
sources[0] = {
name: 'GreenInvoice',
handler: greenInvoiceHandler,
transforms: greenInvoiceTransforms
};
const additionalResolvers = [];
const merger = new BareMerger({
cache,
pubsub,
logger: logger.child('bareMerger'),
store: rootStore.child('bareMerger')
});
return {
sources,
transforms,
additionalTypeDefs,
additionalResolvers,
cache,
pubsub,
merger,
logger,
additionalEnvelopPlugins,
get documents() {
return [];
},
fetchFn,
};
}
export function createBuiltMeshHTTPHandler() {
return createMeshHTTPHandler({
baseDir,
getBuiltMesh: getBuiltMesh,
rawServeConfig: { "browser": false },
});
}
let meshInstance$;
export function getBuiltMesh() {
if (meshInstance$ == null) {
meshInstance$ = getMeshOptions().then(meshOptions => getMesh(meshOptions)).then(mesh => {
const id = mesh.pubsub.subscribe('destroy', () => {
meshInstance$ = undefined;
mesh.pubsub.unsubscribe(id);
});
return mesh;
});
}
return meshInstance$;
}
export const execute = (...args) => getBuiltMesh().then(({ execute }) => execute(...args));
export const subscribe = (...args) => getBuiltMesh().then(({ subscribe }) => subscribe(...args));
export function getMeshSDK(globalContext) {
const sdkRequester$ = getBuiltMesh().then(({ sdkRequesterFactory }) => sdkRequesterFactory(globalContext));
return getSdk((...args) => sdkRequester$.then(sdkRequester => sdkRequester(...args)));
}
export const getExpense_queryDocument = gql `
query getExpense_query($id: String!) {
getExpense(id: $id) {
id
businessType
documentType
status
paymentType
currency
currencyRate
amountExcludeVat
vat
amount
date
dueDate
number
active
description
remarks
supplier {
id
name
active
taxId
paymentTerms
bankName
bankBranch
bankAccount
country
phone
mobile
contactPerson
emails
labels
creationDate
lastUpdateDate
department
accountingKey
address
city
zip
fax
remarks
incomeAmount
paymentAmount
balanceAmount
}
thumbnail
url
cancellable
reportingDate
accountingClassification {
id
key
code
title
irsCode
income
type
vat
}
amountLocal
amountAccounting
vatAccounting
creationDate
lastUpdateDate
}
}
`;
export const searchExpenses_queryDocument = gql `
query searchExpenses_query($input: searchExpensesRequest_Input) {
searchExpenses(input: $input) {
total
page
pageSize
pages
items {
id
businessType
documentType
status
paymentType
currency
currencyRate
amountExcludeVat
vat
amount
date
dueDate
number
active
description
remarks
supplier {
id
name
active
taxId
paymentTerms
bankName
bankBranch
bankAccount
country
phone
mobile
contactPerson
emails
labels
creationDate
lastUpdateDate
department
accountingKey
address
city
zip
fax
remarks
incomeAmount
paymentAmount
balanceAmount
}
thumbnail
url
cancellable
reportingDate
accountingClassification {
id
key
code
title
irsCode
income
type
vat
}
amountLocal
amountAccounting
vatAccounting
creationDate
lastUpdateDate
}
}
}
`;
export const searchDocuments_queryDocument = gql `
query searchDocuments_query($input: searchDocumentsRequest_Input) {
searchDocuments(input: $input) {
total
page
pageSize
pages
items {
amount
amountDueVat
amountExcludedVat
amountExemptVat
amountLocal
amountOpened
business {
accountantDocsEmailSettings
accountantEmails
accountantReportEmailSettings
accountingType
active
advanceNationalInsuranceRate
advanceTaxRate
bankDisplay
bankDisplayEn
deductionRate
documentsEmailSettings
emailSubjectType
exemption
incomeReportEmailSettings
incomeReportFormatType
reportSendingDay
senderEmailSettings
type
}
calculatedAmountLocal
calculatedAmountOpenedLocal
calculatedIncomeAmountExcludeLocal
calculatedIncomeAmountLocal
calculatedPaymentAmountLocal
cancellable
cancelType
client {
country
emails
id
name
phone
taxId
self
}
creationDate
currency
currencyRate
data {
tags
}
description
documentDate
downloaded
id
income {
amount
amountTotal
catalogNum
currency
currencyRate
description
itemId
price
quantity
vat
vatRate
vatType
}
lang
number
payment {
amount
cancellable
currency
currencyRate
date
description
name
price
ref
type
subType
}
ref
remarks
reverseCharge
rounding
signed
skinId
status
templateId
type
url {
he
en
origin
}
vat
vatRate
vatType
}
}
}
`;
export const searchExpenseDrafts_queryDocument = gql `
query searchExpenseDrafts_query($input: searchExpenseDraftsRequest_Input) {
searchExpenseDrafts(input: $input) {
... on searchExpenseDraftsResponse {
total
page
pageSize
pages
items {
currency
currencyRate
vat
amount
description
supplier {
id
name
active
taxId
paymentTerms
bankName
bankBranch
bankAccount
country
phone
mobile
contactPerson
emails
labels
creationDate
lastUpdateDate
department
accountingKey
address
city
zip
fax
remarks
incomeAmount
paymentAmount
balanceAmount
}
fileHash
fileKey
}
}
... on generalErrorResponse {
errorCode_
errorMessage
}
}
}
`;
export const addExpense_mutationDocument = gql `
mutation addExpense_mutation($input: Expense_Input) {
addExpense(input: $input) {
... on Expense {
paymentType {
... on Boolean_container {
Boolean
}
... on mutation_addExpense_oneOf_0_allOf_0_paymentType_oneOf_1_container {
mutation_addExpense_oneOf_0_allOf_0_paymentType_oneOf_1
}
}
currency
currencyRate
vat
amount
date
dueDate
reportingDate
documentType
number
description
remarks
supplier
accountingClassification
active
addRecipient
addAccountingClassification
}
... on ErrorResponse {
errorCode
errorMessage
}
}
}
`;
export const updateExpense_mutationDocument = gql `
mutation updateExpense_mutation($id: String, $input: updateExpenseRequest_Input) {
updateExpense(id: $id, input: $input) {
... on GetExpense {
id
businessType
documentType
status
paymentType
currency
currencyRate
amountExcludeVat
vat
amount
date
dueDate
number
active
description
remarks
supplier {
id
name
active
taxId
paymentTerms
bankName
bankBranch
bankAccount
country
phone
mobile
contactPerson
emails
labels
creationDate
lastUpdateDate
department
accountingKey
address
city
zip
fax
remarks
incomeAmount
paymentAmount
balanceAmount
}
thumbnail
url
cancellable
reportingDate
accountingClassification {
id
key
code
title
irsCode
income
type
vat
}
amountLocal
amountAccounting
vatAccounting
creationDate
lastUpdateDate
}
... on ErrorResponse {
errorCode
errorMessage
}
}
}
`;
export const addExpenseDraftByFile_mutationDocument = gql `
mutation addExpenseDraftByFile_mutation($input: addExpenseDraftByFileRequest_Input) {
addExpenseDraftByFile(input: $input) {
... on GetExpenseDraft {
id
status
creationDate
lastUpdateDate
expense {
paymentType {
... on Boolean_container {
Boolean
}
... on mutation_addExpense_oneOf_0_allOf_0_paymentType_oneOf_1_container {
mutation_addExpense_oneOf_0_allOf_0_paymentType_oneOf_1
}
}
currency
currencyRate
vat
amount
date
dueDate
reportingDate
documentType
number
description
remarks
supplier {
id
name
active
taxId
paymentTerms
bankName
bankBranch
bankAccount
country
phone
mobile
contactPerson
emails
labels
creationDate
lastUpdateDate
department
accountingKey
address
city
zip
fax
remarks
incomeAmount
paymentAmount
balanceAmount
}
accountingClassification {
id
key
code
title
irsCode
income
type
vat
}
active
addRecipient
addAccountingClassification
}
thumbnail
url
}
... on generalErrorResponse {
errorCode_
errorMessage
}
}
}
`;
export function getSdk(requester) {
return {
getExpense_query(variables, options) {
return requester(getExpense_queryDocument, variables, options);
},
searchExpenses_query(variables, options) {
return requester(searchExpenses_queryDocument, variables, options);
},
searchDocuments_query(variables, options) {
return requester(searchDocuments_queryDocument, variables, options);
},
searchExpenseDrafts_query(variables, options) {
return requester(searchExpenseDrafts_queryDocument, variables, options);
},
addExpense_mutation(variables, options) {
return requester(addExpense_mutationDocument, variables, options);
},
updateExpense_mutation(variables, options) {
return requester(updateExpense_mutationDocument, variables, options);
},
addExpenseDraftByFile_mutation(variables, options) {
return requester(addExpenseDraftByFile_mutationDocument, variables, options);
}
};
}