seems merged
This commit is contained in:
+17
-11
@@ -2,11 +2,12 @@ import { Component, OnInit } from '@angular/core';
|
||||
import { GenericRestDataSourceService } from 'projects/poweredsoft/ngx-data/src/public-api';
|
||||
import { of, Observable } from 'rxjs';
|
||||
import { DataSource, IResolveCommandModelEvent } from '@poweredsoft/data';
|
||||
import { GraphQLDataSourceService } from 'projects/poweredsoft/ngx-data-apollo/src/public-api';
|
||||
import { } from 'projects/poweredsoft/ngx-data-apollo/src/public-api';
|
||||
import { Apollo } from 'apollo-angular';
|
||||
import gql from 'graphql-tag';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { DocumentNode } from 'graphql';
|
||||
import { GraphQLDataSourceService, IGraphQLAdvanceQueryInput } from 'projects/poweredsoft/ngx-data-apollo/src/public-api';
|
||||
|
||||
|
||||
export interface IContact {
|
||||
@@ -15,7 +16,7 @@ export interface IContact {
|
||||
lastName: string;
|
||||
}
|
||||
|
||||
export interface ICustomerModel {
|
||||
export interface IContactModel {
|
||||
id: number;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
@@ -26,6 +27,11 @@ export interface IFooCommand {
|
||||
comment: string;
|
||||
}
|
||||
|
||||
export interface IContactDetailQuery extends IGraphQLAdvanceQueryInput<IContactModel>
|
||||
{
|
||||
sex?: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
templateUrl: './app.component.html',
|
||||
@@ -33,14 +39,14 @@ export interface IFooCommand {
|
||||
})
|
||||
export class AppComponent implements OnInit {
|
||||
title = 'ngx-data';
|
||||
dataSource: DataSource<ICustomerModel>;
|
||||
dataSource: DataSource<IContactModel>;
|
||||
|
||||
constructor(genericService: GenericRestDataSourceService, private apollo: Apollo, private graphQLService: GraphQLDataSourceService) {
|
||||
const keyResolver = (model: ICustomerModel) => model.id;
|
||||
const keyResolver = (model: IContactModel) => model.id;
|
||||
|
||||
const transportOptions = genericService.createStandardRestTransportOptions('api/customer', keyResolver);
|
||||
|
||||
this.dataSource = new DataSource<ICustomerModel>({
|
||||
this.dataSource = new DataSource<IContactModel>({
|
||||
resolveIdField: keyResolver,
|
||||
transport: transportOptions,
|
||||
defaultCriteria: {
|
||||
@@ -151,17 +157,13 @@ export class AppComponent implements OnInit {
|
||||
}
|
||||
|
||||
testGraphQL() {
|
||||
|
||||
const builder = this.graphQLService.createDataSourceOptionsBuilder<IContact, number>(
|
||||
'contacts',
|
||||
'GraphQLAdvanceQueryOfContactModelInput',
|
||||
'ContactDetailQueryInput',
|
||||
'id firstName lastName',
|
||||
(m) => m.id,
|
||||
{
|
||||
groups: [
|
||||
{
|
||||
path: 'sex'
|
||||
}
|
||||
],
|
||||
aggregates: [
|
||||
{
|
||||
path: 'id',
|
||||
@@ -171,6 +173,10 @@ export class AppComponent implements OnInit {
|
||||
}
|
||||
);
|
||||
|
||||
builder.beforeRead<IContactDetailQuery>(query => {
|
||||
return of({ ...query, sex: "Male"});
|
||||
});
|
||||
|
||||
const dataSourceOptions = builder.create();
|
||||
const dataSource = new DataSource<IContact>(dataSourceOptions);
|
||||
|
||||
|
||||
+20
-18
@@ -1,24 +1,26 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {ApolloModule, APOLLO_OPTIONS} from 'apollo-angular';
|
||||
import {ApolloModule, APOLLO_OPTIONS, Apollo} from 'apollo-angular';
|
||||
import {HttpLinkModule, HttpLink} from 'apollo-angular-link-http';
|
||||
import {InMemoryCache} from 'apollo-cache-inmemory';
|
||||
|
||||
const uri = 'http://localhost:5000/graphql'; // <-- add the URL of the GraphQL server here
|
||||
export function createApollo(httpLink: HttpLink) {
|
||||
return {
|
||||
link: httpLink.create({uri}),
|
||||
cache: new InMemoryCache(),
|
||||
};
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
exports: [ApolloModule, HttpLinkModule],
|
||||
providers: [
|
||||
{
|
||||
provide: APOLLO_OPTIONS,
|
||||
useFactory: createApollo,
|
||||
deps: [HttpLink],
|
||||
},
|
||||
],
|
||||
exports: [ApolloModule, HttpLinkModule]
|
||||
})
|
||||
export class GraphQLModule {}
|
||||
export class GraphQLModule {
|
||||
constructor(apollo: Apollo,
|
||||
httpLink: HttpLink)
|
||||
{
|
||||
const cache = new InMemoryCache();
|
||||
|
||||
const endpoint = "https://localhost:5001/graphql";
|
||||
apollo.create({
|
||||
link: httpLink.create({uri: endpoint}),
|
||||
cache,
|
||||
defaultOptions: {
|
||||
query: {
|
||||
fetchPolicy: 'network-only'
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user