This repository has been archived by the owner on May 6, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from Tolfix/dev
v1.3
- Loading branch information
Showing
69 changed files
with
709 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { ApolloServer } from 'apollo-server-express'; | ||
import { JWT_Access_Token } from '../../Config'; | ||
import SchemaPoser from './SchemaPoser'; | ||
import jwt from "jsonwebtoken"; | ||
import bcrypt from "bcryptjs"; | ||
import { CacheAdmin, getAdminByUsername } from '../../Cache/CacheAdmin'; | ||
|
||
export default async (server: any) => | ||
{ | ||
|
||
const apolloServer = new ApolloServer({ | ||
schema: SchemaPoser, | ||
context: async ({ req, res }) => { | ||
|
||
const authHeader = req.headers['authorization']; | ||
if(!authHeader) | ||
return { | ||
isAuth: false, | ||
} | ||
|
||
const b64auth = (authHeader).split(' '); | ||
|
||
if(!b64auth[0].toLocaleLowerCase().match(/basic|bearer/g)) | ||
return { | ||
isAuth: false, | ||
} | ||
|
||
if(!b64auth[1]) | ||
return { | ||
isAuth: false, | ||
} | ||
|
||
if(b64auth[0].toLocaleLowerCase() === "basic") | ||
{ | ||
// Check if buffer, or base64 | ||
let [login, password] = (Buffer.isBuffer(b64auth[1]) ? Buffer.from(b64auth[1], 'base64') : b64auth[1]).toString().split(':'); | ||
if(login.includes("==") || password.includes("==")) | ||
{ | ||
login = atob(login); | ||
password = login.split(":")[1]; | ||
login = login.split(":")[0]; | ||
} | ||
|
||
// Check if admin | ||
if(CacheAdmin.has(getAdminByUsername(login) ?? "ADM_")) | ||
{ | ||
let succeed = await bcrypt.compare(password, (CacheAdmin.get(getAdminByUsername(login) ?? "ADM_")?.["password"] ?? "")); | ||
|
||
if(!succeed) | ||
return { | ||
isAuth: false, | ||
} | ||
} | ||
} | ||
|
||
if(b64auth[0].toLocaleLowerCase() === "bearer") | ||
{ | ||
const token = (Buffer.isBuffer(b64auth[1]) ? Buffer.from(b64auth[1], 'base64') : b64auth[1]).toString(); | ||
jwt.verify(token, JWT_Access_Token, (err, payload) => { | ||
if(err || !payload) | ||
return { | ||
isAuth: false, | ||
} | ||
|
||
|
||
return { | ||
isAuth: true, | ||
} | ||
}); | ||
} | ||
|
||
return { | ||
isAuth: false, | ||
} | ||
}, | ||
}); | ||
|
||
await apolloServer.start(); | ||
|
||
apolloServer.applyMiddleware({ | ||
app: server, | ||
path: "/graphql", | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { SchemaComposer } from 'graphql-compose'; | ||
import fs from "fs"; | ||
import { HomeDir } from '../../Config'; | ||
import Logger from '../../Lib/Logger'; | ||
|
||
const schemaComposer = new SchemaComposer(); | ||
|
||
// Go through each in ./Schemas/*.js files and add them to schemaComposer | ||
Logger.info("Loading GraphQL schemas..."); | ||
let schemaDir = HomeDir+"/build/Database/GraphQL/Schemas"; | ||
const files = fs.readdirSync(`${schemaDir}`).filter((f) => f.endsWith('.js')); | ||
for(let f of files) | ||
{ | ||
|
||
// Now we require the file. | ||
const schema = require(`${schemaDir}/${f}`); | ||
// Get the schema.startsWith | ||
const name = schema.startsWith; | ||
if(!name) | ||
continue; | ||
|
||
// Now get schame[`${name}Query`] and schema[`${name}Mutation`] | ||
const query = schema[`${name}Query`]; | ||
const mutation = schema[`${name}Mutation`]; | ||
|
||
// Add the query and mutation to the schemaComposer | ||
if(query) | ||
schemaComposer.Query.addFields(query); | ||
if(mutation) | ||
schemaComposer.Mutation.addFields(mutation); | ||
|
||
continue; | ||
} | ||
|
||
// Lets create the schema | ||
export default schemaComposer.buildSchema(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { composeWithMongoose } from "graphql-compose-mongoose"; | ||
import CategoryModel from "../../Models/Category"; | ||
|
||
const CategoriesGraphQL = composeWithMongoose(CategoryModel); | ||
export const startsWith = "Categories"; | ||
export const CategoriesQuery = { | ||
categoryById: CategoriesGraphQL.getResolver("findById"), | ||
categoryByIds: CategoriesGraphQL.getResolver("findByIds"), | ||
categoryOne: CategoriesGraphQL.getResolver("findOne"), | ||
categoryMany: CategoriesGraphQL.getResolver("findMany"), | ||
categoryCount: CategoriesGraphQL.getResolver("count"), | ||
categoryConnection: CategoriesGraphQL.getResolver("connection"), | ||
categoryPagination: CategoriesGraphQL.getResolver("pagination"), | ||
} | ||
|
||
export const CategoriesMutation = { | ||
categoryCreateOne: CategoriesGraphQL.getResolver("createOne"), | ||
categoryCreateMany: CategoriesGraphQL.getResolver("createMany"), | ||
categoryUpdateById: CategoriesGraphQL.getResolver("updateById"), | ||
categoryUpdateOne: CategoriesGraphQL.getResolver("updateOne"), | ||
categoryUpdateMany: CategoriesGraphQL.getResolver("updateMany"), | ||
categoryRemoveById: CategoriesGraphQL.getResolver("removeById"), | ||
categoryRemoveOne: CategoriesGraphQL.getResolver("removeOne"), | ||
categoryRemoveMany: CategoriesGraphQL.getResolver("removeMany"), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { composeWithMongoose } from "graphql-compose-mongoose"; | ||
import ConfigurableOptionsModel from "../../Models/ConfigurableOptions"; | ||
|
||
const ConfigurableOptionsGraphQL = composeWithMongoose(ConfigurableOptionsModel); | ||
export const startsWith = "ConfigurableOptions"; | ||
export const ConfigurableOptionsQuery = { | ||
configurableOptionsById: ConfigurableOptionsGraphQL.getResolver("findById"), | ||
configurableOptionsByIds: ConfigurableOptionsGraphQL.getResolver("findByIds"), | ||
configurableOptionsOne: ConfigurableOptionsGraphQL.getResolver("findOne"), | ||
configurableOptionsMany: ConfigurableOptionsGraphQL.getResolver("findMany"), | ||
configurableOptionsCount: ConfigurableOptionsGraphQL.getResolver("count"), | ||
configurableOptionsConnection: ConfigurableOptionsGraphQL.getResolver("connection"), | ||
configurableOptionsPagination: ConfigurableOptionsGraphQL.getResolver("pagination"), | ||
} | ||
|
||
export const ConfigurableOptionsMutation = { | ||
configurableOptionsCreateOne: ConfigurableOptionsGraphQL.getResolver("createOne"), | ||
configurableOptionsCreateMany: ConfigurableOptionsGraphQL.getResolver("createMany"), | ||
configurableOptionsUpdateById: ConfigurableOptionsGraphQL.getResolver("updateById"), | ||
configurableOptionsUpdateOne: ConfigurableOptionsGraphQL.getResolver("updateOne"), | ||
configurableOptionsUpdateMany: ConfigurableOptionsGraphQL.getResolver("updateMany"), | ||
configurableOptionsRemoveById: ConfigurableOptionsGraphQL.getResolver("removeById"), | ||
configurableOptionsRemoveOne: ConfigurableOptionsGraphQL.getResolver("removeOne"), | ||
configurableOptionsRemoveMany: ConfigurableOptionsGraphQL.getResolver("removeMany"), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { composeWithMongoose } from "graphql-compose-mongoose"; | ||
import CustomerModel from "../../Models/Customers/Customer"; | ||
|
||
const CustomersGraphQL = composeWithMongoose(CustomerModel); | ||
export const startsWith = "Customers"; | ||
export const CustomersQuery = { | ||
customerById: CustomersGraphQL.getResolver("findById"), | ||
customerByIds: CustomersGraphQL.getResolver("findByIds"), | ||
customerOne: CustomersGraphQL.getResolver("findOne"), | ||
customerMany: CustomersGraphQL.getResolver("findMany"), | ||
customerCount: CustomersGraphQL.getResolver("count"), | ||
customerConnection: CustomersGraphQL.getResolver("connection"), | ||
customerPagination: CustomersGraphQL.getResolver("pagination"), | ||
} | ||
|
||
export const CustomersMutation = { | ||
customerCreateOne: CustomersGraphQL.getResolver("createOne"), | ||
customerCreateMany: CustomersGraphQL.getResolver("createMany"), | ||
customerUpdateById: CustomersGraphQL.getResolver("updateById"), | ||
customerUpdateOne: CustomersGraphQL.getResolver("updateOne"), | ||
customerUpdateMany: CustomersGraphQL.getResolver("updateMany"), | ||
customerRemoveById: CustomersGraphQL.getResolver("removeById"), | ||
customerRemoveOne: CustomersGraphQL.getResolver("removeOne"), | ||
customerRemoveMany: CustomersGraphQL.getResolver("removeMany"), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { composeWithMongoose } from "graphql-compose-mongoose"; | ||
import invoiceModel from "../../Models/Invoices"; | ||
|
||
const InvoicesGraphQL = composeWithMongoose(invoiceModel); | ||
export const startsWith = "Invoices"; | ||
export const InvoicesQuery = { | ||
invoiceById: InvoicesGraphQL.getResolver("findById"), | ||
invoiceByIds: InvoicesGraphQL.getResolver("findByIds"), | ||
invoiceOne: InvoicesGraphQL.getResolver("findOne"), | ||
invoiceMany: InvoicesGraphQL.getResolver("findMany"), | ||
invoiceCount: InvoicesGraphQL.getResolver("count"), | ||
invoiceConnection: InvoicesGraphQL.getResolver("connection"), | ||
invoicePagination: InvoicesGraphQL.getResolver("pagination"), | ||
} | ||
|
||
export const InvoicesMutation = { | ||
invoiceCreateOne: InvoicesGraphQL.getResolver("createOne"), | ||
invoiceCreateMany: InvoicesGraphQL.getResolver("createMany"), | ||
invoiceUpdateById: InvoicesGraphQL.getResolver("updateById"), | ||
invoiceUpdateOne: InvoicesGraphQL.getResolver("updateOne"), | ||
invoiceUpdateMany: InvoicesGraphQL.getResolver("updateMany"), | ||
invoiceRemoveById: InvoicesGraphQL.getResolver("removeById"), | ||
invoiceRemoveOne: InvoicesGraphQL.getResolver("removeOne"), | ||
invoiceRemoveMany: InvoicesGraphQL.getResolver("removeMany"), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { composeWithMongoose } from "graphql-compose-mongoose"; | ||
import OrdersModel from "../../Models/Orders"; | ||
|
||
const OrderGraphQL = composeWithMongoose(OrdersModel); | ||
export const startsWith = "Order"; | ||
export const OrderQuery = { | ||
ordersById: OrderGraphQL.getResolver("findById"), | ||
ordersByIds: OrderGraphQL.getResolver("findByIds"), | ||
ordersOne: OrderGraphQL.getResolver("findOne"), | ||
ordersMany: OrderGraphQL.getResolver("findMany"), | ||
ordersCount: OrderGraphQL.getResolver("count"), | ||
ordersConnection: OrderGraphQL.getResolver("connection"), | ||
ordersPagination: OrderGraphQL.getResolver("pagination"), | ||
} | ||
|
||
export const OrderMutation = { | ||
ordersCreateOne: OrderGraphQL.getResolver("createOne"), | ||
ordersCreateMany: OrderGraphQL.getResolver("createMany"), | ||
ordersUpdateById: OrderGraphQL.getResolver("updateById"), | ||
ordersUpdateOne: OrderGraphQL.getResolver("updateOne"), | ||
ordersUpdateMany: OrderGraphQL.getResolver("updateMany"), | ||
ordersRemoveById: OrderGraphQL.getResolver("removeById"), | ||
ordersRemoveOne: OrderGraphQL.getResolver("removeOne"), | ||
ordersRemoveMany: OrderGraphQL.getResolver("removeMany"), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { composeWithMongoose } from "graphql-compose-mongoose"; | ||
import ProductsModel from "../../Models/Products"; | ||
|
||
const ProductsGraphQL = composeWithMongoose(ProductsModel); | ||
export const startsWith = "Products"; | ||
export const ProductsQuery = { | ||
productById: ProductsGraphQL.getResolver("findById"), | ||
productByIds: ProductsGraphQL.getResolver("findByIds"), | ||
productOne: ProductsGraphQL.getResolver("findOne"), | ||
productMany: ProductsGraphQL.getResolver("findMany"), | ||
productCount: ProductsGraphQL.getResolver("count"), | ||
productConnection: ProductsGraphQL.getResolver("connection"), | ||
productPagination: ProductsGraphQL.getResolver("pagination"), | ||
} | ||
|
||
export const ProductsMutation = { | ||
productCreateOne: ProductsGraphQL.getResolver("createOne"), | ||
productCreateMany: ProductsGraphQL.getResolver("createMany"), | ||
productUpdateById: ProductsGraphQL.getResolver("updateById"), | ||
productUpdateOne: ProductsGraphQL.getResolver("updateOne"), | ||
productUpdateMany: ProductsGraphQL.getResolver("updateMany"), | ||
productRemoveById: ProductsGraphQL.getResolver("removeById"), | ||
productRemoveOne: ProductsGraphQL.getResolver("removeOne"), | ||
productRemoveMany: ProductsGraphQL.getResolver("removeMany"), | ||
}; |
Oops, something went wrong.