@proscom/prostore-apollo
Advanced tools
Comparing version 0.0.20 to 0.1.0
@@ -6,12 +6,27 @@ import { IRequestStoreOptions, RequestStore, IRequestStoreParams } from '@proscom/prostore'; | ||
export declare type ApolloQueryOptions<Vars> = Omit<QueryOptions<Vars>, 'query' | 'variables'>; | ||
export interface IGraphqlQueryOptions<Vars> extends IRequestStoreOptions { | ||
export interface IGraphqlQueryOptions<Vars, Data> extends IRequestStoreOptions<Vars, Data> { | ||
/** Additional Apollo query options */ | ||
apolloOptions: ApolloQueryOptions<Vars>; | ||
} | ||
export interface IGraphqlQueryStoreParams<Vars, Data> extends IRequestStoreParams<Vars, Data> { | ||
/** | ||
* GraphQL query definition using graphql AST from the graphql-tag packages | ||
* | ||
* (be sure to include ids wherever possible in order for Apoolo cache to work correctly) | ||
*/ | ||
query: DocumentNode; | ||
/** Apollo client to be used for fetching the data */ | ||
client: ApolloClient<any>; | ||
/** | ||
* Optional callback to transform the query result into the request store state. | ||
* Use it to remove unnecessary nesting or transform the data | ||
*/ | ||
mapData?: IMapData<Data>; | ||
/** Additional Apollo query options */ | ||
apolloOptions?: ApolloQueryOptions<Vars>; | ||
} | ||
export declare class GraphqlQueryStore<Vars, Data> extends RequestStore<Vars, Data, IGraphqlQueryOptions<Vars>> { | ||
/** | ||
* RequestStore tailored to make Apollo GraphQL requests | ||
*/ | ||
export declare class GraphqlQueryStore<Vars, Data> extends RequestStore<Vars, Data, IGraphqlQueryOptions<Vars, Data>> { | ||
query: DocumentNode; | ||
@@ -22,3 +37,9 @@ client: ApolloClient<any>; | ||
constructor({ query, client, mapData, apolloOptions, ...requestParams }: IGraphqlQueryStoreParams<Vars, Data>); | ||
performRequest(variables: Vars, options: Partial<IGraphqlQueryOptions<Vars>>): Promise<Data>; | ||
/** | ||
* Performs actual GraphQL request using the Apollo Client | ||
* | ||
* @param variables - query variables | ||
* @param options - additional query options | ||
*/ | ||
performRequest(variables: Vars, options: Partial<IGraphqlQueryOptions<Vars, Data>>): Promise<Data>; | ||
} |
@@ -26,6 +26,7 @@ var __extends = (this && this.__extends) || (function () { | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -73,2 +74,5 @@ }); | ||
import { RequestStore } from '@proscom/prostore'; | ||
/** | ||
* RequestStore tailored to make Apollo GraphQL requests | ||
*/ | ||
var GraphqlQueryStore = /** @class */ (function (_super) { | ||
@@ -87,2 +91,8 @@ __extends(GraphqlQueryStore, _super); | ||
} | ||
/** | ||
* Performs actual GraphQL request using the Apollo Client | ||
* | ||
* @param variables - query variables | ||
* @param options - additional query options | ||
*/ | ||
GraphqlQueryStore.prototype.performRequest = function (variables, options) { | ||
@@ -93,3 +103,3 @@ return __awaiter(this, void 0, void 0, function () { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.client.query(__assign({ query: this.query, variables: variables }, this.apolloOptions, options.apolloOptions))]; | ||
case 0: return [4 /*yield*/, this.client.query(__assign(__assign({ query: this.query, variables: variables }, this.apolloOptions), options.apolloOptions))]; | ||
case 1: | ||
@@ -96,0 +106,0 @@ result = _a.sent(); |
@@ -7,12 +7,28 @@ import { Observable } from 'rxjs'; | ||
export declare type ApolloWatchQueryOptions<Vars> = Omit<WatchQueryOptions<Vars>, 'query' | 'variables'>; | ||
export interface IGraphqlWatchQueryOptions<Vars> extends IRequestStoreOptions { | ||
export interface IGraphqlWatchQueryOptions<Vars, Data> extends IRequestStoreOptions<Vars, Data> { | ||
/** Additional Apollo query options */ | ||
apolloOptions: ApolloWatchQueryOptions<Vars>; | ||
} | ||
export interface IGraphqlWatchQueryStoreParams<Vars, Data> extends IRequestStoreParams<Vars, Data> { | ||
/** | ||
* GraphQL query definition using graphql AST from the graphql-tag packages | ||
* | ||
* (be sure to include ids wherever possible in order for Apoolo cache to work correctly) | ||
*/ | ||
query: DocumentNode; | ||
/** Apollo client to be used for fetching the data */ | ||
client: ApolloClient<any>; | ||
/** | ||
* Optional callback to transform the query result into the request store state. | ||
* Use it to remove unnecessary nesting or transform the data | ||
*/ | ||
mapData?: IMapData<Data>; | ||
/** Additional Apollo query options */ | ||
apolloOptions?: ApolloWatchQueryOptions<Vars>; | ||
} | ||
export declare class GraphqlWatchQueryStore<Vars, Data> extends RequestStore<Vars, Data, IGraphqlWatchQueryOptions<Vars>> { | ||
/** | ||
* RequestStore tailored to make Apollo GraphQL requests. | ||
* It also subscribes to Apollo Cache by using watchQuery | ||
*/ | ||
export declare class GraphqlWatchQueryStore<Vars, Data> extends RequestStore<Vars, Data, IGraphqlWatchQueryOptions<Vars, Data>> { | ||
query: DocumentNode; | ||
@@ -23,3 +39,9 @@ client: ApolloClient<any>; | ||
constructor({ query, client, mapData, apolloOptions, ...requestProps }: IGraphqlWatchQueryStoreParams<Vars, Data>); | ||
performRequest(variables: Vars, options: IGraphqlWatchQueryOptions<Vars>): Observable<Data>; | ||
/** | ||
* Performs actual GraphQL request using the Apollo Client | ||
* | ||
* @param variables - query variables | ||
* @param options - additional query options | ||
*/ | ||
performRequest(variables: Vars, options: IGraphqlWatchQueryOptions<Vars, Data>): Observable<Data>; | ||
} |
@@ -39,2 +39,6 @@ var __extends = (this && this.__extends) || (function () { | ||
import { RequestStore } from '@proscom/prostore'; | ||
/** | ||
* RequestStore tailored to make Apollo GraphQL requests. | ||
* It also subscribes to Apollo Cache by using watchQuery | ||
*/ | ||
var GraphqlWatchQueryStore = /** @class */ (function (_super) { | ||
@@ -53,5 +57,11 @@ __extends(GraphqlWatchQueryStore, _super); | ||
} | ||
/** | ||
* Performs actual GraphQL request using the Apollo Client | ||
* | ||
* @param variables - query variables | ||
* @param options - additional query options | ||
*/ | ||
GraphqlWatchQueryStore.prototype.performRequest = function (variables, options) { | ||
var _this = this; | ||
var queryParams = __assign({ query: this.query, variables: variables }, this.apolloOptions, options.apolloOptions); | ||
var queryParams = __assign(__assign({ query: this.query, variables: variables }, this.apolloOptions), options.apolloOptions); | ||
var wq = this.client.watchQuery(queryParams); | ||
@@ -58,0 +68,0 @@ return from(wq).pipe(map(function (result) { return _this.mapData(result.data); })); |
@@ -6,12 +6,27 @@ import { IRequestStoreOptions, RequestStore, IRequestStoreParams } from '@proscom/prostore'; | ||
export declare type ApolloQueryOptions<Vars> = Omit<QueryOptions<Vars>, 'query' | 'variables'>; | ||
export interface IGraphqlQueryOptions<Vars> extends IRequestStoreOptions { | ||
export interface IGraphqlQueryOptions<Vars, Data> extends IRequestStoreOptions<Vars, Data> { | ||
/** Additional Apollo query options */ | ||
apolloOptions: ApolloQueryOptions<Vars>; | ||
} | ||
export interface IGraphqlQueryStoreParams<Vars, Data> extends IRequestStoreParams<Vars, Data> { | ||
/** | ||
* GraphQL query definition using graphql AST from the graphql-tag packages | ||
* | ||
* (be sure to include ids wherever possible in order for Apoolo cache to work correctly) | ||
*/ | ||
query: DocumentNode; | ||
/** Apollo client to be used for fetching the data */ | ||
client: ApolloClient<any>; | ||
/** | ||
* Optional callback to transform the query result into the request store state. | ||
* Use it to remove unnecessary nesting or transform the data | ||
*/ | ||
mapData?: IMapData<Data>; | ||
/** Additional Apollo query options */ | ||
apolloOptions?: ApolloQueryOptions<Vars>; | ||
} | ||
export declare class GraphqlQueryStore<Vars, Data> extends RequestStore<Vars, Data, IGraphqlQueryOptions<Vars>> { | ||
/** | ||
* RequestStore tailored to make Apollo GraphQL requests | ||
*/ | ||
export declare class GraphqlQueryStore<Vars, Data> extends RequestStore<Vars, Data, IGraphqlQueryOptions<Vars, Data>> { | ||
query: DocumentNode; | ||
@@ -22,3 +37,9 @@ client: ApolloClient<any>; | ||
constructor({ query, client, mapData, apolloOptions, ...requestParams }: IGraphqlQueryStoreParams<Vars, Data>); | ||
performRequest(variables: Vars, options: Partial<IGraphqlQueryOptions<Vars>>): Promise<Data>; | ||
/** | ||
* Performs actual GraphQL request using the Apollo Client | ||
* | ||
* @param variables - query variables | ||
* @param options - additional query options | ||
*/ | ||
performRequest(variables: Vars, options: Partial<IGraphqlQueryOptions<Vars, Data>>): Promise<Data>; | ||
} |
@@ -27,6 +27,7 @@ "use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -74,3 +75,7 @@ }); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GraphqlQueryStore = void 0; | ||
var prostore_1 = require("@proscom/prostore"); | ||
/** | ||
* RequestStore tailored to make Apollo GraphQL requests | ||
*/ | ||
var GraphqlQueryStore = /** @class */ (function (_super) { | ||
@@ -89,2 +94,8 @@ __extends(GraphqlQueryStore, _super); | ||
} | ||
/** | ||
* Performs actual GraphQL request using the Apollo Client | ||
* | ||
* @param variables - query variables | ||
* @param options - additional query options | ||
*/ | ||
GraphqlQueryStore.prototype.performRequest = function (variables, options) { | ||
@@ -95,3 +106,3 @@ return __awaiter(this, void 0, void 0, function () { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.client.query(__assign({ query: this.query, variables: variables }, this.apolloOptions, options.apolloOptions))]; | ||
case 0: return [4 /*yield*/, this.client.query(__assign(__assign({ query: this.query, variables: variables }, this.apolloOptions), options.apolloOptions))]; | ||
case 1: | ||
@@ -98,0 +109,0 @@ result = _a.sent(); |
@@ -7,12 +7,28 @@ import { Observable } from 'rxjs'; | ||
export declare type ApolloWatchQueryOptions<Vars> = Omit<WatchQueryOptions<Vars>, 'query' | 'variables'>; | ||
export interface IGraphqlWatchQueryOptions<Vars> extends IRequestStoreOptions { | ||
export interface IGraphqlWatchQueryOptions<Vars, Data> extends IRequestStoreOptions<Vars, Data> { | ||
/** Additional Apollo query options */ | ||
apolloOptions: ApolloWatchQueryOptions<Vars>; | ||
} | ||
export interface IGraphqlWatchQueryStoreParams<Vars, Data> extends IRequestStoreParams<Vars, Data> { | ||
/** | ||
* GraphQL query definition using graphql AST from the graphql-tag packages | ||
* | ||
* (be sure to include ids wherever possible in order for Apoolo cache to work correctly) | ||
*/ | ||
query: DocumentNode; | ||
/** Apollo client to be used for fetching the data */ | ||
client: ApolloClient<any>; | ||
/** | ||
* Optional callback to transform the query result into the request store state. | ||
* Use it to remove unnecessary nesting or transform the data | ||
*/ | ||
mapData?: IMapData<Data>; | ||
/** Additional Apollo query options */ | ||
apolloOptions?: ApolloWatchQueryOptions<Vars>; | ||
} | ||
export declare class GraphqlWatchQueryStore<Vars, Data> extends RequestStore<Vars, Data, IGraphqlWatchQueryOptions<Vars>> { | ||
/** | ||
* RequestStore tailored to make Apollo GraphQL requests. | ||
* It also subscribes to Apollo Cache by using watchQuery | ||
*/ | ||
export declare class GraphqlWatchQueryStore<Vars, Data> extends RequestStore<Vars, Data, IGraphqlWatchQueryOptions<Vars, Data>> { | ||
query: DocumentNode; | ||
@@ -23,3 +39,9 @@ client: ApolloClient<any>; | ||
constructor({ query, client, mapData, apolloOptions, ...requestProps }: IGraphqlWatchQueryStoreParams<Vars, Data>); | ||
performRequest(variables: Vars, options: IGraphqlWatchQueryOptions<Vars>): Observable<Data>; | ||
/** | ||
* Performs actual GraphQL request using the Apollo Client | ||
* | ||
* @param variables - query variables | ||
* @param options - additional query options | ||
*/ | ||
performRequest(variables: Vars, options: IGraphqlWatchQueryOptions<Vars, Data>): Observable<Data>; | ||
} |
@@ -38,5 +38,10 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GraphqlWatchQueryStore = void 0; | ||
var rxjs_1 = require("rxjs"); | ||
var operators_1 = require("rxjs/operators"); | ||
var prostore_1 = require("@proscom/prostore"); | ||
/** | ||
* RequestStore tailored to make Apollo GraphQL requests. | ||
* It also subscribes to Apollo Cache by using watchQuery | ||
*/ | ||
var GraphqlWatchQueryStore = /** @class */ (function (_super) { | ||
@@ -55,5 +60,11 @@ __extends(GraphqlWatchQueryStore, _super); | ||
} | ||
/** | ||
* Performs actual GraphQL request using the Apollo Client | ||
* | ||
* @param variables - query variables | ||
* @param options - additional query options | ||
*/ | ||
GraphqlWatchQueryStore.prototype.performRequest = function (variables, options) { | ||
var _this = this; | ||
var queryParams = __assign({ query: this.query, variables: variables }, this.apolloOptions, options.apolloOptions); | ||
var queryParams = __assign(__assign({ query: this.query, variables: variables }, this.apolloOptions), options.apolloOptions); | ||
var wq = this.client.watchQuery(queryParams); | ||
@@ -60,0 +71,0 @@ return rxjs_1.from(wq).pipe(operators_1.map(function (result) { return _this.mapData(result.data); })); |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./GraphqlQueryStore")); | ||
__export(require("./GraphqlWatchQueryStore")); | ||
__exportStar(require("./GraphqlQueryStore"), exports); | ||
__exportStar(require("./GraphqlWatchQueryStore"), exports); | ||
//# sourceMappingURL=prostore-apollo.js.map |
{ | ||
"name": "@proscom/prostore-apollo", | ||
"version": "0.0.20", | ||
"version": "0.1.0", | ||
"description": "> TODO: description", | ||
@@ -29,3 +29,3 @@ "author": "Andrew Starostin <a.starostin@proscom.ru>", | ||
"dependencies": { | ||
"@proscom/prostore": "^0.0.20" | ||
"@proscom/prostore": "^0.1.0" | ||
}, | ||
@@ -42,3 +42,3 @@ "peerDependencies": { | ||
"sideEffects": false, | ||
"gitHead": "ea3c5171457075715c3337afa63b87b6db6a51bd" | ||
"gitHead": "041eb4482d6d97d7461d8b24cbfa95e110c8e8ea" | ||
} |
111
README.md
# `prostore-apollo` | ||
> TODO: description | ||
Эта библиотека расширяет [`prostore`](https://gitlab.com/proscom/prostore/-/tree/master/packages%2Fprostore), | ||
добавляя в него специальные классы сторов для GraphQL-запросов, | ||
выполняемых с помощью [Apollo Client](https://www.apollographql.com/docs/react/). | ||
## Usage | ||
В библиотеку входят два класса: `GraphqlQueryStore` и `GraphqlWatchQueryStore` | ||
которые расширяют `RequestStore`, обеспечивая единообразное API | ||
для выполнения запросов и хранения их результатов в сторе, | ||
на который можно подписаться. Первый класс использует метод `client.query` | ||
для выполнения запросов, а второй - `client.watchQuery`. | ||
Таким образом, `GraphqlWatchQueryStore` обновляется не только при | ||
первичном выполнении запроса, но и в случае последующего обновления | ||
локального кеша Apollo (например при рефетче, либо очистке кеша). | ||
## Использование | ||
У `GraphqlWatchQueryStore` точно такое же API, поэтому ниже | ||
пример только для `GraphqlQueryStore`. | ||
```javascript | ||
import gql from 'graphql-tag'; | ||
import { GraphqlQueryStore } from '@proscom/prostore-apollo'; | ||
import { ApolloClient } from 'apollo-client'; | ||
// Создаем клиент Apollo для выполнения запросов | ||
const client = new ApolloClient(/*...*/); | ||
// Задаем graphql-запрос с переменными | ||
const query = gql` | ||
query getData($variable: Int) { | ||
data(filter: $variable) { | ||
# Всегда включайте id в запрос, если такое поле есть | ||
# в типе, потому что иначе Apollo Cache сломается | ||
# если какой-то другой запрос вернет тот же самый объект, | ||
# и в нем будет id | ||
id | ||
value1 | ||
value2 | ||
} | ||
} | ||
`; | ||
// Создаем наш стор | ||
const store = new GraphqlQueryStore({ | ||
// Выполняемый запрос | ||
query, | ||
// Клиент, который будет выполнять запрос | ||
client, | ||
// Дополнительные параметры, которые будут переданы | ||
// в client.query | ||
apolloOptions: {}, | ||
// Функция, которая определяет что положить в state.data | ||
// Можно положить только часть ответа, например достать вложенный объект | ||
// Удобно для запросов, которые выполняют только один query | ||
mapData: (result) => result.data, | ||
// Так как GraphqlQueryStore расширяет RequestStore | ||
// то можно передать все параметры конструктора RequestStore | ||
// см. подробнее в Readme @proscom/prostore | ||
// https://gitlab.com/proscom/prostore/-/blob/master/packages/prostore/README.md#requeststore | ||
// Первоначальное значение | ||
initialData: null, | ||
// Функция пропуска запроса в зависимости от переменных | ||
skipQuery: (vars) => undefined, | ||
// Функция обновления данных при повторном запросе | ||
updateData: (data, oldData, params) => data, | ||
// Уникальный идентификатор стора для передачи данных | ||
// при использовании серверного рендеринга | ||
ssrId: undefined | ||
}); | ||
// Чтобы инициировать запрос данных, надо вызвать | ||
store.loadData( | ||
// variables - переменные запроса, определенные в query | ||
{ | ||
variable: 5 | ||
}, | ||
// options - объект опций | ||
{ | ||
// можно перезаписать состояние стора вручную | ||
changeState: {}, | ||
// можно передать какие-то параметры в apollo.query | ||
apolloOptions: {} | ||
} | ||
); | ||
// Можно подождать ответа сразу | ||
try { | ||
const result = await store.loadData(/* ... */); | ||
} catch (error) { | ||
// ... | ||
} | ||
// А можно подписаться на все изменения стора | ||
store.state$.subscribe((state) => { | ||
const { loading, loaded, error, data, variables } = state; | ||
// ... | ||
}); | ||
``` | ||
const prostoreApollo = require('prostore-apollo'); | ||
// TODO: DEMONSTRATE API | ||
``` | ||
Для реализации бесконечной подгрузки, см. раздел | ||
["Пагинация с дозагрузкой"](https://gitlab.com/proscom/prostore/-/blob/master/packages/prostore/README.md#%D0%BF%D0%B0%D0%B3%D0%B8%D0%BD%D0%B0%D1%86%D0%B8%D1%8F-%D1%81-%D0%B4%D0%BE%D0%B7%D0%B0%D0%B3%D1%80%D1%83%D0%B7%D0%BA%D0%BE%D0%B9) | ||
документации `@proscom/prostore`. |
@@ -15,3 +15,4 @@ import { | ||
export interface IGraphqlQueryOptions<Vars> extends IRequestStoreOptions { | ||
export interface IGraphqlQueryOptions<Vars, Data> extends IRequestStoreOptions<Vars, Data> { | ||
/** Additional Apollo query options */ | ||
apolloOptions: ApolloQueryOptions<Vars>; | ||
@@ -22,12 +23,29 @@ } | ||
extends IRequestStoreParams<Vars, Data> { | ||
/** | ||
* GraphQL query definition using graphql AST from the graphql-tag packages | ||
* | ||
* (be sure to include ids wherever possible in order for Apoolo cache to work correctly) | ||
*/ | ||
query: DocumentNode; | ||
/** Apollo client to be used for fetching the data */ | ||
client: ApolloClient<any>; | ||
/** | ||
* Optional callback to transform the query result into the request store state. | ||
* Use it to remove unnecessary nesting or transform the data | ||
*/ | ||
mapData?: IMapData<Data>; | ||
/** Additional Apollo query options */ | ||
apolloOptions?: ApolloQueryOptions<Vars>; | ||
} | ||
/** | ||
* RequestStore tailored to make Apollo GraphQL requests | ||
*/ | ||
export class GraphqlQueryStore<Vars, Data> extends RequestStore< | ||
Vars, | ||
Data, | ||
IGraphqlQueryOptions<Vars> | ||
IGraphqlQueryOptions<Vars, Data> | ||
> { | ||
@@ -62,5 +80,11 @@ query: DocumentNode; | ||
/** | ||
* Performs actual GraphQL request using the Apollo Client | ||
* | ||
* @param variables - query variables | ||
* @param options - additional query options | ||
*/ | ||
async performRequest( | ||
variables: Vars, | ||
options: Partial<IGraphqlQueryOptions<Vars>> | ||
options: Partial<IGraphqlQueryOptions<Vars, Data>> | ||
): Promise<Data> { | ||
@@ -67,0 +91,0 @@ const result = await this.client.query({ |
@@ -17,3 +17,4 @@ import { from, Observable } from 'rxjs'; | ||
export interface IGraphqlWatchQueryOptions<Vars> extends IRequestStoreOptions { | ||
export interface IGraphqlWatchQueryOptions<Vars, Data> extends IRequestStoreOptions<Vars, Data> { | ||
/** Additional Apollo query options */ | ||
apolloOptions: ApolloWatchQueryOptions<Vars>; | ||
@@ -24,12 +25,30 @@ } | ||
extends IRequestStoreParams<Vars, Data> { | ||
/** | ||
* GraphQL query definition using graphql AST from the graphql-tag packages | ||
* | ||
* (be sure to include ids wherever possible in order for Apoolo cache to work correctly) | ||
*/ | ||
query: DocumentNode; | ||
/** Apollo client to be used for fetching the data */ | ||
client: ApolloClient<any>; | ||
/** | ||
* Optional callback to transform the query result into the request store state. | ||
* Use it to remove unnecessary nesting or transform the data | ||
*/ | ||
mapData?: IMapData<Data>; | ||
/** Additional Apollo query options */ | ||
apolloOptions?: ApolloWatchQueryOptions<Vars>; | ||
} | ||
/** | ||
* RequestStore tailored to make Apollo GraphQL requests. | ||
* It also subscribes to Apollo Cache by using watchQuery | ||
*/ | ||
export class GraphqlWatchQueryStore<Vars, Data> extends RequestStore< | ||
Vars, | ||
Data, | ||
IGraphqlWatchQueryOptions<Vars> | ||
IGraphqlWatchQueryOptions<Vars, Data> | ||
> { | ||
@@ -64,5 +83,11 @@ query: DocumentNode; | ||
/** | ||
* Performs actual GraphQL request using the Apollo Client | ||
* | ||
* @param variables - query variables | ||
* @param options - additional query options | ||
*/ | ||
performRequest( | ||
variables: Vars, | ||
options: IGraphqlWatchQueryOptions<Vars> | ||
options: IGraphqlWatchQueryOptions<Vars, Data> | ||
): Observable<Data> { | ||
@@ -69,0 +94,0 @@ const queryParams: WatchQueryOptions<Vars> = { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
0
113
44696
23
740
1
+ Added@proscom/prostore@0.1.13(transitive)
+ Addedtslib@2.8.1(transitive)
- Removed@proscom/prostore@0.0.20(transitive)
Updated@proscom/prostore@^0.1.0