New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.3.13 to 0.3.14

batching/queryMerging.d.ts

1

actions.d.ts

@@ -50,2 +50,3 @@ import { GraphQLResult } from 'graphql';

mutationId: string;
fragmentMap: FragmentMap;
}

@@ -52,0 +53,0 @@ export declare function isMutationInitAction(action: ApolloAction): action is MutationInitAction;

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

dataIdFromObject: config.dataIdFromObject,
fragmentMap: queryStoreValue.fragmentMap,
});

@@ -43,0 +44,0 @@ return newState;

56

data/storeUtils.js
"use strict";
var includes = require('lodash.includes');
function isScalarValue(value) {
var SCALAR_TYPES = ['IntValue', 'FloatValue', 'StringValue', 'BooleanValue'];
var SCALAR_TYPES = ['StringValue', 'BooleanValue'];
return includes(SCALAR_TYPES, value.kind);
}
function isNumberValue(value) {
var NUMBER_TYPES = ['IntValue', 'FloatValue'];
return includes(NUMBER_TYPES, value.kind);
}
function isVariable(value) {
return value.kind === 'Variable';
}
function isObject(value) {
return value.kind === 'ObjectValue';
}
function isList(value) {
return value.kind === 'ListValue';
}
function valueToObjectRepresentation(argObj, name, value, variables) {
if (isNumberValue(value)) {
argObj[name.value] = Number(value.value);
}
else if (isScalarValue(value)) {
argObj[name.value] = value.value;
}
else if (isObject(value)) {
var nestedArgObj_1 = {};
value.fields.map(function (obj) { return valueToObjectRepresentation(nestedArgObj_1, obj.name, obj.value, variables); });
argObj[name.value] = nestedArgObj_1;
}
else if (isVariable(value)) {
if (!variables || !(value.name.value in variables)) {
throw new Error("The inline argument \"" + value.name.value + "\" is expected as a variable but was not provided.");
}
var variableValue = variables[value.name.value];
argObj[name.value] = variableValue;
}
else if (isList(value)) {
argObj[name.value] = value.values.map(function (listValue) {
var nestedArgArrayObj = {};
valueToObjectRepresentation(nestedArgArrayObj, name, listValue, variables);
return nestedArgArrayObj[name.value];
});
}
else {
throw new Error("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\" is not supported.\n Use variables instead of inline arguments to overcome this limitation.");
}
}
function storeKeyNameFromField(field, variables) {

@@ -15,15 +55,3 @@ if (field.arguments && field.arguments.length) {

var name = _a.name, value = _a.value;
if (isScalarValue(value)) {
argObj_1[name.value] = value.value;
}
else if (isVariable(value)) {
if (!variables) {
throw new Error('Internal err: Field has a variable argument but variables not passed.');
}
var variableValue = variables[value.name.value];
argObj_1[name.value] = variableValue;
}
else {
throw new Error("For inline arguments, only scalar types are supported. To use Enum or Object types, please pass them as variables.");
}
return valueToObjectRepresentation(argObj_1, name, value, variables);
});

@@ -30,0 +58,0 @@ var stringifiedArgs = JSON.stringify(argObj_1);

import { ApolloAction } from '../actions';
import { SelectionSet } from 'graphql';
import { FragmentMap } from '../queries/getFromAST';
export interface MutationStore {

@@ -12,2 +13,3 @@ [mutationId: string]: MutationStoreValue;

error: Error;
fragmentMap: FragmentMap;
}

@@ -14,0 +16,0 @@ export interface SelectionSetWithRoot {

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

error: null,
fragmentMap: action.fragmentMap,
};

@@ -16,0 +17,0 @@ return newState;

import 'whatwg-fetch';
import { GraphQLResult } from 'graphql';
import { GraphQLResult, Document } from 'graphql';
import { MiddlewareInterface } from './middleware';
export interface Request {
debugName?: string;
query?: Document;
variables?: Object;
operationName?: string;
}
export interface PrintedRequest {
debugName?: string;
query?: string;
variables?: Object;
operationName?: string;
}

