add data source
This commit is contained in:
+52
-3
@@ -1,10 +1,49 @@
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { NgModule, APP_INITIALIZER } from '@angular/core';
|
||||
|
||||
import { AppRoutingModule } from './app-routing.module';
|
||||
import { AppComponent } from './app.component';
|
||||
import { HomeComponent } from './home/home.component';
|
||||
|
||||
import { Apollo, ApolloModule } from 'apollo-angular';
|
||||
import { HttpLink, HttpLinkModule } from 'apollo-angular-link-http';
|
||||
import { DefaultOptions } from 'apollo-client';
|
||||
import { InMemoryCache } from 'apollo-cache-inmemory';
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
|
||||
export function app_Init(apollo: Apollo, httpLink: HttpLink) {
|
||||
return async () => {
|
||||
const defaultOptions: DefaultOptions = {
|
||||
watchQuery: {
|
||||
fetchPolicy: 'no-cache',
|
||||
errorPolicy: 'ignore',
|
||||
},
|
||||
query: {
|
||||
fetchPolicy: 'network-only',
|
||||
errorPolicy: 'all',
|
||||
},
|
||||
mutate: {
|
||||
fetchPolicy: 'no-cache',
|
||||
},
|
||||
};
|
||||
|
||||
apollo.createDefault({
|
||||
link: httpLink.create({ uri: 'https://localhost:5001' }),
|
||||
cache: new InMemoryCache(),
|
||||
defaultOptions: defaultOptions,
|
||||
});
|
||||
|
||||
apollo.createNamed('command', {
|
||||
link: httpLink.create({ uri: 'https://localhost:6001' }),
|
||||
cache: new InMemoryCache(),
|
||||
defaultOptions: defaultOptions,
|
||||
});
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
@@ -14,9 +53,19 @@ import { HomeComponent } from './home/home.component';
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
AppRoutingModule
|
||||
AppRoutingModule,
|
||||
HttpClientModule,
|
||||
ApolloModule,
|
||||
HttpLinkModule
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: app_Init,
|
||||
deps: [Apollo, HttpLink],
|
||||
multi: true,
|
||||
},
|
||||
],
|
||||
providers: [],
|
||||
bootstrap: [AppComponent]
|
||||
})
|
||||
export class AppModule { }
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { GraphQLDataSourceService } from '@poweredsoft/ngx-data-apollo';
|
||||
import { IDataSource, DataSource } from '@poweredsoft/data';
|
||||
|
||||
export interface IMerchant{
|
||||
id: string,
|
||||
name: string,
|
||||
address: string
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MerchantService {
|
||||
|
||||
constructor(private dataSourceGenericService: GraphQLDataSourceService) {
|
||||
|
||||
dataSourceGenericService
|
||||
}
|
||||
|
||||
createMerchantDataSource() : IDataSource<IMerchant> {
|
||||
const optionsBuilder = this.dataSourceGenericService.createDataSourceOptionsBuilder<IMerchant, string>(
|
||||
'merchants',
|
||||
'GraphQLAdvanceQueryOfMerchantInput',
|
||||
'id, name, address',
|
||||
(model) => model.id,
|
||||
{
|
||||
page: 1,
|
||||
pageSize: 4
|
||||
},
|
||||
true
|
||||
);
|
||||
const options = optionsBuilder.create();
|
||||
return new DataSource<IMerchant>(options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user