remove apollo for now

This commit is contained in:
Mathias Beaulieu-Duncan 2024-08-25 19:07:21 -04:00
parent 8d50344a03
commit 6567466700
Signed by: mathias
GPG Key ID: 1C16CF05BAF9162D
17 changed files with 8 additions and 979 deletions

View File

@ -140,8 +140,8 @@
"tsConfig": "projects/openharbor/ngx-data/tsconfig.lib.prod.json"
}
}
},
"test": {
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/openharbor/ngx-data/src/test.ts",
@ -162,46 +162,7 @@
}
}
}
},
"ngx-data-apollo": {
"projectType": "library",
"root": "projects/openharbor/ngx-data-apollo",
"sourceRoot": "projects/openharbor/ngx-data-apollo/src",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:ng-packagr",
"options": {
"tsConfig": "projects/openharbor/ngx-data-apollo/tsconfig.lib.json",
"project": "projects/openharbor/ngx-data-apollo/ng-package.json"
}
, "configurations": {
"production": {
"tsConfig": "projects/openharbor/ngx-data-apollo/tsconfig.lib.prod.json"
}
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/openharbor/ngx-data-apollo/src/test.ts",
"tsConfig": "projects/openharbor/ngx-data-apollo/tsconfig.spec.json",
"karmaConfig": "projects/openharbor/ngx-data-apollo/karma.conf.js"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"projects/openharbor/ngx-data-apollo/tsconfig.lib.json",
"projects/openharbor/ngx-data-apollo/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}},
}
},
"defaultProject": "demo"
}

View File

@ -22,11 +22,6 @@
"@angular/platform-browser-dynamic": "~11.2.14",
"@angular/router": "~11.2.14",
"@poweredsoft/data": "0.0.32",
"apollo-angular": "^1.8.0",
"apollo-angular-link-http": "^1.9.0",
"apollo-cache-inmemory": "^1.6.0",
"apollo-client": "^2.6.0",
"apollo-link": "^1.2.11",
"graphql": "^14.5.0",
"graphql-tag": "^2.10.0",
"rxjs": "~6.5.3",
@ -38,9 +33,9 @@
"@angular/cli": "~11.2.19",
"@angular/compiler-cli": "~11.2.14",
"@angular/language-service": "~11.2.14",
"@types/node": "^12.11.1",
"@types/jasmine": "~3.6.0",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^12.11.1",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",

View File