@@ -12,2 +19,5 @@ export interface NetworkInterface {

}
export interface BatchedNetworkInterface extends NetworkInterface {
batchQuery(requests: Request[]): Promise<GraphQLResult[]>;
}
export interface HTTPNetworkInterface extends NetworkInterface {

@@ -23,2 +33,4 @@ _uri: string;

}
export declare function addQueryMerging(networkInterface: NetworkInterface): BatchedNetworkInterface;
export declare function printRequest(request: Request): PrintedRequest;
export declare function createNetworkInterface(uri: string, opts?: RequestInit): HTTPNetworkInterface;

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

require('whatwg-fetch');
var printer_1 = require('graphql/language/printer');
var queryMerging_1 = require('./batching/queryMerging');
function addQueryMerging(networkInterface) {
return {
query: function (request) {
return networkInterface.query(request);
},
batchQuery: function (requests) {
var composedRequest = queryMerging_1.mergeRequests(requests);
return this.query(composedRequest).then(function (composedResult) {
return queryMerging_1.unpackMergedResult(composedResult, requests);
});
},
};
}
exports.addQueryMerging = addQueryMerging;
function printRequest(request) {
var printedRequest = {
debugName: request.debugName,
query: printer_1.print(request.query),
variables: request.variables,
operationName: request.operationName,
};
return printedRequest;
}
exports.printRequest = printRequest;
function createNetworkInterface(uri, opts) {

@@ -42,3 +68,3 @@ if (opts === void 0) { opts = {}; }

return fetch(uri, assign({}, _opts, options, {
body: JSON.stringify(request),
body: JSON.stringify(printRequest(request)),
headers: assign({}, options.headers, {

@@ -45,0 +71,0 @@ Accept: '*/*',

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

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

import { Document, OperationDefinition, FragmentDefinition } from 'graphql';
export declare function getMutationDefinition(doc: Document): OperationDefinition;
export declare function checkDocument(doc: Document): void;
export declare function getOperationName(doc: Document): string;
export declare function getFragmentDefinitions(doc: Document): FragmentDefinition[];

@@ -5,0 +6,0 @@ export declare function getQueryDefinition(doc: Document): OperationDefinition;

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

exports.checkDocument = checkDocument;
function getOperationName(doc) {
var res = '';
doc.definitions.forEach(function (definition) {
if (definition.kind === 'OperationDefinition'
&& definition.name) {
res = definition.name.value;
}
});
return res;
}
exports.getOperationName = getOperationName;
function getFragmentDefinitions(doc) {

@@ -35,0 +46,0 @@ checkDocument(doc);

@@ -78,7 +78,11 @@ "use strict";

mutationDef = queryTransform_1.applyTransformerToOperation(mutationDef, this.queryTransformer);
mutation = getFromAST_1.replaceOperationDefinition(mutation, mutationDef);
}
var mutationString = printer_1.print(mutationDef);
mutation = getFromAST_1.replaceOperationDefinition(mutation, mutationDef);
var mutationString = printer_1.print(mutation);
var queryFragmentMap = getFromAST_1.createFragmentMap(getFromAST_1.getFragmentDefinitions(mutation));
var request = {
query: mutationString,
query: mutation,
variables: variables,
operationName: getFromAST_1.getOperationName(mutation),
};

@@ -95,2 +99,3 @@ this.store.dispatch({

mutationId: mutationId,
fragmentMap: queryFragmentMap,
});

@@ -147,5 +152,2 @@ return this.networkInterface.query(request)

refetch: function (variables) {
if (pollingTimer) {
clearInterval(pollingTimer);
}
variables = variables || options.variables;

@@ -195,2 +197,3 @@ return _this.fetchQuery(queryId, assign(options, {

var minimizedQuery = querySS;
var minimizedQueryDoc = transformedQuery;
var initialResult;

@@ -221,2 +224,3 @@ if (!forceFetch) {

minimizedQueryString = printer_1.print(diffedQuery);
minimizedQueryDoc = diffedQuery;
}

@@ -226,2 +230,3 @@ else {

minimizedQueryString = null;
minimizedQueryDoc = null;
}

@@ -257,4 +262,5 @@ }

var request = {
query: minimizedQueryString,
query: minimizedQueryDoc,
variables: variables,
operationName: getFromAST_1.getOperationName(minimizedQueryDoc),
};

@@ -261,0 +267,0 @@ return this.networkInterface.query(request)

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