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.13 to 0.4.14

batchedNetworkInterface.d.ts

2

batching.d.ts

@@ -23,5 +23,5 @@ import { WatchQueryOptions } from './watchQueryOptions';

enqueueRequest(request: QueryFetchRequest): Promise<GraphQLResult>;
consumeQueue(): Promise<GraphQLResult>[];
consumeQueue(): Promise<GraphQLResult>[] | undefined;
start(pollInterval: Number): void;
stop(): void;
}

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

if (this.queuedRequests.length < 1) {
return;
return undefined;
}

@@ -29,0 +29,0 @@ var requests = this.queuedRequests.map(function (queuedRequest) {

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

}).unpackedData;
return { data: unpackedData };
return assign({}, result, { data: unpackedData });
});

@@ -213,2 +213,10 @@ return resultArray;

exports.renameFragmentSpreads = renameFragmentSpreads;
function renameVariablesInArgument(argument, aliasName) {
if (argument.kind === 'Argument' &&
argument.value.kind === 'Variable') {
var varx = argument.value;
argument.value.name.value = getVariableAliasName(varx, aliasName);
}
return argument;
}
function renameVariables(selSet, aliasName) {

@@ -221,8 +229,13 @@ if (selSet && selSet.selections) {

field.arguments = field.arguments.map(function (argument) {
if (argument.kind === 'Argument' &&
argument.value.kind === 'Variable') {
var varx = argument.value;
argument.value.name.value = getVariableAliasName(varx, aliasName);
return renameVariablesInArgument(argument, aliasName);
});
}
if (field.directives) {
field.directives = field.directives.map(function (directive) {
if (directive.arguments) {
directive.arguments = directive.arguments.map(function (argument) {
return renameVariablesInArgument(argument, aliasName);
});
}
return argument;
return directive;
});

@@ -229,0 +242,0 @@ }

@@ -42,3 +42,3 @@ import { NormalizedCache } from './store';

export declare type MutationBehaviorReducer = (state: NormalizedCache, args: MutationBehaviorReducerArgs) => NormalizedCache;
export declare function cleanArray(originalArray: any, dataId: any): any;
export declare function cleanArray(originalArray: any[], dataId: any): any[];
export declare function mutationResultQueryResultReducer(state: NormalizedCache, {behavior, config}: MutationBehaviorReducerArgs): NormalizedCache;

@@ -45,0 +45,0 @@ export declare type MutationQueryReducer = (previousResult: Object, options: {

@@ -21,5 +21,5 @@ import { ApolloAction } from '../actions';

}
export declare type StoreValue = number | string | string[] | IdValue | JsonValue;
export declare type StoreValue = number | string | string[] | IdValue | JsonValue | undefined;
export declare function isIdValue(idObject: StoreValue): idObject is IdValue;
export declare function isJsonValue(jsonObject: StoreValue): jsonObject is JsonValue;
export declare function data(previousState: NormalizedCache, action: ApolloAction, queries: QueryStore, mutations: MutationStore, config: ApolloReducerConfig): NormalizedCache;

@@ -5,4 +5,5 @@ import { NetworkInterface, createNetworkInterface, addQueryMerging } from './networkInterface';

import { createApolloStore, ApolloStore, createApolloReducer, ApolloReducerConfig } from './store';
import { QueryManager } from './QueryManager';
import { QueryManager, SubscriptionOptions } from './QueryManager';
import { ObservableQuery } from './ObservableQuery';
import { Observable } from './util/Observable';
import { WatchQueryOptions } from './watchQueryOptions';

@@ -62,6 +63,8 @@ import { readQueryFromStore, readFragmentFromStore } from './data/readFromStore';

}): Promise<ApolloQueryResult>;
subscribe(options: SubscriptionOptions): Observable<any>;
reducer(): Function;
middleware: () => (store: ApolloStore) => (next: any) => (action: any) => any;
initStore(): void;
resetStore(): void;
private setStore(store);
}

@@ -121,2 +121,6 @@ "use strict";

