77// import { SchemaComposer } from 'graphql-compose';
88// const schemaComposer = new SchemaComposer();
99
10- import { schemaComposer , composeWithRelay , Resolver } from './schemaComposer' ;
10+ import { schemaComposer , composeWithRelay } from './schemaComposer' ;
1111import { CategoryTC } from './models/category' ;
1212import { CustomerTC } from './models/customer' ;
1313import { EmployeeTC } from './models/employee' ;
@@ -16,7 +16,10 @@ import { ProductTC } from './models/product';
1616import { RegionTC } from './models/region' ;
1717import { ShipperTC } from './models/shipper' ;
1818import { SupplierTC } from './models/supplier' ;
19- import allowOnlyForLocalhost from './auth/allowOnlyForLocalhost' ;
19+ // import { allowOnlyForLocalhost } from './wrappers/allowOnlyForLocalhost';
20+ import { addQueryToPayload } from './wrappers/addQueryToPayload' ;
21+ import { autoResetDataIn30min } from './wrappers/autoResetDataIn30min' ;
22+ import seed from './data/seed' ;
2023
2124composeWithRelay ( schemaComposer . Query ) ;
2225
@@ -63,7 +66,8 @@ const fields = {
6366ViewerTC . addFields ( fields ) ;
6467
6568schemaComposer . Mutation . addFields ( {
66- ...allowOnlyForLocalhost ( {
69+ // ...allowOnlyForLocalhost({
70+ ...autoResetDataIn30min ( {
6771 ...addQueryToPayload ( {
6872 createProduct : ProductTC . getResolver ( 'createOne' ) ,
6973 updateProduct : ProductTC . getResolver ( 'updateById' ) ,
@@ -76,16 +80,15 @@ schemaComposer.Mutation.addFields({
7680 updateEmployee : EmployeeTC . getResolver ( 'updateById' ) ,
7781 } ) ,
7882 } ) ,
83+ resetData : {
84+ type : 'String' ,
85+ description :
86+ 'Remove all data and seed DB from scratch. Anyway data automatically reloaded every 30 minutes.' ,
87+ resolve : async ( ) => {
88+ await seed ( ) ;
89+ return 'Success' ;
90+ } ,
91+ } ,
7992} ) ;
8093
81- function addQueryToPayload ( resolvers : { [ name : string ] : Resolver < any , any , any > } ) {
82- Object . keys ( resolvers ) . forEach ( ( k ) => {
83- resolvers [ k ] . getOTC ( ) . setField ( 'query' , {
84- type : 'Query' ,
85- resolve : ( ) => ( { } ) ,
86- } ) ;
87- } ) ;
88- return resolvers ;
89- }
90-
9194export default schemaComposer . buildSchema ( ) ;
0 commit comments