Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

slava-special-surprise

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slava-special-surprise - npm Package Compare versions

Comparing version 0.4.10 to 0.4.11

lib/src/util/errorHandling.d.ts

10

CHANGELOG.md

@@ -6,7 +6,15 @@ # Change log

### vNEXT
- Added an `refetchQueries` option to `mutate`. The point is to just refetch certain queries on a mutation rather than having to manually specify how the result should be incorporated for each of them with `updateQueries`. [PR #482](https://github.com/apollostack/apollo-client/pull/482) and [Issue #448](https://github.com/apollostack/apollo-client/issues/448).
### v0.4.10
- Fixed issue with alias names in batched queries. [PR #493](https://github.com/apollostack/apollo-client/pull/493) and [Issue #490](https://github.com/apollostack/apollo-client/issues).
- Add loading state tracking within Apollo Client in order to simplify the handling of loading state within the view layers. [Issue #342](https://github.com/apollostack/apollo-client/issues/342) and [PR #467](https://github.com/apollostack/apollo-client/pull/467)
- Fixed the way new variables extend the original arguments when passed to methods `fetchMore` and `refetch`. [PR #497](https://github.com/apollostack/apollo-client/pull/497).
### v0.4.9
- Fixed issue with `fragments` array for `updateQueries`. [PR #475](https://github.com/apollostack/apollo-client/pull/475) and [Issue #470](https://github.com/apollostack/apollo-client/issues/470).
- Add a new experimental feature to observable queries called `fetchMore`. It allows application developers to update the results of a query in the store by issuing new queries. We are currently testing this feature internally and we will document it once it is stable.
- Add a new experimental feature to observable queries called `fetchMore`. It allows application developers to update the results of a query in the store by issuing new queries. We are currently testing this feature internally and we will document it once it is stable. [PR #472](https://github.com/apollostack/apollo-client/pull/472).

@@ -13,0 +21,0 @@ ### v0.4.8

3

lib/src/batching/queryMerging.js
"use strict";
var getFromAST_1 = require('../queries/getFromAST');
var storeUtils_1 = require('../data/storeUtils');
var assign = require('lodash.assign');

@@ -32,3 +33,3 @@ var cloneDeep = require('lodash.clonedeep');

var field = fieldMap[mergeInfo.fieldIndex];
data[field.name.value] = result.data[dataKey];
data[storeUtils_1.resultKeyNameFromField(field)] = result.data[dataKey];
if (resultArray[childRequestIndex]) {

@@ -35,0 +36,0 @@ assign(resultArray[childRequestIndex].data, data);

@@ -16,2 +16,3 @@ import { NetworkInterface, createNetworkInterface, addQueryMerging } from './networkInterface';

data: any;
loading: boolean;
};

@@ -53,2 +54,3 @@ export declare let fragmentDefinitionsMap: {

data: any;
loading: boolean;
}>;

@@ -86,4 +88,6 @@ mutate: (options: {

};
refetchQueries?: string[];
}) => Promise<{
data: any;
loading: boolean;
}>;

@@ -90,0 +94,0 @@ reducer(): Function;

@@ -17,3 +17,3 @@ import { WatchQueryOptions, FetchMoreQueryOptions } from './watchQueryOptions';

options: WatchQueryOptions;
private queryId;
queryId: string;
private scheduler;

@@ -20,0 +20,0 @@ private queryManager;

@@ -8,2 +8,3 @@ "use strict";

var Observable_1 = require('./util/Observable');
var errorHandling_1 = require('./util/errorHandling');
var assign = require('lodash.assign');

@@ -46,3 +47,4 @@ var ObservableQuery = (function (_super) {

this.refetch = function (variables) {
variables = variables || _this.options.variables;
variables = variables || _this.options.variables ?
assign({}, _this.options.variables, variables) : undefined;
if (_this.options.noFetch) {

@@ -65,4 +67,6 @@ throw new Error('noFetch option should not use query refetch.');

else {
var variables = _this.options.variables || fetchMoreOptions.variables ?
assign({}, _this.options.variables, fetchMoreOptions.variables) : undefined;
combinedOptions = assign({}, _this.options, fetchMoreOptions, {
variables: assign({}, _this.options.variables, fetchMoreOptions.variables),
variables: variables,
});

@@ -78,12 +82,15 @@ }

var _a = _this.queryManager.getQueryWithPreviousResult(_this.queryId), previousResult = _a.previousResult, queryVariables = _a.queryVariables, querySelectionSet = _a.querySelectionSet, _b = _a.queryFragments, queryFragments = _b === void 0 ? [] : _b;
_this.queryManager.store.dispatch({
type: 'APOLLO_UPDATE_QUERY_RESULT',
newResult: reducer(previousResult, {
fetchMoreResult: fetchMoreResult,
var newResult = errorHandling_1.tryFunctionOrLogError(function () { return reducer(previousResult, {
fetchMoreResult: fetchMoreResult,
queryVariables: queryVariables,
}); });
if (newResult) {
_this.queryManager.store.dispatch({
type: 'APOLLO_UPDATE_QUERY_RESULT',
newResult: newResult,
queryVariables: queryVariables,
}),
queryVariables: queryVariables,
querySelectionSet: querySelectionSet,
queryFragments: queryFragments,
});
querySelectionSet: querySelectionSet,
queryFragments: queryFragments,
});
}
});

@@ -90,0 +97,0 @@ };

@@ -30,2 +30,3 @@ import { NetworkInterface } from './networkInterface';

private observableQueries;
private queryIdsByName;
constructor({networkInterface, store, reduxRootKey, queryTransformer, shouldBatch, batchInterval}: {

@@ -40,3 +41,3 @@ networkInterface: NetworkInterface;

broadcastNewStore(store: any): void;
mutate({mutation, variables, resultBehaviors, fragments, optimisticResponse, updateQueries}: {
mutate({mutation, variables, resultBehaviors, fragments, optimisticResponse, updateQueries, refetchQueries}: {
mutation: Document;

@@ -48,2 +49,3 @@ variables?: Object;

updateQueries?: MutationQueryReducersMap;
refetchQueries?: string[];
}): Promise<ApolloQueryResult>;

@@ -78,2 +80,3 @@ queryListenerForObserver(queryId: string, options: WatchQueryOptions, observer: Observer<ApolloQueryResult>): QueryListener;

private fetchQueryOverInterface(queryId, options, network);
private refetchQueryByName(queryName);
private isDifferentResult(queryId, result);

@@ -80,0 +83,0 @@ private broadcastQueries();

@@ -13,2 +13,3 @@ "use strict";

var scheduler_1 = require('./scheduler');
var errorHandling_1 = require('./util/errorHandling');
var errors_1 = require('./errors');

@@ -39,2 +40,3 @@ var ObservableQuery_1 = require('./ObservableQuery');

this.observableQueries = {};
this.queryIdsByName = {};
if (this.store['subscribe']) {

@@ -58,3 +60,3 @@ var currentStoreData_1;

var _this = this;
var mutation = _a.mutation, variables = _a.variables, _b = _a.resultBehaviors, resultBehaviors = _b === void 0 ? [] : _b, _c = _a.fragments, fragments = _c === void 0 ? [] : _c, optimisticResponse = _a.optimisticResponse, updateQueries = _a.updateQueries;
var mutation = _a.mutation, variables = _a.variables, _b = _a.resultBehaviors, resultBehaviors = _b === void 0 ? [] : _b, _c = _a.fragments, fragments = _c === void 0 ? [] : _c, optimisticResponse = _a.optimisticResponse, updateQueries = _a.updateQueries, _d = _a.refetchQueries, refetchQueries = _d === void 0 ? [] : _d;
var mutationId = this.generateQueryId();

@@ -103,2 +105,3 @@ mutation = getFromAST_1.addFragmentsToDocument(mutation, fragments);

});
refetchQueries.forEach(function (name) { _this.refetchQueryByName(name); });
resolve(result);

@@ -148,2 +151,3 @@ })

}),
loading: queryStoreValue.loading,
};

@@ -233,2 +237,8 @@ if (observer.next) {

this.observableQueries[queryId] = { observableQuery: observableQuery, subscriptions: [] };
var queryDef = getFromAST_1.getQueryDefinition(observableQuery.options.query);
if (queryDef.name && queryDef.name.value) {
var queryName = getFromAST_1.getQueryDefinition(observableQuery.options.query).name.value;
this.queryIdsByName[queryName] = this.queryIdsByName[queryName] || [];
this.queryIdsByName[queryName].push(observableQuery.queryId);
}
};

@@ -247,3 +257,8 @@ QueryManager.prototype.addQuerySubscription = function (queryId, querySubscription) {

QueryManager.prototype.removeObservableQuery = function (queryId) {
var observableQuery = this.observableQueries[queryId].observableQuery;
var queryName = getFromAST_1.getQueryDefinition(observableQuery.options.query).name.value;
delete this.observableQueries[queryId];
this.queryIdsByName[queryName] = this.queryIdsByName[queryName].filter(function (val) {
return !(observableQuery.queryId === val);
});
};

@@ -319,29 +334,24 @@ QueryManager.prototype.resetStore = function () {

var resultBehaviors = [];
var queryIdsByName = {};
Object.keys(this.observableQueries).forEach(function (queryId) {
var observableQuery = _this.observableQueries[queryId].observableQuery;
var queryName = getFromAST_1.getQueryDefinition(observableQuery.options.query).name.value;
queryIdsByName[queryName] =
queryIdsByName[queryName] || [];
queryIdsByName[queryName].push(queryId);
});
Object.keys(updateQueries).forEach(function (queryName) {
var reducer = updateQueries[queryName];
var queries = queryIdsByName[queryName];
if (!queries) {
var queryIds = _this.queryIdsByName[queryName];
if (!queryIds) {
return;
}
queries.forEach(function (queryId) {
queryIds.forEach(function (queryId) {
var _a = _this.getQueryWithPreviousResult(queryId, isOptimistic), previousResult = _a.previousResult, queryVariables = _a.queryVariables, querySelectionSet = _a.querySelectionSet, queryFragments = _a.queryFragments;
resultBehaviors.push({
type: 'QUERY_RESULT',
newResult: reducer(previousResult, {
mutationResult: mutationResult,
queryName: queryName,
var newResult = errorHandling_1.tryFunctionOrLogError(function () { return reducer(previousResult, {
mutationResult: mutationResult,
queryName: queryName,
queryVariables: queryVariables,
}); });
if (newResult) {
resultBehaviors.push({
type: 'QUERY_RESULT',
newResult: newResult,
queryVariables: queryVariables,
}),
queryVariables: queryVariables,
querySelectionSet: querySelectionSet,
queryFragments: queryFragments,
});
querySelectionSet: querySelectionSet,
queryFragments: queryFragments,
});
}
});

@@ -465,3 +475,3 @@ });

_this.removeFetchQueryPromise(requestId);
resolve({ data: resultFromStore });
resolve({ data: resultFromStore, loading: false });
}).catch(function (error) {

@@ -483,2 +493,8 @@ _this.store.dispatch({

};
QueryManager.prototype.refetchQueryByName = function (queryName) {
var _this = this;
this.queryIdsByName[queryName].forEach(function (queryId) {
_this.observableQueries[queryId].observableQuery.refetch();
});
};
QueryManager.prototype.isDifferentResult = function (queryId, result) {

@@ -485,0 +501,0 @@ return !isEqual(this.queryResults[queryId], result);

{
"name": "slava-special-surprise",
"version": "0.4.10",
"version": "0.4.11",
"description": "A simple yet functional GraphQL client.",

@@ -5,0 +5,0 @@ "main": "./lib/src/index.js",

@@ -52,2 +52,6 @@ // Implements a style of query merging in which two queries are merged together

import {
resultKeyNameFromField,
} from '../data/storeUtils';
import assign = require('lodash.assign');

@@ -100,3 +104,3 @@ import cloneDeep = require('lodash.clonedeep');

const field = fieldMap[mergeInfo.fieldIndex];
data[field.name.value] = result.data[dataKey];
data[resultKeyNameFromField(field)] = result.data[dataKey];

@@ -103,0 +107,0 @@ if (resultArray[childRequestIndex]) {

@@ -97,5 +97,6 @@ import {

data: any;
// Right now only has one property, but will later include loading state, and possibly other info
// This is different from the GraphQLResult type because it doesn't include errors - those are
// thrown via the standard promise/observer catch mechanism
loading: boolean;
// This type is different from the GraphQLResult type because it doesn't include errors.
// Those are thrown via the standard promise/observer catch mechanism.
}

@@ -261,2 +262,3 @@

updateQueries?: MutationQueryReducersMap,
refetchQueries?: string[],
}): Promise<ApolloQueryResult> => {

@@ -263,0 +265,0 @@ this.initStore();

@@ -17,2 +17,4 @@ import { WatchQueryOptions, FetchMoreQueryOptions } from './watchQueryOptions';

import { tryFunctionOrLogError } from './util/errorHandling';
import assign = require('lodash.assign');

@@ -33,3 +35,3 @@

public options: WatchQueryOptions;
private queryId: string;
public queryId: string;
private scheduler: QueryScheduler;

@@ -91,4 +93,6 @@ private queryManager: QueryManager;

this.refetch = (variables?: any) => {
// If no new variables passed, use existing variables
variables = variables || this.options.variables;
// Extend variables if available
variables = variables || this.options.variables ?
assign({}, this.options.variables, variables) : undefined;
if (this.options.noFetch) {

@@ -115,4 +119,7 @@ throw new Error('noFetch option should not use query refetch.');

// fetch the same query with a possibly new variables
const variables = this.options.variables || fetchMoreOptions.variables ?
assign({}, this.options.variables, fetchMoreOptions.variables) : undefined;
combinedOptions = assign({}, this.options, fetchMoreOptions, {
variables: assign({}, this.options.variables, fetchMoreOptions.variables),
variables,
});

@@ -135,12 +142,17 @@ }

this.queryManager.store.dispatch({
type: 'APOLLO_UPDATE_QUERY_RESULT',
newResult: reducer(previousResult, {
const newResult = tryFunctionOrLogError(() => reducer(
previousResult, {
fetchMoreResult,
queryVariables,
}),
queryVariables,
querySelectionSet,
queryFragments,
});
}));
if (newResult) {
this.queryManager.store.dispatch({
type: 'APOLLO_UPDATE_QUERY_RESULT',
newResult,
queryVariables,
querySelectionSet,
queryFragments,
});
}
});

@@ -147,0 +159,0 @@ };

@@ -83,2 +83,3 @@ import {

import { Observer, Subscription } from './util/Observable';
import { tryFunctionOrLogError } from './util/errorHandling';

@@ -130,2 +131,7 @@ import {

// A map going from the name of a query to an observer issued for it by watchQuery. This is
// generally used to refetches for refetchQueries and to update mutation results through
// updateQueries.
private queryIdsByName: { [queryName: string]: string[] };
constructor({

@@ -169,2 +175,3 @@ networkInterface,

this.observableQueries = {};
this.queryIdsByName = {};

@@ -199,2 +206,3 @@ // this.store is usually the fake store we get from the Redux middleware API

updateQueries,
refetchQueries = [],
}: {

@@ -207,2 +215,3 @@ mutation: Document,

updateQueries?: MutationQueryReducersMap,
refetchQueries?: string[],
}): Promise<ApolloQueryResult> {

@@ -270,2 +279,3 @@ const mutationId = this.generateQueryId();

refetchQueries.forEach((name) => { this.refetchQueryByName(name); });
resolve(result);

@@ -328,2 +338,3 @@ })

}),
loading: queryStoreValue.loading,
};

@@ -441,5 +452,15 @@

// Adds an ObservableQuery to this.observableQueries
// Adds an ObservableQuery to this.observableQueries and to this.observableQueriesByName.
public addObservableQuery(queryId: string, observableQuery: ObservableQuery) {
this.observableQueries[queryId] = { observableQuery, subscriptions: [] };
// Insert the ObservableQuery into this.observableQueriesByName if the query has a name
const queryDef = getQueryDefinition(observableQuery.options.query);
if (queryDef.name && queryDef.name.value) {
const queryName = getQueryDefinition(observableQuery.options.query).name.value;
// XXX we may we want to warn the user about query name conflicts in the future
this.queryIdsByName[queryName] = this.queryIdsByName[queryName] || [];
this.queryIdsByName[queryName].push(observableQuery.queryId);
}
}

@@ -460,3 +481,8 @@

public removeObservableQuery(queryId: string) {
const observableQuery = this.observableQueries[queryId].observableQuery;
const queryName = getQueryDefinition(observableQuery.options.query).name.value;
delete this.observableQueries[queryId];
this.queryIdsByName[queryName] = this.queryIdsByName[queryName].filter((val) => {
return !(observableQuery.queryId === val);
});
}

@@ -570,16 +596,6 @@

const queryIdsByName: { [name: string]: string[] } = {};
Object.keys(this.observableQueries).forEach((queryId) => {
const observableQuery = this.observableQueries[queryId].observableQuery;
const queryName = getQueryDefinition(observableQuery.options.query).name.value;
queryIdsByName[queryName] =
queryIdsByName[queryName] || [];
queryIdsByName[queryName].push(queryId);
});
Object.keys(updateQueries).forEach((queryName) => {
const reducer = updateQueries[queryName];
const queries = queryIdsByName[queryName];
if (!queries) {
const queryIds = this.queryIdsByName[queryName];
if (!queryIds) {
// XXX should throw an error?

@@ -589,3 +605,3 @@ return;

queries.forEach((queryId) => {
queryIds.forEach((queryId) => {
const {

@@ -598,13 +614,18 @@ previousResult,

resultBehaviors.push({
type: 'QUERY_RESULT',
newResult: reducer(previousResult, {
const newResult = tryFunctionOrLogError(() => reducer(
previousResult, {
mutationResult,
queryName,
queryVariables,
}),
queryVariables,
querySelectionSet,
queryFragments,
});
}));
if (newResult) {
resultBehaviors.push({
type: 'QUERY_RESULT',
newResult,
queryVariables,
querySelectionSet,
queryFragments,
});
}
});

@@ -775,3 +796,3 @@ });

this.removeFetchQueryPromise(requestId);
resolve({ data: resultFromStore });
resolve({ data: resultFromStore, loading: false });
}).catch((error: Error) => {

@@ -798,2 +819,10 @@ this.store.dispatch({

// Refetches a query given that query's name. Refetches
// all ObservableQuery instances associated with the query name.
private refetchQueryByName(queryName: string) {
this.queryIdsByName[queryName].forEach((queryId) => {
this.observableQueries[queryId].observableQuery.refetch();
});
}
// Given a query id and a new result, this checks if the old result is

@@ -800,0 +829,0 @@ // the same as the last result for that particular query id.

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc