apollo-client
Advanced tools
Comparing version 0.3.10 to 0.3.11
@@ -7,2 +7,3 @@ import { NetworkInterface, createNetworkInterface } from './networkInterface'; | ||
import { IdGetter } from './data/extensions'; | ||
import { QueryTransformer } from './queries/queryTransform'; | ||
export { createNetworkInterface, createApolloStore, createApolloReducer, readQueryFromStore, readFragmentFromStore }; | ||
@@ -16,3 +17,4 @@ export default class ApolloClient { | ||
reducerConfig: ApolloReducerConfig; | ||
constructor({networkInterface, reduxRootKey, initialState, dataIdFromObject}?: { | ||
queryTransformer: QueryTransformer; | ||
constructor({networkInterface, reduxRootKey, initialState, dataIdFromObject, queryTransformer}?: { | ||
networkInterface?: NetworkInterface; | ||
@@ -22,2 +24,3 @@ reduxRootKey?: string; | ||
dataIdFromObject?: IdGetter; | ||
queryTransformer?: QueryTransformer; | ||
}); | ||
@@ -24,0 +27,0 @@ watchQuery: (options: WatchQueryOptions) => ObservableQuery; |
@@ -15,3 +15,3 @@ "use strict"; | ||
var _this = this; | ||
var _b = _a === void 0 ? {} : _a, networkInterface = _b.networkInterface, reduxRootKey = _b.reduxRootKey, initialState = _b.initialState, dataIdFromObject = _b.dataIdFromObject; | ||
var _b = _a === void 0 ? {} : _a, networkInterface = _b.networkInterface, reduxRootKey = _b.reduxRootKey, initialState = _b.initialState, dataIdFromObject = _b.dataIdFromObject, queryTransformer = _b.queryTransformer; | ||
this.watchQuery = function (options) { | ||
@@ -48,2 +48,3 @@ _this.initStore(); | ||
store: store, | ||
queryTransformer: _this.queryTransformer, | ||
}); | ||
@@ -55,2 +56,3 @@ }; | ||
networkInterface_1.createNetworkInterface('/graphql'); | ||
this.queryTransformer = queryTransformer; | ||
this.reducerConfig = { | ||
@@ -57,0 +59,0 @@ dataIdFromObject: dataIdFromObject, |
{ | ||
"name": "apollo-client", | ||
"version": "0.3.10", | ||
"version": "0.3.11", | ||
"description": "A simple yet functional GraphQL client.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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 function addTypenameToQuery(queryDef: OperationDefinition): OperationDefinition; | ||
export declare function applyTransformerToOperation(queryDef: OperationDefinition, queryTransformer: QueryTransformer): OperationDefinition; |
"use strict"; | ||
var cloneDeep = require('lodash.clonedeep'); | ||
function addTypenameToSelectionSet(queryPiece) { | ||
function addFieldToSelectionSet(fieldName, queryPiece) { | ||
if (queryPiece == null || queryPiece.selections == null) { | ||
@@ -12,3 +12,3 @@ return queryPiece; | ||
kind: 'Name', | ||
value: '__typename', | ||
value: fieldName, | ||
}, | ||
@@ -24,2 +24,6 @@ }; | ||
} | ||
exports.addFieldToSelectionSet = addFieldToSelectionSet; | ||
function addTypenameToSelectionSet(queryPiece) { | ||
return addFieldToSelectionSet('__typename', queryPiece); | ||
} | ||
exports.addTypenameToSelectionSet = addTypenameToSelectionSet; | ||
@@ -32,2 +36,8 @@ function addTypenameToQuery(queryDef) { | ||
exports.addTypenameToQuery = addTypenameToQuery; | ||
function applyTransformerToOperation(queryDef, queryTransformer) { | ||
var queryClone = cloneDeep(queryDef); | ||
queryTransformer(queryClone.selectionSet); | ||
return queryClone; | ||
} | ||
exports.applyTransformerToOperation = applyTransformerToOperation; | ||
//# sourceMappingURL=queryTransform.js.map |
import { NetworkInterface } from './networkInterface'; | ||
import { ApolloStore } from './store'; | ||
import { QueryTransformer } from './queries/queryTransform'; | ||
import { GraphQLResult, Document } from 'graphql'; | ||
@@ -28,8 +29,10 @@ import { Observable, Observer, Subscription } from './util/Observable'; | ||
private pollingTimer; | ||
private queryTransformer; | ||
private queryListeners; | ||
private idCounter; | ||
constructor({networkInterface, store, reduxRootKey}: { | ||
constructor({networkInterface, store, reduxRootKey, queryTransformer}: { | ||
networkInterface: NetworkInterface; | ||
store: ApolloStore; | ||
reduxRootKey: string; | ||
queryTransformer?: QueryTransformer; | ||
}); | ||
@@ -36,0 +39,0 @@ broadcastNewStore(store: any): void; |
@@ -10,2 +10,3 @@ "use strict"; | ||
var getFromAST_1 = require('./queries/getFromAST'); | ||
var queryTransform_1 = require('./queries/queryTransform'); | ||
var printer_1 = require('graphql/language/printer'); | ||
@@ -46,3 +47,3 @@ var readFromStore_1 = require('./data/readFromStore'); | ||
var _this = this; | ||
var networkInterface = _a.networkInterface, store = _a.store, reduxRootKey = _a.reduxRootKey; | ||
var networkInterface = _a.networkInterface, store = _a.store, reduxRootKey = _a.reduxRootKey, queryTransformer = _a.queryTransformer; | ||
this.idCounter = 0; | ||
@@ -52,2 +53,3 @@ this.networkInterface = networkInterface; | ||
this.reduxRootKey = reduxRootKey; | ||
this.queryTransformer = queryTransformer; | ||
this.queryListeners = {}; | ||
@@ -68,3 +70,6 @@ if (this.store['subscribe']) { | ||
var mutationDef = getFromAST_1.getMutationDefinition(mutation); | ||
var mutationString = printer_1.print(mutation); | ||
if (this.queryTransformer) { | ||
mutationDef = queryTransform_1.applyTransformerToOperation(mutationDef, this.queryTransformer); | ||
} | ||
var mutationString = printer_1.print(mutationDef); | ||
var request = { | ||
@@ -167,2 +172,5 @@ query: mutationString, | ||
var queryDef = getFromAST_1.getQueryDefinition(query); | ||
if (this.queryTransformer) { | ||
queryDef = queryTransform_1.applyTransformerToOperation(queryDef, this.queryTransformer); | ||
} | ||
var queryString = printer_1.print(query); | ||
@@ -169,0 +177,0 @@ var querySS = { |
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
111193
1702