apollo-client
Advanced tools
Comparing version
@@ -19,3 +19,4 @@ import { NetworkInterface, createNetworkInterface } from './networkInterface'; | ||
shouldBatch: boolean; | ||
constructor({networkInterface, reduxRootKey, initialState, dataIdFromObject, queryTransformer, shouldBatch}?: { | ||
shouldForceFetch: boolean; | ||
constructor({networkInterface, reduxRootKey, initialState, dataIdFromObject, queryTransformer, shouldBatch, ssrMode, ssrForceFetchDelay}?: { | ||
networkInterface?: NetworkInterface; | ||
@@ -27,2 +28,4 @@ reduxRootKey?: string; | ||
shouldBatch?: boolean; | ||
ssrMode?: boolean; | ||
ssrForceFetchDelay?: number; | ||
}); | ||
@@ -29,0 +32,0 @@ watchQuery: (options: WatchQueryOptions) => ObservableQuery; |
@@ -20,5 +20,6 @@ "use strict"; | ||
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; | ||
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; | ||
this.watchQuery = function (options) { | ||
_this.initStore(); | ||
options.forceFetch = _this.shouldForceFetch && options.forceFetch; | ||
return _this.queryManager.watchQuery(options); | ||
@@ -28,2 +29,3 @@ }; | ||
_this.initStore(); | ||
options.forceFetch = _this.shouldForceFetch && options.forceFetch; | ||
return _this.queryManager.query(options); | ||
@@ -64,2 +66,6 @@ }; | ||
this.shouldBatch = shouldBatch; | ||
this.shouldForceFetch = !(ssrMode || ssrForceFetchDelay > 0); | ||
if (ssrForceFetchDelay) { | ||
setTimeout(function () { return _this.shouldForceFetch = true; }, ssrForceFetchDelay); | ||
} | ||
this.reducerConfig = { | ||
@@ -66,0 +72,0 @@ dataIdFromObject: dataIdFromObject, |
{ | ||
"name": "apollo-client", | ||
"version": "0.3.20", | ||
"version": "0.3.21", | ||
"description": "A simple yet functional GraphQL client.", | ||
@@ -25,2 +25,3 @@ "main": "index.js", | ||
"graphql": "^0.4.18 || ^0.5.0 || ^0.6.0", | ||
"graphql-tag": "^0.1.1", | ||
"lodash.assign": "^4.0.8", | ||
@@ -35,2 +36,3 @@ "lodash.clonedeep": "^4.3.2", | ||
"lodash.isboolean": "^3.0.3", | ||
"lodash.isequal": "^4.2.0", | ||
"lodash.isnull": "^3.0.0", | ||
@@ -41,3 +43,2 @@ "lodash.isnumber": "^3.0.3", | ||
"lodash.isundefined": "^3.0.1", | ||
"lodash.isequal": "^4.2.0", | ||
"redux": "^3.3.1", | ||
@@ -68,2 +69,4 @@ "symbol-observable": "^0.2.4", | ||
"request-promise": "^2.0.1", | ||
"rxjs": "^5.0.0-beta.7", | ||
"sinon": "^1.17.4", | ||
"source-map-support": "^0.4.0", | ||
@@ -74,5 +77,4 @@ "swapi-graphql": "^0.0.4", | ||
"typings": "^1.0.0", | ||
"uglify-js": "^2.6.2", | ||
"rxjs": "^5.0.0-beta.7" | ||
"uglify-js": "^2.6.2" | ||
} | ||
} |
import { SelectionSet, OperationDefinition } from 'graphql'; | ||
export declare type QueryTransformer = (queryPiece: SelectionSet) => void; | ||
export declare function addFieldToSelectionSet(fieldName: string, queryPiece: SelectionSet): SelectionSet; | ||
export declare function addTypenameToSelectionSet(queryPiece: SelectionSet): SelectionSet; | ||
export declare type QueryTransformer = (selectionSet: SelectionSet) => void; | ||
export declare function addFieldToSelectionSet(fieldName: string, selectionSet: SelectionSet): SelectionSet; | ||
export declare function addTypenameToSelectionSet(selectionSet: SelectionSet): SelectionSet; | ||
export declare function addTypenameToQuery(queryDef: OperationDefinition): OperationDefinition; | ||
export declare function applyTransformerToOperation(queryDef: OperationDefinition, queryTransformer: QueryTransformer): OperationDefinition; |
"use strict"; | ||
var cloneDeep = require('lodash.clonedeep'); | ||
function addFieldToSelectionSet(fieldName, queryPiece) { | ||
if (queryPiece == null || queryPiece.selections == null) { | ||
return queryPiece; | ||
function addFieldToSelectionSet(fieldName, selectionSet) { | ||
if (selectionSet == null || selectionSet.selections == null) { | ||
return selectionSet; | ||
} | ||
var typenameFieldAST = { | ||
var fieldAst = { | ||
kind: 'Field', | ||
@@ -15,13 +15,19 @@ alias: null, | ||
}; | ||
queryPiece.selections.map(function (child) { | ||
if (child.kind === 'Field' || child.kind === 'InlineFragment') { | ||
addTypenameToSelectionSet(child.selectionSet); | ||
var alreadyHasThisField = false; | ||
selectionSet.selections.map(function (selection) { | ||
if (selection.kind === 'Field' || selection.kind === 'InlineFragment') { | ||
addTypenameToSelectionSet(selection.selectionSet); | ||
} | ||
if (selection.kind === 'Field' && selection.name.value === fieldName) { | ||
alreadyHasThisField = true; | ||
} | ||
}); | ||
queryPiece.selections.push(typenameFieldAST); | ||
return queryPiece; | ||
if (!alreadyHasThisField) { | ||
selectionSet.selections.push(fieldAst); | ||
} | ||
return selectionSet; | ||
} | ||
exports.addFieldToSelectionSet = addFieldToSelectionSet; | ||
function addTypenameToSelectionSet(queryPiece) { | ||
return addFieldToSelectionSet('__typename', queryPiece); | ||
function addTypenameToSelectionSet(selectionSet) { | ||
return addFieldToSelectionSet('__typename', selectionSet); | ||
} | ||
@@ -28,0 +34,0 @@ exports.addTypenameToSelectionSet = addTypenameToSelectionSet; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
177035
-0.53%21
5%28
3.7%70
-4.11%2613
-0.95%+ Added
+ Added