@ -1,24 +0,0 @@
# NgxDataApollo
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.2.4.
## Code scaffolding
Run `ng generate component component-name --project ngx-data-apollo` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project ngx-data-apollo`.
> Note: Don't forget to add `--project ngx-data-apollo` or else it will be added to the default project in your `angular.json` file.
## Build
Run `ng build ngx-data-apollo` to build the project. The build artifacts will be stored in the `dist/` directory.
## Publishing
After building your library with `ng build ngx-data-apollo`, go to the dist folder `cd dist/ngx-data-apollo` and run `npm publish`.
## Running unit tests
Run `ng test ngx-data-apollo` to execute the unit tests via [Karma](https://karma-runner.github.io).
## Further help
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).

View File

@ -1,32 +0,0 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../../../coverage/poweredsoft/ngx-data-apollo'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true
});
};

View File

@ -1,7 +0,0 @@
{
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../../dist/poweredsoft/ngx-data-apollo",
"lib": {
"entryFile": "src/public-api.ts"
}
}

View File

@ -1,18 +0,0 @@
{
"name": "@poweredsoft/ngx-data-apollo",
"version": "0.0.9",
"dependencies": {
"tslib": "^2.0.0"
},
"peerDependencies": {
"@poweredsoft/data": "^0.0.31",
"@angular/common": "^8.2.4",
"@angular/core": "^8.2.4",
"apollo-angular-link-http": "^1.9.0",
"apollo-link": "^1.2.11",
"apollo-client": "^2.6.0",
"apollo-cache-inmemory": "^1.6.0",
"graphql-tag": "^2.10.0",
"graphql": "^14.5.0"
}
}

View File

@ -1,401 +0,0 @@
import { IDataSourceOptions, IQueryCriteria, IDataSourceTransportOptions, IDataSourceQueryAdapterOptions, IDataSourceCommandAdapterOptions, IAdvanceQueryAdapter, IFilter, IAggregate, ISort, IGroup, ISimpleFilter, ICompositeFilter, IQueryExecutionGroupResult, IQueryExecutionResult, IAggregateResult, IGroupQueryResult, IResolveCommandModelEvent, IDataSourceErrorMessage, IDataSourceValidationError } from '@poweredsoft/data';
import { Apollo } from 'apollo-angular';
import { IGraphQLAdvanceQueryResult, IGraphQLAdvanceQueryInput, IGraphQLAdvanceQueryFilterInput, IGraphQLAdvanceQueryAggregateInput, IGraphQLAdvanceQuerySortInput, IGraphQLAdvanceQueryGroupInput, FilterType, IGraphQLAdvanceQueryAggregateResult, IGraphQLVariantResult, AggregateType, IGraphQLAdvanceGroupResult } from './models';
import gql from 'graphql-tag';
import { DocumentNode, GraphQLError } from 'graphql';
import { map, catchError, switchMap } from 'rxjs/operators';
import { Observable, throwError, of } from 'rxjs';
import { FetchResult } from 'apollo-link';
import { ApolloError } from 'apollo-client';
export class GraphQLDataSourceOptionsBuilder<TModel, TKey> {
private _commands: { [key: string] : IDataSourceCommandAdapterOptions<any> } = {};
private _beforeRead: (TQuery: IGraphQLAdvanceQueryInput<TModel>) => Observable<IGraphQLAdvanceQueryInput<TModel>>;
querySelect: string;
constructor(private apollo: Apollo,
private queryName: string,
private queryInputName: string,
querySelect: string | string[],
private keyResolver: (model: TModel) => TKey,
private defaultCriteria: IQueryCriteria,
private manageNotificationMessage: boolean)
{
if (Array.isArray(querySelect))
this.querySelect = querySelect.join(' ');
else
this.querySelect = querySelect;
}
create(): IDataSourceOptions<TModel> {
let ret: IDataSourceOptions<TModel> = {
resolveIdField: this.keyResolver,
defaultCriteria: this.defaultCriteria,
transport: this.createTransport()
};
return ret;
}
protected createTransport(): IDataSourceTransportOptions<TModel> {
let ret: IDataSourceTransportOptions<TModel> = {
query: this.createQuery(),
commands: this._commands
};
return ret;
}
public beforeRead<TAdvanceQuery extends IGraphQLAdvanceQueryInput<TModel>>(beforeRead: (query: TAdvanceQuery) => Observable<TAdvanceQuery>)
{
this._beforeRead = beforeRead;
return this._beforeRead;
}
protected createQuery(): IDataSourceQueryAdapterOptions<TModel> {
let ret: IDataSourceQueryAdapterOptions<TModel> = {
adapter: <IAdvanceQueryAdapter<IQueryCriteria, TModel>>{
handle: (query: IQueryCriteria) => {
const finalBeforeRead = this._beforeRead || (t => of(t));
const advanceQuery = this.createGraphQLQueryCriteria(query);
return finalBeforeRead(advanceQuery)
.pipe(
switchMap(finalAdvanceQuery => {
const o$ = this.apollo.query<any>({
query: this.createGraphQLQuery(finalAdvanceQuery),
variables: {
criteria: finalAdvanceQuery
}
});
return o$.pipe(
map(result => {
const queryResult = result.data[this.queryName] as IGraphQLAdvanceQueryResult<TModel>;
return this.queryResultFromGraphQLAdvancedResult(finalAdvanceQuery, queryResult);
})
);
})
);
}
}
};
return ret;
}
private queryResultFromGraphQLAdvancedResult(query: IGraphQLAdvanceQueryInput<TModel>, result: IGraphQLAdvanceQueryResult<TModel>): IQueryExecutionResult<TModel> | IQueryExecutionGroupResult<TModel> {
const ret: IQueryExecutionGroupResult<TModel> & IQueryExecutionResult<TModel> = {
data: result.data,
groups: result.groups ? result.groups.map(this.fromGraphQLGroupResult.bind(this)) : null,
totalRecords: result.totalRecords,
numberOfPages: result.numberOfPages,
aggregates: result.aggregates ? result.aggregates.map(this.fromGraphQLAggregateResult.bind(this)) : null
};
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 {
return {
path: agg.path,
type: this.normalizeFirstLetter(agg.type),
value: this.getValueFromVariantResult(agg.value)
};
}
private normalizeFirstLetter(type: string): string {
if (type) {
const ret = type.toLowerCase();
return ret.substring(0, 1).toUpperCase() + ret.substring(1);
}
return type;
}
private getValueFromVariantResult(variant: IGraphQLVariantResult): any {
if (variant && variant.typeName)
{
if (variant.typeName.toLowerCase() == "int")
return variant.intValue;
else if (variant.typeName.toLowerCase() == "long")
return variant.longValue;
else if (variant.typeName.toLowerCase() == "boolean")
return variant.booleanValue;
else if (variant.typeName.toLowerCase() == "decimal")
return variant.decimalValue;
else if (variant.typeName.toLowerCase() == "datetime")
return variant.dateTimeValue;
else if (variant.typeName.toLowerCase() == "string")
return variant.stringValue;
else if (variant.typeName.toLowerCase() == "json")
return JSON.parse(variant.json);
}
return null;
}
private createGraphQLQuery(query: IGraphQLAdvanceQueryInput<TModel>): DocumentNode {
return gql`
query getAll($criteria: ${this.queryInputName}) {
${this.queryName}(params: $criteria) {
totalRecords
numberOfPages
${this.createAggregateSelect(query)}
${this.createQuerySelect(query)}
}
}
`;
}
private createAggregateSelect(query: IGraphQLAdvanceQueryInput<TModel>): any {
if (query.aggregates && query.aggregates.length)
{
return `
aggregates {
type
path
value {
${this.createSelectVariant()}
}
}
`;
}
return '';
}
private createGraphQLQueryCriteria(query: IQueryCriteria): IGraphQLAdvanceQueryInput<TModel> {
const ret: IGraphQLAdvanceQueryInput<TModel> = {
page: query.page,
pageSize: query.pageSize,
filters: query.filters ? query.filters.map(this.convertFilter.bind(this)) : null,
sorts: query.sorts ? query.sorts.map(this.convertSort.bind(this)) : null,
aggregates: query.aggregates ? query.aggregates.map(this.convertAggregates.bind(this)) : null,
groups: query.groups ? query.groups.map(this.convertGroup.bind(this)) : null
};
return ret;
}
/*public addMutationTest<TMutation, TMutationResult>(name: string, mutationName: string, mutationSelect?: string, resolveCommandModel?: (event: IResolveCommandModelEvent<TModel>) => Observable<TMutation & any>) {
this._commands[name] = <IDataSourceCommandAdapterOptions<TModel>> {
adapter: {
handle: this.apollo.use()
},
resolveCommandModel: resolveCommandModel
};
return this;
}*/
public addMutation<TMutation, TMutationResult>(name: string, mutationName: string, handle: (command: TMutation) => Observable<FetchResult<TMutationResult>>, resolveCommandModel?: (event: IResolveCommandModelEvent<TModel>) => Observable<TMutation & any>) {
const handleWrapper = command => {
return handle(command)
.pipe(
map(result => {
return result.data[mutationName];
}),
catchError((error: ApolloError) => {
console.log(error);
// should handle bad request with exception
// should handle bad request with validation
// should handle forbidden result 403
// should handle not authorized result 401
if (!error.networkError) {
const validationError = error.graphQLErrors.find(t => t.extensions.code == 'ValidationError');
const authenticationError = error.graphQLErrors.find(t => t.extensions.code == 'AuthenticationError');
if (validationError) {
const extensions = validationError.extensions;
const result = Object.keys(extensions).filter(t => t != 'code').reduce((prev, attributeName) => {
prev[attributeName] = extensions[attributeName];
return prev;
}, {});
console.log('error result', result);
return throwError(<IDataSourceValidationError>{
type: 'validation',
errors: result
});
}
else if (authenticationError) {
return throwError(<IDataSourceErrorMessage>{
type: 'message',
message: "Unauthorized"
});
}
}
return throwError(<IDataSourceErrorMessage>{
type: 'message',
message: error.message
});
})
);
};
this._commands[name] = <IDataSourceCommandAdapterOptions<TModel>> {
adapter: {
handle: handleWrapper
},
resolveCommandModel: resolveCommandModel
};
return this;
}
private createGroupSelect(query: IGraphQLAdvanceQueryInput<TModel>, 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: IGraphQLAdvanceQueryInput<TModel>): string {
if (query.groups && query.groups.length) {
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 `
data {
${this.querySelect}
}
`;
}
private convertGroup(group: IGroup): IGraphQLAdvanceQueryGroupInput {
return {
path: group.path,
ascending: group.ascending
};
}
private convertAggregates(aggregate: IAggregate): IGraphQLAdvanceQueryAggregateInput {
return {
path: aggregate.path,
type: this.resolveAggregateType(aggregate.type)
};
}
private resolveAggregateType(type: string): AggregateType {
return type ? type.toUpperCase() as any : null;
/*
if (type)
{
if (type.toUpperCase() == 'COUNT') return AggregateType.COUNT
if (type.toUpperCase() == 'SUM') return AggregateType.SUM
if (type.toUpperCase() == 'AVG') return AggregateType.AVG
if (type.toUpperCase() == 'LONGCOUNT') return AggregateType.LONGCOUNT
if (type.toUpperCase() == 'MIN') return AggregateType.MIN
if (type.toUpperCase() == 'MAX') return AggregateType.MAX
if (type.toUpperCase() == 'FIRST') return AggregateType.FIRST
if (type.toUpperCase() == 'FIRSTORDEFAULT') return AggregateType.FIRSTORDEFAULT
if (type.toUpperCase() == 'LAST') return AggregateType.LAST
if (type.toUpperCase() == 'LASTORDEFAULT') return AggregateType.LASTORDEFAULT
}
throw new Error('Aggregate type');*/
}
private convertSort(sort: ISort): IGraphQLAdvanceQuerySortInput {
return {
path: sort.path,
ascending: sort.ascending
};
}
private convertFilter(filter: IFilter): IGraphQLAdvanceQueryFilterInput {
if (filter.type == "Composite") {
const compositeFilter = filter as ICompositeFilter;
return {
not: false,
and: compositeFilter.and,
type: FilterType.COMPOSITE,
filters: compositeFilter.filters.map(this.convertFilter.bind(this)),
};
}
const simpleFilter = filter as ISimpleFilter;
return {
filters: null,
and: filter.and,
not: false,
path: simpleFilter.path,
type: this.resolveFilterType(simpleFilter.type),
value: {
stringValue: simpleFilter.value as string
}
};
}
private resolveFilterType(type: string): FilterType {
return type ? type.toUpperCase() as any: null;
/*
if (type)
{
if (type.toUpperCase() == 'EQUAL') return FilterType.EQUAL
if (type.toUpperCase() == 'CONTAINS') return FilterType.CONTAINS
if (type.toUpperCase() == 'STARTSWITH') return FilterType.STARTSWITH
if (type.toUpperCase() == 'ENDSWITH') return FilterType.ENDSWITH
if (type.toUpperCase() == 'COMPOSITE') return FilterType.COMPOSITE
if (type.toUpperCase() == 'NOTEQUAL') return FilterType.NOTEQUAL
if (type.toUpperCase() == 'GREATERTHAN') return FilterType.GREATERTHAN
if (type.toUpperCase() == 'LESSTHANOREQUAL') return FilterType.LESSTHANOREQUAL
if (type.toUpperCase() == 'GREATERTHANOREQUAL') return FilterType.GREATERTHANOREQUAL
if (type.toUpperCase() == 'LESSTHAN') return FilterType.LESSTHAN
if (type.toUpperCase() == 'IN') return FilterType.IN
if (type.toUpperCase() == 'NOTIN') return FilterType.NOTIN
}
throw new Error('unknown filter type');*/
}
}

View File

@ -1,36 +0,0 @@
import { Injectable } from '@angular/core';
import { IQueryCriteria, IDataSource } from '@poweredsoft/data';
import { Apollo } from 'apollo-angular';
import { GraphQLDataSourceOptionsBuilder } from './GraphQLDataSourceOptionsBuilder';
@Injectable({
providedIn: 'root'
})
export class GraphQLDataSourceService
{
constructor(private apollo: Apollo) {
}
createDataSourceOptionsBuilder<TModel, TKey>(
queryName: string,
queryInputName: string,
querySelect: string | string[],
keyResolver: (model: TModel) => TKey,
defaultCriteria: IQueryCriteria,
manageNotificationMessage: boolean = true) : GraphQLDataSourceOptionsBuilder<TModel, TKey>
{
if (Array.isArray(querySelect))
querySelect = querySelect.join(' ');
return new GraphQLDataSourceOptionsBuilder(
this.apollo,
queryName,
queryInputName,
querySelect,
keyResolver,
defaultCriteria,
manageNotificationMessage
);
}
}

View File

@ -1,103 +0,0 @@
export enum AggregateType {
COUNT,
SUM,
AVG,
LONGCOUNT,
MIN,
MAX,
FIRST,
FIRSTORDEFAULT,
LAST,
LASTORDEFAULT
}
export enum FilterType {
EQUAL,
CONTAINS,
STARTSWITH,
ENDSWITH,
COMPOSITE,
NOTEQUAL,
GREATERTHAN,
LESSTHANOREQUAL,
GREATERTHANOREQUAL,
LESSTHAN,
IN,
NOTIN
}
export interface IGraphQLVariantInput {
dateTimeValue?: Date
decimalValue?: number
intValue?: number
longValue?: number
stringValue?: string
booleanValue?: boolean;
}
export interface IGraphQLVariantResult {
dateTimeValue?: string;
decimalValue?: number;
intValue?: number;
json?: string;
longValue?: number;
stringValue?: string;
booleanValue?: boolean;
typeName: string;
}
export interface IGraphQLAdvanceQueryAggregateInput {
path?: string;
type: AggregateType;
}
export interface IGraphQLAdvanceQueryAggregateResult {
path: string
type: string
value: IGraphQLVariantResult
}
export interface IGraphQLAdvanceQueryFilterInput {
and?: boolean
filters?: IGraphQLAdvanceQueryFilterInput[]
not?: boolean
path?: string
type: FilterType
value?: IGraphQLVariantInput
}
export interface IGraphQLAdvanceQueryGroupInput {
ascending?: boolean
path: string
}
export interface IGraphQLAdvanceQuerySortInput {
ascending?: boolean
path: string
}
export interface IGraphQLAdvanceQueryInput<T> {
aggregates?: IGraphQLAdvanceQueryAggregateInput[]
filters?: IGraphQLAdvanceQueryFilterInput[]
groups?: IGraphQLAdvanceQueryGroupInput[]
page?: number
pageSize?: number
sorts?: IGraphQLAdvanceQuerySortInput[]
}
export interface IGraphQLAdvanceGroupResult<T> {
aggregates?: IGraphQLAdvanceQueryAggregateResult[]
data?: T[]
groupPath?: string
groupValue?: IGraphQLVariantResult
hasSubGroups?: boolean
subGroups?: IGraphQLAdvanceGroupResult<T>[]
}
export interface IGraphQLAdvanceQueryResult<T> {
aggregates?: IGraphQLAdvanceQueryAggregateResult[];
data?: T[];
groups?: IGraphQLAdvanceGroupResult<T>[];
numberOfPages?: number;
totalRecords: number;
}

View File

@ -1,9 +0,0 @@
import { GraphQLDataSourceService } from "./lib/graphql-datas-source.service";
/*
* Public API Surface of ngx-data-apollo
*/
export * from './lib/graphql-datas-source.service';
export * from './lib/GraphQLDataSourceOptionsBuilder';
export * from './lib/models';

View File

@ -1,26 +0,0 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "../../../out-tsc/lib",
"declarationMap": true,
"target": "es2015",
"declaration": true,
"inlineSources": true,
"types": [],
"lib": [
"dom",
"es2018"
]
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableResourceInlining": true
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}

View File

@ -1,9 +0,0 @@
{
"extends": "./tsconfig.lib.json",
"compilerOptions": {
"declarationMap": false
},
"angularCompilerOptions": {
"enableIvy": false
}
}

View File

@ -1,17 +0,0 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "../../../out-tsc/spec",
"types": [
"jasmine",
"node"
]
},
"files": [
"src/test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}

View File

@ -1,17 +0,0 @@
{
"extends": "../../../tslint.json",
"rules": {
"directive-selector": [
true,
"attribute",
"lib",
"camelCase"
],
"component-selector": [
true,
"element",
"lib",
"kebab-case"
]
}
}

View File

@ -1,26 +0,0 @@
import {NgModule} from '@angular/core';
import {ApolloModule, Apollo} from 'apollo-angular';
import {HttpLinkModule, HttpLink} from 'apollo-angular-link-http';
import {InMemoryCache} from 'apollo-cache-inmemory';
@NgModule({
exports: [ApolloModule, HttpLinkModule]
})
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'
}
}
});
}
}

View File

@ -1,68 +0,0 @@
import { Injectable } from '@angular/core';
import { IGraphQLAdvanceQueryInput, GraphQLDataSourceService } from 'projects/poweredsoft/ngx-data-apollo/src/public-api';
import { IQueryCriteria, DataSource } from '@poweredsoft/data';
import { of } from 'rxjs';
import { Apollo } from 'apollo-angular';
import gql from 'graphql-tag';
export interface IValidationTestCommand {
value: string;
}
export interface ITestModel {
id: string;
}
export interface ITestQuery extends IGraphQLAdvanceQueryInput<ITestModel> {
}
export interface IGenerateDatasource<T, TAdvanceQuery extends IGraphQLAdvanceQueryInput<T>> {
criteria: IQueryCriteria;
beforeReadQueryCriteria?: TAdvanceQuery
}
export interface IGenerateItemDatasource extends IGenerateDatasource<ITestModel, ITestQuery> {
}
@Injectable({
providedIn: 'root'
})
export class TestService {
constructor(private graphQLService: GraphQLDataSourceService, private apollo: Apollo) { }
generateDatasource(options: IGenerateItemDatasource) {
const keyResolver = (m: ITestModel) => m.id;
let builder = this.graphQLService.createDataSourceOptionsBuilder<ITestModel, string>(
"test",
"TestQueryInput",
[
'id'
],
keyResolver,
options.criteria
);
if (options.beforeReadQueryCriteria) {
builder.beforeRead<ITestQuery>(query => {
return of({ ...query, ...options.beforeReadQueryCriteria });
});
}
builder.addMutation<IValidationTestCommand, string>(
'validationTest',
'validationTest',
(command) => {
return this.apollo.mutate<string>({
mutation:gql`mutation executeValidationTest($command: ValidationTestCommandInput) {
validationTest(params: $command)
}`,
variables: {
command: command
}
});
});
return new DataSource<ITestModel>(builder.create());
}
}

138
yarn.lock
View File

@ -1419,7 +1419,7 @@
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca"
integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==
"@types/node@*", "@types/node@>=10.0.0", "@types/node@>=6":
"@types/node@*", "@types/node@>=10.0.0":
version "22.5.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-22.5.0.tgz#10f01fe9465166b4cab72e75f60d8b99d019f958"
integrity sha512-DkFrJOe+rfdHTqqMg0bSNlGlQ85hSoh2TPzZyhHsXnMtligRWpxUySiyw8FY14ITt24HVCiQPWxS3KO/QlGmWg==
@ -1472,11 +1472,6 @@
"@types/source-list-map" "*"
source-map "^0.6.1"
"@types/zen-observable@^0.8.0":
version "0.8.7"
resolved "https://registry.yarnpkg.com/@types/zen-observable/-/zen-observable-0.8.7.tgz#114e2ffc8d5be4915fdd5bc90668fc0ceaadb760"
integrity sha512-LKzNTjj+2j09wAo/vvVjzgw5qckJJzhdGgWHW7j69QIGdq/KnZrMAMIHQiWGl3Ccflh5/CudBAntTPYdprPltA==
"@webassemblyjs/ast@1.9.0":
version "1.9.0"
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.9.0.tgz#bd850604b4042459a5a41cd7d338cbed695ed964"
@ -1622,21 +1617,6 @@
"@webassemblyjs/wast-parser" "1.9.0"
"@xtuc/long" "4.2.2"
"@wry/context@^0.4.0":
version "0.4.4"
resolved "https://registry.yarnpkg.com/@wry/context/-/context-0.4.4.tgz#e50f5fa1d6cfaabf2977d1fda5ae91717f8815f8"
integrity sha512-LrKVLove/zw6h2Md/KZyWxIkFM6AoyKp71OqpH9Hiip1csjPVoD3tPxlbQUNxEnHENks3UGgNpSBCAfq9KWuag==
dependencies:
"@types/node" ">=6"
tslib "^1.9.3"
"@wry/equality@^0.1.2":
version "0.1.11"
resolved "https://registry.yarnpkg.com/@wry/equality/-/equality-0.1.11.tgz#35cb156e4a96695aa81a9ecc4d03787bc17f1790"
integrity sha512-mwEVBDUVODlsQQ5dfuLUS5/Tf7jqUKyhKYHmVi4fPB6bDMOfWvUPJmKgS1Z7Za/sOI3vzWt4+O7yCiL/70MogA==
dependencies:
tslib "^1.9.3"
"@xtuc/ieee754@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@xtuc/ieee754/-/ieee754-1.2.0.tgz#eef014a3145ae477a1cbc00cd1e552336dceb790"
@ -1834,83 +1814,6 @@ anymatch@~3.1.2:
normalize-path "^3.0.0"
picomatch "^2.0.4"
apollo-angular-link-http-common@~1.10.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/apollo-angular-link-http-common/-/apollo-angular-link-http-common-1.10.0.tgz#c8d8666f9f17dbc6e4d60474441548ac83054aac"
integrity sha512-Oue8b/naWZvG/oQ+3ZAqaBVreBIwqy16yOk5CpoE7+Gjhett9KGVu/OZcpH89/ifwXyWzHpKnCUnB1fxgbnR7Q==
dependencies:
tslib "^2.0.0"
apollo-angular-link-http@^1.9.0:
version "1.11.0"
resolved "https://registry.yarnpkg.com/apollo-angular-link-http/-/apollo-angular-link-http-1.11.0.tgz#5465664aac1944881900e845f043cf627af0f812"
integrity sha512-/mFytwvHhmWOX3emi8ljpuas8HpwSVOfbKniOeDFSE44g9HsPKkq2bGTucUTUo0Un3cCBEVKei2jTIDVsZPqFA==
dependencies:
apollo-angular-link-http-common "~1.10.0"
extract-files "6.0.0"
tslib "^2.0.0"
apollo-angular@^1.8.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/apollo-angular/-/apollo-angular-1.10.0.tgz#da95875d3065da53624fcbe4b8aa273e5ace18ac"
integrity sha512-VPSNk8Li5KRDhZ3GSJPEYg1r57KySND2m1XWgkLNYmQExzNDs/Su9EeWThwOqjZ7x9JbGjpvWiQeUQaCs96PjA==
dependencies:
semver "^7.0.0"
tslib "^2.0.0"
apollo-cache-inmemory@^1.6.0:
version "1.6.6"
resolved "https://registry.yarnpkg.com/apollo-cache-inmemory/-/apollo-cache-inmemory-1.6.6.tgz#56d1f2a463a6b9db32e9fa990af16d2a008206fd"
integrity sha512-L8pToTW/+Xru2FFAhkZ1OA9q4V4nuvfoPecBM34DecAugUZEBhI2Hmpgnzq2hTKZ60LAMrlqiASm0aqAY6F8/A==
dependencies:
apollo-cache "^1.3.5"
apollo-utilities "^1.3.4"
optimism "^0.10.0"
ts-invariant "^0.4.0"
tslib "^1.10.0"
apollo-cache@1.3.5, apollo-cache@^1.3.5:
version "1.3.5"
resolved "https://registry.yarnpkg.com/apollo-cache/-/apollo-cache-1.3.5.tgz#9dbebfc8dbe8fe7f97ba568a224bca2c5d81f461"
integrity sha512-1XoDy8kJnyWY/i/+gLTEbYLnoiVtS8y7ikBr/IfmML4Qb+CM7dEEbIUOjnY716WqmZ/UpXIxTfJsY7rMcqiCXA==
dependencies:
apollo-utilities "^1.3.4"
tslib "^1.10.0"
apollo-client@^2.6.0:
version "2.6.10"
resolved "https://registry.yarnpkg.com/apollo-client/-/apollo-client-2.6.10.tgz#86637047b51d940c8eaa771a4ce1b02df16bea6a"
integrity sha512-jiPlMTN6/5CjZpJOkGeUV0mb4zxx33uXWdj/xQCfAMkuNAC3HN7CvYDyMHHEzmcQ5GV12LszWoQ/VlxET24CtA==
dependencies:
"@types/zen-observable" "^0.8.0"
apollo-cache "1.3.5"
apollo-link "^1.0.0"
apollo-utilities "1.3.4"
symbol-observable "^1.0.2"
ts-invariant "^0.4.0"
tslib "^1.10.0"
zen-observable "^0.8.0"
apollo-link@^1.0.0, apollo-link@^1.2.11:
version "1.2.14"
resolved "https://registry.yarnpkg.com/apollo-link/-/apollo-link-1.2.14.tgz#3feda4b47f9ebba7f4160bef8b977ba725b684d9"
integrity sha512-p67CMEFP7kOG1JZ0ZkYZwRDa369w5PIjtMjvrQd/HnIV8FRsHRqLqK+oAZQnFa1DDdZtOtHTi+aMIW6EatC2jg==
dependencies:
apollo-utilities "^1.3.0"
ts-invariant "^0.4.0"
tslib "^1.9.3"
zen-observable-ts "^0.8.21"
apollo-utilities@1.3.4, apollo-utilities@^1.3.0, apollo-utilities@^1.3.4:
version "1.3.4"
resolved "https://registry.yarnpkg.com/apollo-utilities/-/apollo-utilities-1.3.4.tgz#6129e438e8be201b6c55b0f13ce49d2c7175c9cf"
integrity sha512-pk2hiWrCXMAy2fRPwEyhvka+mqwzeP60Jr1tRYi5xru+3ko94HI9o6lK0CT33/w4RDlxWchmdhDCrvdr+pHCig==
dependencies:
"@wry/equality" "^0.1.2"
fast-json-stable-stringify "^2.0.0"
ts-invariant "^0.4.0"
tslib "^1.10.0"
app-root-path@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/app-root-path/-/app-root-path-3.1.0.tgz#5971a2fc12ba170369a7a1ef018c71e6e47c2e86"
@ -4247,11 +4150,6 @@ extglob@^2.0.4:
snapdragon "^0.8.1"
to-regex "^3.0.1"
extract-files@6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/extract-files/-/extract-files-6.0.0.tgz#a273fd666aac97fd32e788b62d72d978bf43bb71"
integrity sha512-v9UVTPkERZR1NjEOIPvmbzLFdh8YZFEGjRdSJraop6HJe9PQ8HU9iv6eRMuF06CXXXO/R5OBmnWMixZHuZ8CsA==
extsprintf@1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05"
@ -6970,13 +6868,6 @@ opn@^5.5.0:
dependencies:
is-wsl "^1.1.0"
optimism@^0.10.0:
version "0.10.3"
resolved "https://registry.yarnpkg.com/optimism/-/optimism-0.10.3.tgz#163268fdc741dea2fb50f300bedda80356445fd7"
integrity sha512-9A5pqGoQk49H6Vhjb9kPgAeeECfUDF6aIICbMDL23kDLStBn1MWk3YvcZ4xWF9CsSf6XEgvRLkXy4xof/56vVw==
dependencies:
"@wry/context" "^0.4.0"
ora@5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/ora/-/ora-5.3.0.tgz#fb832899d3a1372fe71c8b2c534bbfe74961bb6f"
@ -9357,11 +9248,6 @@ symbol-observable@3.0.0:
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-3.0.0.tgz#eea8f6478c651018e059044268375c408c15c533"
integrity sha512-6tDOXSHiVjuCaasQSWTmHUWn4PuG7qa3+1WT031yTc/swT7+rLiw3GOrFxaH1E3lLP09dH3bVuVDf2gK5rxG3Q==
symbol-observable@^1.0.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804"
integrity sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ==
sync-rpc@^1.3.6:
version "1.3.6"
resolved "https://registry.yarnpkg.com/sync-rpc/-/sync-rpc-1.3.6.tgz#b2e8b2550a12ccbc71df8644810529deb68665a7"
@ -9563,13 +9449,6 @@ tree-kill@1.2.2:
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc"
integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==
ts-invariant@^0.4.0:
version "0.4.4"
resolved "https://registry.yarnpkg.com/ts-invariant/-/ts-invariant-0.4.4.tgz#97a523518688f93aafad01b0e80eb803eb2abd86"
integrity sha512-uEtWkFM/sdZvRNNDL3Ehu4WVpwaulhwQszV8mrtcdeE8nN00BV9mAmQ88RkrBhFgl9gMgvjJLAQcZbnPXI9mlA==
dependencies:
tslib "^1.9.3"
ts-node@~7.0.0:
version "7.0.1"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-7.0.1.tgz#9562dc2d1e6d248d24bc55f773e3f614337d9baf"
@ -9594,7 +9473,7 @@ tslib@2.1.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a"
integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==
tslib@^1.10.0, tslib@^1.13.0, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3:
tslib@^1.10.0, tslib@^1.13.0, tslib@^1.8.1, tslib@^1.9.0:
version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
@ -10397,19 +10276,6 @@ yocto-queue@^0.1.0:
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==
zen-observable-ts@^0.8.21:
version "0.8.21"
resolved "https://registry.yarnpkg.com/zen-observable-ts/-/zen-observable-ts-0.8.21.tgz#85d0031fbbde1eba3cd07d3ba90da241215f421d"
integrity sha512-Yj3yXweRc8LdRMrCC8nIc4kkjWecPAUVh0TI0OUrWXx6aX790vLcDlWca6I4vsyCGH3LpWxq0dJRcMOFoVqmeg==
dependencies:
tslib "^1.9.3"
zen-observable "^0.8.0"
zen-observable@^0.8.0:
version "0.8.15"
resolved "https://registry.yarnpkg.com/zen-observable/-/zen-observable-0.8.15.tgz#96415c512d8e3ffd920afd3889604e30b9eaac15"
integrity sha512-PQ2PC7R9rslx84ndNBZB/Dkv8V8fZEpk83RLgXtYd0fwUgEjseMn1Dgajh2x6S8QbZAFa9p2qVCEuYZNgve0dQ==
zone.js@~0.10.2, zone.js@~0.10.3:
version "0.10.3"
resolved "https://registry.yarnpkg.com/zone.js/-/zone.js-0.10.3.tgz#3e5e4da03c607c9dcd92e37dd35687a14a140c16"