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

apollo-client

Package Overview
Dependencies
Maintainers
2
Versions
309
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-client - npm Package Compare versions

Comparing version 0.4.15 to 0.4.16

2

actions.d.ts

@@ -0,1 +1,3 @@

/// <reference types="typed-graphql" />
/// <reference types="chai" />
import { GraphQLResult, SelectionSet, FragmentDefinition } from 'graphql';

@@ -2,0 +4,0 @@ import { SelectionSetWithRoot } from './queries/store';

@@ -0,1 +1,2 @@

/// <reference types="isomorphic-fetch" />
export interface AfterwareResponse {

@@ -2,0 +3,0 @@ response: IResponse;

@@ -0,1 +1,3 @@

/// <reference types="isomorphic-fetch" />
/// <reference types="typed-graphql" />
import { HTTPFetchNetworkInterface, RequestAndOptions, Request, BatchedNetworkInterface } from './networkInterface';

@@ -2,0 +4,0 @@ import { GraphQLResult } from 'graphql';

@@ -0,1 +1,2 @@

/// <reference types="typed-graphql" />
import { WatchQueryOptions } from './watchQueryOptions';

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

@@ -0,1 +1,3 @@

/// <reference types="typed-graphql" />
/// <reference types="chai" />
import { OperationDefinition, Field, FragmentDefinition, FragmentSpread, Document, SelectionSet, VariableDefinition, Variable, GraphQLResult } from 'graphql';

@@ -2,0 +4,0 @@ import { FragmentMap } from '../queries/getFromAST';

@@ -0,1 +1,3 @@

/// <reference types="typed-graphql" />
/// <reference types="chai" />
import { NormalizedCache } from './store';

@@ -2,0 +4,0 @@ import { SelectionSetWithRoot } from '../queries/store';

6

data/diffAgainstStore.js

@@ -6,3 +6,3 @@ "use strict";

var has = require('lodash.has');
var assign = require('lodash.assign');
var deepAssign = require('deep-assign');
var storeUtils_1 = require('./storeUtils');

@@ -111,3 +111,3 @@ var store_1 = require('./store');

if (isObject(fieldResult)) {
assign(result, fieldResult);
deepAssign(result, fieldResult);
}

@@ -150,3 +150,3 @@ if (!fragmentErrors[typename]) {

if (isObject(fieldResult)) {
assign(result, fieldResult);
deepAssign(result, fieldResult);
}

@@ -153,0 +153,0 @@ if (!fragmentErrors[typename]) {

@@ -0,1 +1,2 @@

/// <reference types="chai" />
export declare type IdGetter = (value: Object) => string;

@@ -2,0 +3,0 @@ export declare const getIdField: (data: {

@@ -0,1 +1,3 @@

/// <reference types="typed-graphql" />
/// <reference types="chai" />
import { NormalizedCache } from './store';

@@ -2,0 +4,0 @@ import { GraphQLResult, SelectionSet, FragmentDefinition } from 'graphql';

@@ -0,1 +1,3 @@

/// <reference types="typed-graphql" />
/// <reference types="chai" />
import { SelectionSet, Document } from 'graphql';

@@ -2,0 +4,0 @@ import { FragmentMap } from '../queries/getFromAST';

@@ -0,1 +1,3 @@

/// <reference types="typed-graphql" />
/// <reference types="chai" />
import { NormalizedCache } from './store';

@@ -2,0 +4,0 @@ import { SelectionSet, FragmentDefinition } from 'graphql';

@@ -0,1 +1,2 @@

/// <reference types="typed-graphql" />
import { FragmentMap } from '../queries/getFromAST';

@@ -2,0 +3,0 @@ import { SelectionSet } from 'graphql';

@@ -0,1 +1,3 @@

/// <reference types="typed-graphql" />
/// <reference types="chai" />
import { Field, InlineFragment, Selection, GraphQLResult } from 'graphql';

@@ -2,0 +4,0 @@ export declare function storeKeyNameFromField(field: Field, variables?: Object): string;

@@ -0,1 +1,3 @@

/// <reference types="chai" />
/// <reference types="typed-graphql" />
import { FragmentMap } from '../queries/getFromAST';

@@ -2,0 +4,0 @@ import { SelectionSet, Document } from 'graphql';

@@ -0,1 +1,2 @@

/// <reference types="typed-graphql" />
import { GraphQLError } from 'graphql';

@@ -2,0 +3,0 @@ export declare class ApolloError extends Error {

@@ -0,8 +1,10 @@

/// <reference types="typed-graphql" />
/// <reference types="chai" />
import { NetworkInterface, createNetworkInterface, addQueryMerging } from './networkInterface';
import { Document, FragmentDefinition } from 'graphql';
import { print } from 'graphql-tag/printer';
import { createApolloStore, ApolloStore, createApolloReducer, ApolloReducerConfig } from './store';
import { QueryManager, SubscriptionOptions } from './QueryManager';
import { createApolloStore, ApolloStore, createApolloReducer, ApolloReducerConfig, Store } from './store';
import { QueryManager, SubscriptionOptions, ResultComparator, ResultTransformer } from './QueryManager';
import { ObservableQuery } from './ObservableQuery';
import { Observable } from './util/Observable';
import { Observable, Subscription } from './util/Observable';
import { WatchQueryOptions } from './watchQueryOptions';

@@ -14,3 +16,5 @@ import { readQueryFromStore, readFragmentFromStore } from './data/readFromStore';

import { MutationBehavior, MutationBehaviorReducerMap, MutationQueryReducersMap } from './data/mutationResults';
export { createNetworkInterface, addQueryMerging, createApolloStore, createApolloReducer, readQueryFromStore, readFragmentFromStore, addTypenameToSelectionSet as addTypename, writeQueryToStore, writeFragmentToStore, print as printAST };
import { createFragmentMap } from './queries/getFromAST';
import { ApolloError } from './errors';
export { createNetworkInterface, addQueryMerging, createApolloStore, createApolloReducer, readQueryFromStore, readFragmentFromStore, addTypenameToSelectionSet as addTypename, writeQueryToStore, writeFragmentToStore, print as printAST, createFragmentMap, ApolloError, WatchQueryOptions, ObservableQuery, MutationBehavior, MutationQueryReducersMap, Subscription, ApolloStore };
export declare type ApolloQueryResult = {

@@ -20,2 +24,3 @@ data: any;

};
export declare type ApolloStateSelector = (state: any) => Store;
export declare let fragmentDefinitionsMap: {

@@ -32,2 +37,3 @@ [fragmentName: string]: FragmentDefinition[];

reduxRootKey: string;
reduxRootSelector: ApolloStateSelector | null;
initialState: any;

@@ -37,2 +43,4 @@ queryManager: QueryManager;

queryTransformer: QueryTransformer;
resultTransformer: ResultTransformer;
resultComparator: ResultComparator;
shouldBatch: boolean;

@@ -43,8 +51,11 @@ shouldForceFetch: boolean;

batchInterval: number;
constructor({networkInterface, reduxRootKey, initialState, dataIdFromObject, queryTransformer, shouldBatch, ssrMode, ssrForceFetchDelay, mutationBehaviorReducers, batchInterval}?: {
constructor({networkInterface, reduxRootKey, reduxRootSelector, initialState, dataIdFromObject, queryTransformer, resultTransformer, resultComparator, shouldBatch, ssrMode, ssrForceFetchDelay, mutationBehaviorReducers, batchInterval}?: {
networkInterface?: NetworkInterface;
reduxRootKey?: string;
reduxRootSelector?: string | ApolloStateSelector;
initialState?: any;
dataIdFromObject?: IdGetter;
queryTransformer?: QueryTransformer;
resultTransformer?: ResultTransformer;
resultComparator?: ResultComparator;
shouldBatch?: boolean;

@@ -51,0 +62,0 @@ ssrMode?: boolean;

@@ -11,2 +11,4 @@ "use strict";

var QueryManager_1 = require('./QueryManager');
var ObservableQuery_1 = require('./ObservableQuery');
exports.ObservableQuery = ObservableQuery_1.ObservableQuery;
var readFromStore_1 = require('./data/readFromStore');

@@ -22,5 +24,10 @@ exports.readQueryFromStore = readFromStore_1.readQueryFromStore;

var getFromAST_1 = require('./queries/getFromAST');
exports.createFragmentMap = getFromAST_1.createFragmentMap;
var errors_1 = require('./errors');
exports.ApolloError = errors_1.ApolloError;
var isUndefined = require('lodash.isundefined');
var assign = require('lodash.assign');
var flatten = require('lodash.flatten');
var isString = require('lodash.isstring');
var DEFAULT_REDUX_ROOT_KEY = 'apollo';
exports.fragmentDefinitionsMap = {};

@@ -60,6 +67,9 @@ var printFragmentWarnings = true;

exports.clearFragmentDefinitions = clearFragmentDefinitions;
function defaultReduxRootSelector(state) {
return state[DEFAULT_REDUX_ROOT_KEY];
}
var ApolloClient = (function () {
function ApolloClient(_a) {
var _this = this;
var _b = _a === void 0 ? {} : _a, networkInterface = _b.networkInterface, reduxRootKey = _b.reduxRootKey, initialState = _b.initialState, dataIdFromObject = _b.dataIdFromObject, queryTransformer = _b.queryTransformer, _c = _b.shouldBatch, shouldBatch = _c === void 0 ? false : _c, _d = _b.ssrMode, ssrMode = _d === void 0 ? false : _d, _e = _b.ssrForceFetchDelay, ssrForceFetchDelay = _e === void 0 ? 0 : _e, _f = _b.mutationBehaviorReducers, mutationBehaviorReducers = _f === void 0 ? {} : _f, batchInterval = _b.batchInterval;
var _b = _a === void 0 ? {} : _a, networkInterface = _b.networkInterface, reduxRootKey = _b.reduxRootKey, reduxRootSelector = _b.reduxRootSelector, initialState = _b.initialState, dataIdFromObject = _b.dataIdFromObject, queryTransformer = _b.queryTransformer, resultTransformer = _b.resultTransformer, resultComparator = _b.resultComparator, _c = _b.shouldBatch, shouldBatch = _c === void 0 ? false : _c, _d = _b.ssrMode, ssrMode = _d === void 0 ? false : _d, _e = _b.ssrForceFetchDelay, ssrForceFetchDelay = _e === void 0 ? 0 : _e, _f = _b.mutationBehaviorReducers, mutationBehaviorReducers = _f === void 0 ? {} : _f, batchInterval = _b.batchInterval;
this.middleware = function () {

@@ -75,3 +85,22 @@ return function (store) {

};
this.reduxRootKey = reduxRootKey ? reduxRootKey : 'apollo';
if (reduxRootKey && reduxRootSelector) {
throw new Error('Both "reduxRootKey" and "reduxRootSelector" are configured, but only one of two is allowed.');
}
if (reduxRootKey) {
console.warn('"reduxRootKey" option is deprecated and might be removed in the upcoming versions, ' +
'please use the "reduxRootSelector" instead.');
this.reduxRootKey = reduxRootKey;
}
if (!reduxRootSelector && reduxRootKey) {
this.reduxRootSelector = function (state) { return state[reduxRootKey]; };
}
else if (isString(reduxRootSelector)) {
this.reduxRootSelector = function (state) { return state[reduxRootSelector]; };
}
else if (typeof reduxRootSelector === 'function') {
this.reduxRootSelector = reduxRootSelector;
}
else {
this.reduxRootSelector = null;
}
this.initialState = initialState ? initialState : {};

@@ -81,2 +110,4 @@ this.networkInterface = networkInterface ? networkInterface :

this.queryTransformer = queryTransformer;
this.resultTransformer = resultTransformer;
this.resultComparator = resultComparator;
this.shouldBatch = shouldBatch;

@@ -137,4 +168,10 @@ this.shouldForceFetch = !(ssrMode || ssrForceFetchDelay > 0);

}
if (this.reduxRootSelector) {
throw new Error('Cannot initialize the store because "reduxRootSelector" or "reduxRootKey" is provided. ' +
'They should only be used when the store is created outside of the client. ' +
'This may lead to unexpected results when querying the store internally. ' +
"Please remove that option from ApolloClient constructor.");
}
this.setStore(store_1.createApolloStore({
reduxRootKey: this.reduxRootKey,
reduxRootKey: DEFAULT_REDUX_ROOT_KEY,
initialState: this.initialState,

@@ -150,4 +187,6 @@ config: this.reducerConfig,

ApolloClient.prototype.setStore = function (store) {
if (isUndefined(store.getState()[this.reduxRootKey])) {
throw new Error("Existing store does not use apolloReducer for " + this.reduxRootKey);
var reduxRootSelector = (this.reduxRootSelector) ? this.reduxRootSelector : defaultReduxRootSelector;
if (isUndefined(reduxRootSelector(store.getState()))) {
throw new Error('Existing store does not use apolloReducer. Please make sure the store ' +
'is properly configured and "reduxRootSelector" is correctly specified.');
}

@@ -157,5 +196,7 @@ this.store = store;

networkInterface: this.networkInterface,
reduxRootKey: this.reduxRootKey,
reduxRootSelector: reduxRootSelector,
store: store,
queryTransformer: this.queryTransformer,
resultTransformer: this.resultTransformer,
resultComparator: this.resultComparator,
shouldBatch: this.shouldBatch,

@@ -162,0 +203,0 @@ batchInterval: this.batchInterval,

@@ -0,1 +1,2 @@

/// <reference types="isomorphic-fetch" />
import { Request } from './networkInterface';

@@ -2,0 +3,0 @@ export interface MiddlewareRequest {

@@ -0,1 +1,3 @@

/// <reference types="chai" />
/// <reference types="typed-graphql" />
import { ApolloAction } from '../actions';

@@ -2,0 +4,0 @@ import { SelectionSet } from 'graphql';

@@ -0,1 +1,4 @@

/// <reference types="typed-graphql" />
/// <reference types="chai" />
/// <reference types="isomorphic-fetch" />
import 'whatwg-fetch';

@@ -2,0 +5,0 @@ import { GraphQLResult, Document } from 'graphql';

@@ -0,1 +1,2 @@

/// <reference types="chai" />
import { WatchQueryOptions, FetchMoreQueryOptions } from './watchQueryOptions';

@@ -2,0 +3,0 @@ import { Observable } from './util/Observable';

@@ -54,3 +54,4 @@ "use strict";

variables: variables,
}));
}))
.then(function (result) { return _this.queryManager.transformResult(result); });
};

@@ -104,3 +105,2 @@ this.fetchMore = function (fetchMoreOptions) {

this.stopPolling = function () {
_this.queryManager.stopQuery(_this.queryId);
if (isPollingQuery) {

@@ -107,0 +107,0 @@ _this.scheduler.stopPollingQuery(_this.queryId);

{
"name": "apollo-client",
"version": "0.4.15",
"version": "0.4.16",
"description": "A simple yet functional GraphQL client.",

@@ -23,3 +23,4 @@ "main": "index.js",

"dependencies": {
"es6-promise": "^3.1.2",
"es6-promise": "^3.3.1",
"deep-assign": "^2.0.0",
"graphql-tag": "^0.1.13",

@@ -50,2 +51,12 @@ "lodash.assign": "^4.0.8",

"devDependencies": {
"@types/async": "^2.0.31",
"@types/chai": "^3.4.32",
"@types/chai-as-promised": "0.0.28",
"@types/isomorphic-fetch": "0.0.30",
"@types/lodash": "^4.14.34",
"@types/mocha": "^2.2.31",
"@types/node": "^6.0.38",
"@types/promises-a-plus": "0.0.26",
"@types/redux": "^3.5.29",
"@types/sinon": "^1.16.29",
"async": "^2.0.0",

@@ -59,2 +70,3 @@ "browserify": "^13.0.0",

"es6-promise": "^3.1.2",
"typed-graphql": "1.0.1",
"grunt": "1.0.1",

@@ -79,5 +91,4 @@ "grunt-tslint": "3.2.1",

"typescript": "2.0.0",
"typings": "^1.0.0",
"uglify-js": "^2.6.2"
}
}

@@ -0,1 +1,2 @@

/// <reference types="typed-graphql" />
import { Selection } from 'graphql';

@@ -2,0 +3,0 @@ export declare function shouldInclude(selection: Selection, variables?: {

@@ -0,1 +1,2 @@

/// <reference types="typed-graphql" />
import { Document, OperationDefinition, FragmentDefinition } from 'graphql';

@@ -2,0 +3,0 @@ export declare function getMutationDefinition(doc: Document): OperationDefinition;

@@ -0,1 +1,2 @@

/// <reference types="typed-graphql" />
import { Document, SelectionSet } from 'graphql';

@@ -2,0 +3,0 @@ export declare type QueryTransformer = (selectionSet: SelectionSet) => void;

@@ -0,1 +1,3 @@

/// <reference types="chai" />
/// <reference types="typed-graphql" />
import { ApolloAction } from '../actions';

@@ -2,0 +4,0 @@ import { FragmentMap } from '../queries/getFromAST';

@@ -0,1 +1,4 @@

/// <reference types="typed-graphql" />
/// <reference types="node" />
/// <reference types="chai" />
import { NetworkInterface } from './networkInterface';

@@ -9,3 +12,3 @@ import { ApolloStore, Store } from './store';

import { QueryScheduler } from './scheduler';
import { ApolloQueryResult } from './index';
import { ApolloQueryResult, ApolloStateSelector } from './index';
import { Observer, Subscription, Observable } from './util/Observable';

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

}
export declare type ResultTransformer = (resultData: ApolloQueryResult) => ApolloQueryResult;
export declare type ResultComparator = (result1: ApolloQueryResult, result2: ApolloQueryResult) => boolean;
export declare class QueryManager {

@@ -30,4 +35,6 @@ pollingTimers: {

private networkInterface;
private reduxRootKey;
private reduxRootSelector;
private queryTransformer;
private resultTransformer;
private resultComparator;
private queryListeners;

@@ -41,7 +48,9 @@ private queryResults;

private queryIdsByName;
constructor({networkInterface, store, reduxRootKey, queryTransformer, shouldBatch, batchInterval}: {
constructor({networkInterface, store, reduxRootSelector, queryTransformer, resultTransformer, resultComparator, shouldBatch, batchInterval}: {
networkInterface: NetworkInterface;
store: ApolloStore;
reduxRootKey: string;
reduxRootSelector: ApolloStateSelector;
queryTransformer?: QueryTransformer;
resultTransformer?: ResultTransformer;
resultComparator?: ResultComparator;
shouldBatch?: Boolean;

@@ -87,2 +96,3 @@ batchInterval?: number;

};
transformResult(result: ApolloQueryResult): ApolloQueryResult;
private collectResultBehaviorsFromUpdateQueries(updateQueries, mutationResult, isOptimistic?);

@@ -89,0 +99,0 @@ private transformQueryDocument(options);

@@ -21,8 +21,10 @@ "use strict";

var _this = this;
var networkInterface = _a.networkInterface, store = _a.store, reduxRootKey = _a.reduxRootKey, queryTransformer = _a.queryTransformer, _b = _a.shouldBatch, shouldBatch = _b === void 0 ? false : _b, _c = _a.batchInterval, batchInterval = _c === void 0 ? 10 : _c;
var networkInterface = _a.networkInterface, store = _a.store, reduxRootSelector = _a.reduxRootSelector, queryTransformer = _a.queryTransformer, resultTransformer = _a.resultTransformer, resultComparator = _a.resultComparator, _b = _a.shouldBatch, shouldBatch = _b === void 0 ? false : _b, _c = _a.batchInterval, batchInterval = _c === void 0 ? 10 : _c;
this.idCounter = 0;
this.networkInterface = networkInterface;
this.store = store;
this.reduxRootKey = reduxRootKey;
this.reduxRootSelector = reduxRootSelector;
this.queryTransformer = queryTransformer;
this.resultTransformer = resultTransformer;
this.resultComparator = resultComparator;
this.pollingTimers = {};

@@ -106,3 +108,3 @@ this.batchInterval = batchInterval;

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

@@ -156,3 +158,3 @@ .catch(function (err) {

_this.queryResults[queryId] = resultFromStore;
observer.next(resultFromStore);
observer.next(_this.transformResult(resultFromStore));
}

@@ -217,3 +219,3 @@ }

QueryManager.prototype.getApolloState = function () {
return this.store.getState()[this.reduxRootKey];
return this.reduxRootSelector(this.store.getState());
};

@@ -369,2 +371,10 @@ QueryManager.prototype.getDataWithOptimisticResults = function () {

};
QueryManager.prototype.transformResult = function (result) {
if (!this.resultTransformer) {
return result;
}
else {
return this.resultTransformer(result);
}
};
QueryManager.prototype.collectResultBehaviorsFromUpdateQueries = function (updateQueries, mutationResult, isOptimistic) {

@@ -418,3 +428,3 @@ var _this = this;

selectionSet: queryDef.selectionSet,
store: this.store.getState()[this.reduxRootKey].data,
store: this.reduxRootSelector(this.store.getState()).data,
throwOnMissingField: false,

@@ -575,3 +585,4 @@ rootId: rootId,

QueryManager.prototype.isDifferentResult = function (queryId, result) {
return !isEqual(this.queryResults[queryId], result);
var comparator = this.resultComparator || isEqual;
return !comparator(this.queryResults[queryId], result);
};

@@ -578,0 +589,0 @@ QueryManager.prototype.broadcastQueries = function () {

@@ -0,1 +1,2 @@

/// <reference types="typed-graphql" />
import { OperationDefinition, VariableDefinition, Name, Document } from 'graphql';

@@ -2,0 +3,0 @@ import { SelectionSetWithRoot } from './queries/store';

@@ -18,3 +18,3 @@ # Apollo client

[Read the docs.](http://docs.apollostack.com/apollo-client/index.html)
[Read the docs.](http://dev.apollodata.com/core/)

@@ -21,0 +21,0 @@ ---

@@ -47,3 +47,4 @@ "use strict";

}
return redux_1.createStore(redux_1.combineReducers((_e = {}, _e[reduxRootKey] = createApolloReducer(config), _e)), initialState, redux_1.compose.apply(void 0, enhancers));
var compose = redux_1.compose;
return redux_1.createStore(redux_1.combineReducers((_e = {}, _e[reduxRootKey] = createApolloReducer(config), _e)), initialState, compose.apply(void 0, enhancers));
var _e;

@@ -50,0 +51,0 @@ }

@@ -0,1 +1,3 @@

/// <reference types="typed-graphql" />
/// <reference types="chai" />
import { Document, FragmentDefinition } from 'graphql';

@@ -2,0 +4,0 @@ export interface WatchQueryOptions {

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

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