;
ApolloClient.prototype.subscribe = function (options) {
this.initStore();
return this.queryManager.startGraphQLSubscription(options);
};
ApolloClient.prototype.reducer = function () {

@@ -136,2 +140,6 @@ return store_1.createApolloReducer(this.reducerConfig);

;
ApolloClient.prototype.resetStore = function () {
this.queryManager.resetStore();
};
;
ApolloClient.prototype.setStore = function (store) {

@@ -138,0 +146,0 @@ if (isUndefined(store.getState()[this.reduxRootKey])) {

@@ -7,3 +7,3 @@ import { Request } from './networkInterface';

export interface MiddlewareInterface {
applyMiddleware(request: MiddlewareRequest, next: Function): any;
applyMiddleware(request: MiddlewareRequest, next: Function): void;
}

@@ -10,2 +10,3 @@ import 'whatwg-fetch';

operationName?: string;
[additionalKey: string]: any;
}

@@ -23,3 +24,3 @@ export interface PrintedRequest {

export interface SubscriptionNetworkInterface extends NetworkInterface {
subscribe(request: Request, handler: (error, result) => void): number;
subscribe(request: Request, handler: (error: any, result: any) => void): number;
unsubscribe(id: Number): void;

@@ -48,2 +49,20 @@ }

export declare function printRequest(request: Request): PrintedRequest;
export declare function createNetworkInterface(uri: string, opts?: RequestInit): HTTPNetworkInterface;
export declare class HTTPFetchNetworkInterface implements NetworkInterface {
_uri: string;
_opts: RequestInit;
_middlewares: MiddlewareInterface[];
_afterwares: AfterwareInterface[];
constructor(uri: string, opts?: RequestInit);
applyMiddlewares({request, options}: RequestAndOptions): Promise<RequestAndOptions>;
applyAfterwares({response, options}: ResponseAndOptions): Promise<ResponseAndOptions>;
fetchFromRemoteEndpoint({request, options}: RequestAndOptions): Promise<IResponse>;
query(request: Request): Promise<GraphQLResult>;
use(middlewares: MiddlewareInterface[]): void;
useAfter(afterwares: AfterwareInterface[]): void;
}
export interface NetworkInterfaceOptions {
uri: string;
opts?: RequestInit;
transportBatching?: boolean;
}
export declare function createNetworkInterface(interfaceOpts: (NetworkInterfaceOptions | string), backOpts?: RequestInit): HTTPNetworkInterface;
"use strict";
var isString = require('lodash.isstring');
var assign = require('lodash.assign');
var mapValues = require('lodash.mapvalues');
require('whatwg-fetch');

@@ -24,24 +25,22 @@ var printer_1 = require('graphql-tag/printer');

function printRequest(request) {
var printedRequest = {
debugName: request.debugName,
query: printer_1.print(request.query),
variables: request.variables,
operationName: request.operationName,
};
return printedRequest;
return mapValues(request, function (val, key) {
return key === 'query' ? printer_1.print(val) : val;
});
}
exports.printRequest = printRequest;
function createNetworkInterface(uri, opts) {
if (opts === void 0) { opts = {}; }
if (!uri) {
throw new Error('A remote enpdoint is required for a network layer');
var HTTPFetchNetworkInterface = (function () {
function HTTPFetchNetworkInterface(uri, opts) {
if (opts === void 0) { opts = {}; }
if (!uri) {
throw new Error('A remote enpdoint is required for a network layer');
}
if (!isString(uri)) {
throw new Error('Remote endpoint must be a string');
}
this._uri = uri;
this._opts = assign({}, opts);
this._middlewares = [];
this._afterwares = [];
}
if (!isString(uri)) {
throw new Error('Remote endpoint must be a string');
}
var _uri = uri;
var _opts = assign({}, opts);
var _middlewares = [];
var _afterwares = [];
function applyMiddlewares(_a) {
HTTPFetchNetworkInterface.prototype.applyMiddlewares = function (_a) {
var _this = this;

@@ -65,6 +64,6 @@ var request = _a.request, options = _a.options;

};
queue(_middlewares.slice(), _this);
queue(_this._middlewares.slice(), _this);
});
}
function applyAfterwares(_a) {
};
HTTPFetchNetworkInterface.prototype.applyAfterwares = function (_a) {
var _this = this;

@@ -88,8 +87,8 @@ var response = _a.response, options = _a.options;

};
queue(_afterwares.slice(), _this);
queue(_this._afterwares.slice(), _this);
});
}
function fetchFromRemoteEndpoint(_a) {
};
HTTPFetchNetworkInterface.prototype.fetchFromRemoteEndpoint = function (_a) {
var request = _a.request, options = _a.options;
return fetch(uri, assign({}, _opts, options, {
return fetch(this._uri, assign({}, this._opts, options, {
body: JSON.stringify(printRequest(request)),

@@ -102,12 +101,13 @@ headers: assign({}, options.headers, {

}));
}
};
;
function query(request) {
var options = assign({}, _opts);
return applyMiddlewares({
HTTPFetchNetworkInterface.prototype.query = function (request) {
var _this = this;
var options = assign({}, this._opts);
return this.applyMiddlewares({
request: request,
options: options,
}).then(fetchFromRemoteEndpoint)
}).then(this.fetchFromRemoteEndpoint.bind(this))
.then(function (response) {
applyAfterwares({
_this.applyAfterwares({
response: response,

@@ -127,8 +127,9 @@ options: options,

});
}
};
;
function use(middlewares) {
HTTPFetchNetworkInterface.prototype.use = function (middlewares) {
var _this = this;
middlewares.map(function (middleware) {
if (typeof middleware.applyMiddleware === 'function') {
_middlewares.push(middleware);
_this._middlewares.push(middleware);
}

@@ -139,7 +140,8 @@ else {

});
}
function useAfter(afterwares) {
};
HTTPFetchNetworkInterface.prototype.useAfter = function (afterwares) {
var _this = this;
afterwares.map(function (afterware) {
if (typeof afterware.applyAfterware === 'function') {
_afterwares.push(afterware);
_this._afterwares.push(afterware);
}

@@ -150,14 +152,24 @@ else {

});
};
return HTTPFetchNetworkInterface;
}());
exports.HTTPFetchNetworkInterface = HTTPFetchNetworkInterface;
var batchedNetworkInterface_1 = require('./batchedNetworkInterface');
function createNetworkInterface(interfaceOpts, backOpts) {
if (backOpts === void 0) { backOpts = {}; }
if (isString(interfaceOpts) || !interfaceOpts) {
var uri = interfaceOpts;
return addQueryMerging(new HTTPFetchNetworkInterface(uri, backOpts));
}
return addQueryMerging({
_uri: _uri,
_opts: _opts,
_middlewares: _middlewares,
_afterwares: _afterwares,
query: query,
use: use,
useAfter: useAfter,
});
else {
var _a = interfaceOpts, _b = _a.transportBatching, transportBatching = _b === void 0 ? false : _b, _c = _a.opts, opts = _c === void 0 ? {} : _c, uri = _a.uri;
if (transportBatching) {
return new batchedNetworkInterface_1.HTTPBatchedNetworkInterface(uri, opts);
}
else {
return addQueryMerging(new HTTPFetchNetworkInterface(uri, opts));
}
}
}
exports.createNetworkInterface = createNetworkInterface;
//# sourceMappingURL=networkInterface.js.map

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

import { WatchQueryOptions, FetchMoreQueryOptions, GraphQLSubscriptionOptions } from './watchQueryOptions';
import { WatchQueryOptions, FetchMoreQueryOptions } from './watchQueryOptions';
import { Observable } from './util/Observable';

@@ -17,3 +17,2 @@ import { QueryScheduler } from './scheduler';

fetchMore: (options: FetchMoreQueryOptions & FetchMoreOptions) => Promise<any>;
startGraphQLSubscription: (options: GraphQLSubscriptionOptions) => number;
updateQuery: (mapFn: (previousQueryResult: any, options: UpdateQueryOptions) => any) => void;

@@ -20,0 +19,0 @@ stopPolling: () => void;

@@ -89,30 +89,2 @@ "use strict";

};
this.startGraphQLSubscription = function (graphQLSubscriptionOptions) {
var subOptions = {
query: graphQLSubscriptionOptions.subscription,
variables: graphQLSubscriptionOptions.variables,
fragments: graphQLSubscriptionOptions.fragments,
handler: function (error, result) {
var reducer = graphQLSubscriptionOptions.updateQuery;
if (error) {
throw new Error(JSON.stringify(error));
}
else {
var mapFn = function (previousResult, _a) {
var queryVariables = _a.queryVariables;
return reducer(previousResult, {
subscriptionResult: result,
queryVariables: queryVariables,
});
};
_this.updateQuery(mapFn);
}
},
};
if (graphQLSubscriptionOptions) {
return _this.queryManager.startSubscription(subOptions);
}
;
return null;
};
this.updateQuery = function (mapFn) {

@@ -119,0 +91,0 @@ var _a = _this.queryManager.getQueryWithPreviousResult(_this.queryId), previousResult = _a.previousResult, queryVariables = _a.queryVariables, querySelectionSet = _a.querySelectionSet, _b = _a.queryFragments, queryFragments = _b === void 0 ? [] : _b;

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

@@ -58,3 +58,3 @@ "main": "index.js",

"grunt": "1.0.1",
"grunt-tslint": "3.2.0",
"grunt-tslint": "3.2.1",
"gzip-size": "^3.0.0",

@@ -69,3 +69,3 @@ "isomorphic-fetch": "^2.2.1",

"nodemon": "^1.9.2",
"pretty-bytes": "^3.0.1",
"pretty-bytes": "^4.0.0",
"remap-istanbul": "^0.5.1",

@@ -77,3 +77,3 @@ "request-promise": "^4.0.1",

"tslint": "3.15.1",
"typescript": "^2.0.0",
"typescript": "2.0.0",
"typings": "^1.0.0",

@@ -80,0 +80,0 @@ "uglify-js": "^2.6.2"

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

import { ApolloQueryResult } from './index';
import { Observer, Subscription } from './util/Observable';
import { Observer, Subscription, Observable } from './util/Observable';
import { WatchQueryOptions } from './watchQueryOptions';

@@ -21,3 +21,2 @@ import { ObservableQuery } from './ObservableQuery';

fragments?: FragmentDefinition[];
handler: (error: Object, result: Object) => void;
}

@@ -76,3 +75,3 @@ export declare class QueryManager {

startQuery(queryId: string, options: WatchQueryOptions, listener: QueryListener): string;
startSubscription(options: SubscriptionOptions): number;
startGraphQLSubscription(options: SubscriptionOptions): Observable<any>;
stopQuery(queryId: string): void;

@@ -90,4 +89,4 @@ getQueryWithPreviousResult(queryId: string, isOptimistic?: boolean): {

private handleDiffQuery({queryDef, rootId, variables, fragmentMap, noFetch});
private fetchRequest({requestId, queryId, query, querySS, options, fragmentMap, networkInterface});
private fetchQueryOverInterface(queryId, options, networkInterface);
private fetchRequest({requestId, queryId, query, querySS, options, fragmentMap});
private fetchQueryOverInterface(queryId, options);
private refetchQueryByName(queryName);

@@ -94,0 +93,0 @@ private isDifferentResult(queryId, result);

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

var scheduler_1 = require('./scheduler');
var Observable_1 = require('./util/Observable');
var errorHandling_1 = require('./util/errorHandling');

@@ -199,3 +200,3 @@ var errors_1 = require('./errors');

QueryManager.prototype.fetchQuery = function (queryId, options) {
return this.fetchQueryOverInterface(queryId, options, this.networkInterface);
return this.fetchQueryOverInterface(queryId, options);
};

@@ -284,4 +285,5 @@ QueryManager.prototype.generateQueryId = function () {

};
QueryManager.prototype.startSubscription = function (options) {
var query = options.query, variables = options.variables, _a = options.fragments, fragments = _a === void 0 ? [] : _a, handler = options.handler;
QueryManager.prototype.startGraphQLSubscription = function (options) {
var _this = this;
var query = options.query, variables = options.variables, _a = options.fragments, fragments = _a === void 0 ? [] : _a;
var queryDoc = getFromAST_1.addFragmentsToDocument(query, fragments);

@@ -296,3 +298,31 @@ if (this.queryTransformer) {

};
return this.networkInterface.subscribe(request, handler);
var subId;
var observers = [];
return new Observable_1.Observable(function (observer) {
observers.push(observer);
if (observers.length === 1) {
var handler = function (error, result) {
if (error) {
observers.forEach(function (obs) {
obs.error(error);
});
}
else {
observers.forEach(function (obs) {
obs.next(result);
});
}
};
subId = _this.networkInterface.subscribe(request, handler);
}
return {
unsubscribe: function () {
observers = observers.filter(function (obs) { return obs !== observer; });
if (observers.length === 0) {
_this.networkInterface.unsubscribe(subId);
}
},
_networkSubscriptionId: subId,
};
});
};

@@ -411,3 +441,3 @@ ;

var _this = this;
var requestId = _a.requestId, queryId = _a.queryId, query = _a.query, querySS = _a.querySS, options = _a.options, fragmentMap = _a.fragmentMap, networkInterface = _a.networkInterface;
var requestId = _a.requestId, queryId = _a.queryId, query = _a.query, querySS = _a.querySS, options = _a.options, fragmentMap = _a.fragmentMap;
var variables = options.variables, noFetch = options.noFetch, returnPartialData = options.returnPartialData;

@@ -463,3 +493,3 @@ var request = {

};
QueryManager.prototype.fetchQueryOverInterface = function (queryId, options, networkInterface) {
QueryManager.prototype.fetchQueryOverInterface = function (queryId, options) {
var variables = options.variables, _a = options.forceFetch, forceFetch = _a === void 0 ? false : _a, _b = options.returnPartialData, returnPartialData = _b === void 0 ? false : _b, _c = options.noFetch, noFetch = _c === void 0 ? false : _c;

@@ -534,3 +564,2 @@ var _d = this.transformQueryDocument(options), queryDoc = _d.queryDoc, fragmentMap = _d.fragmentMap;

fragmentMap: fragmentMap,
networkInterface: networkInterface,
});

@@ -537,0 +566,0 @@ }

@@ -52,2 +52,5 @@ "use strict";

function getDataWithOptimisticResults(store) {
if (store.optimistic.length === 0) {
return store.data;
}
var patches = store.optimistic.map(function (opt) { return opt.data; });

@@ -54,0 +57,0 @@ return assign.apply(void 0, [{}, store.data].concat(patches));

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

export declare function tryFunctionOrLogError(f: any): any;
export declare function tryFunctionOrLogError(f: Function): any;

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

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

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