data source options
This commit is contained in:
parent
0adaa73439
commit
44def3a9fc
@ -1,6 +1,6 @@
|
|||||||
import { IDataSourceOptions, IQueryCriteria, IDataSourceTransportOptions, IDataSourceQueryAdapterOptions, IDataSourceCommandAdapterOptions, IAdvanceQueryAdapter, IFilter, IAggregate, ISort, IGroup, ISimpleFilter, ICompositeFilter, IQueryExecutionGroupResult, IQueryExecutionResult, IAggregateResult } from '@poweredsoft/data';
|
import { IDataSourceOptions, IQueryCriteria, IDataSourceTransportOptions, IDataSourceQueryAdapterOptions, IDataSourceCommandAdapterOptions, IAdvanceQueryAdapter, IFilter, IAggregate, ISort, IGroup, ISimpleFilter, ICompositeFilter, IQueryExecutionGroupResult, IQueryExecutionResult, IAggregateResult, IGroupQueryResult } from '@poweredsoft/data';
|
||||||
import { Apollo } from 'apollo-angular';
|
import { Apollo } from 'apollo-angular';
|
||||||
import { IGraphQLAdvanceQueryResult, IGraphQLAdvanceQueryInput, IGraphQLAdvanceQueryFilterInput, IGraphQLAdvanceQueryAggregateInput, IGraphQLAdvanceQuerySortInput, IGraphQLAdvanceQueryGroupInput, FilterType, IGraphQLAdvanceQueryAggregateResult, IGraphQLVariantResult, AggregateType } from './models';
|
import { IGraphQLAdvanceQueryResult, IGraphQLAdvanceQueryInput, IGraphQLAdvanceQueryFilterInput, IGraphQLAdvanceQueryAggregateInput, IGraphQLAdvanceQuerySortInput, IGraphQLAdvanceQueryGroupInput, FilterType, IGraphQLAdvanceQueryAggregateResult, IGraphQLVariantResult, AggregateType, IGraphQLAdvanceGroupResult } from './models';
|
||||||
import gql from 'graphql-tag';
|
import gql from 'graphql-tag';
|
||||||
import { DocumentNode } from 'graphql';
|
import { DocumentNode } from 'graphql';
|
||||||
import { map, catchError } from 'rxjs/operators';
|
import { map, catchError } from 'rxjs/operators';
|
||||||
@ -63,17 +63,28 @@ export class GraphQLDataSourceOptionsBuilder<TModel, TKey> {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
private queryResultFromGraphQLAdvancedResult(query: IQueryCriteria, result: IGraphQLAdvanceQueryResult<TModel>): IQueryExecutionResult<TModel> | IQueryExecutionGroupResult<TModel> {
|
private queryResultFromGraphQLAdvancedResult(query: IQueryCriteria, result: IGraphQLAdvanceQueryResult<TModel>): IQueryExecutionResult<TModel> | IQueryExecutionGroupResult<TModel> {
|
||||||
if (query.groups && query.groups.length) {
|
|
||||||
throw 'todo';
|
const ret: IQueryExecutionGroupResult<TModel> & IQueryExecutionResult<TModel> = {
|
||||||
}
|
|
||||||
const ret: IQueryExecutionResult<TModel> = {
|
|
||||||
data: result.data,
|
data: result.data,
|
||||||
|
groups: result.groups ? result.groups.map(this.fromGraphQLGroupResult.bind(this)) : null,
|
||||||
totalRecords: result.totalRecords,
|
totalRecords: result.totalRecords,
|
||||||
numberOfPages: result.numberOfPages,
|
numberOfPages: result.numberOfPages,
|
||||||
aggregates: result.aggregates ? result.aggregates.map(this.fromGraphQLAggregateResult.bind(this)) : null
|
aggregates: result.aggregates ? result.aggregates.map(this.fromGraphQLAggregateResult.bind(this)) : null
|
||||||
};
|
};
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fromGraphQLGroupResult(group: IGraphQLAdvanceGroupResult<TModel>) : IGroupQueryResult<TModel> {
|
||||||
|
return {
|
||||||
|
aggregates: group.aggregates ? group.aggregates.map(this.convertAggregates.bind(this)) : null,
|
||||||
|
data: group.data,
|
||||||
|
groupPath: group.groupPath,
|
||||||
|
groupValue: this.getValueFromVariantResult(group.groupValue),
|
||||||
|
hasSubGroups: group.hasSubGroups,
|
||||||
|
subGroups: group.subGroups ? group.subGroups.map(this.fromGraphQLGroupResult.bind(this)) : null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private fromGraphQLAggregateResult(agg: IGraphQLAdvanceQueryAggregateResult): IAggregateResult {
|
private fromGraphQLAggregateResult(agg: IGraphQLAdvanceQueryAggregateResult): IAggregateResult {
|
||||||
return {
|
return {
|
||||||
path: agg.path,
|
path: agg.path,
|
||||||
@ -135,14 +146,7 @@ export class GraphQLDataSourceOptionsBuilder<TModel, TKey> {
|
|||||||
type
|
type
|
||||||
path
|
path
|
||||||
value {
|
value {
|
||||||
booleanValue
|
${this.createSelectVariant()}
|
||||||
dateTimeValue
|
|
||||||
decimalValue
|
|
||||||
intValue
|
|
||||||
json
|
|
||||||
longValue
|
|
||||||
stringValue
|
|
||||||
typeName
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
@ -174,10 +178,53 @@ export class GraphQLDataSourceOptionsBuilder<TModel, TKey> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private createGroupSelect(query: IQueryCriteria, group: IGroup, isLast: boolean) {
|
||||||
|
let ret = `
|
||||||
|
groupPath
|
||||||
|
groupValue {
|
||||||
|
${this.createSelectVariant()}
|
||||||
|
}
|
||||||
|
hasSubGroups
|
||||||
|
${this.createAggregateSelect(query)}
|
||||||
|
`;
|
||||||
|
|
||||||
|
if (isLast) {
|
||||||
|
ret += `
|
||||||
|
data {
|
||||||
|
${this.querySelect}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
} else {
|
||||||
|
ret += `
|
||||||
|
subGroups {
|
||||||
|
___INNER___
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private createSelectVariant() {
|
||||||
|
return `booleanValue dateTimeValue decimalValue intValue json longValue stringValue typeName`;
|
||||||
|
}
|
||||||
|
|
||||||
private createQuerySelect(query: IQueryCriteria): string {
|
private createQuerySelect(query: IQueryCriteria): string {
|
||||||
if (query.groups && query.groups.length) {
|
if (query.groups && query.groups.length) {
|
||||||
throw 'todo';
|
|
||||||
|
const groupSelect = query.groups.reduce((prev, current, currentIndex) => {
|
||||||
|
const isLast = currentIndex+1 == query.groups.length;
|
||||||
|
const group = this.createGroupSelect(query, current, isLast);
|
||||||
|
return prev.replace('___INNER___', group);
|
||||||
|
}, `
|
||||||
|
groups {
|
||||||
|
___INNER___
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
|
||||||
|
return groupSelect;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `
|
return `
|
||||||
data {
|
data {
|
||||||
${this.querySelect}
|
${this.querySelect}
|
||||||
|
@ -85,10 +85,19 @@ export interface IGraphQLAdvanceQueryInput<T> {
|
|||||||
sorts?: IGraphQLAdvanceQuerySortInput[]
|
sorts?: IGraphQLAdvanceQuerySortInput[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IGraphQLAdvanceGroupResult<T> {
|
||||||
|
aggregates?: IGraphQLAdvanceQueryAggregateResult[]
|
||||||
|
data?: T[]
|
||||||
|
groupPath?: string
|
||||||
|
groupValue?: IGraphQLVariantResult
|
||||||
|
hasSubGroups?: boolean
|
||||||
|
subGroups?: IGraphQLAdvanceGroupResult<T>[]
|
||||||
|
}
|
||||||
|
|
||||||
export interface IGraphQLAdvanceQueryResult<T> {
|
export interface IGraphQLAdvanceQueryResult<T> {
|
||||||
aggregates?: IGraphQLAdvanceQueryAggregateResult[];
|
aggregates?: IGraphQLAdvanceQueryAggregateResult[];
|
||||||
data?: T[];
|
data?: T[];
|
||||||
groups?: IGraphQLAdvanceQueryResult<T>[];
|
groups?: IGraphQLAdvanceGroupResult<T>[];
|
||||||
numberOfPages?: number;
|
numberOfPages?: number;
|
||||||
totalRecords: number;
|
totalRecords: number;
|
||||||
}
|
}
|
@ -84,6 +84,11 @@ export class AppComponent implements OnInit {
|
|||||||
'id firstName lastName',
|
'id firstName lastName',
|
||||||
(m) => m.id,
|
(m) => m.id,
|
||||||
{
|
{
|
||||||
|
groups: [
|
||||||
|
{
|
||||||
|
path: 'sex'
|
||||||
|
}
|
||||||
|
],
|
||||||
aggregates: [
|
aggregates: [
|
||||||
{
|
{
|
||||||
path: 'id',
|
path: 'id',
|
||||||
|
Loading…
Reference in New Issue
Block a user