apollo-client
Advanced tools
Comparing version 0.4.12 to 0.4.13
@@ -279,2 +279,15 @@ "use strict"; | ||
} | ||
function collectUsedVariablesFromDirectives(directives) { | ||
return flatten(directives.map(function (directive) { | ||
if (directive.arguments) { | ||
return flatten(directive.arguments.map(function (arg) { | ||
if (arg.kind === 'Argument' && arg.value.kind === 'Variable') { | ||
return [arg.value.name.value]; | ||
} | ||
return []; | ||
})); | ||
} | ||
return []; | ||
})); | ||
} | ||
function collectUsedVariablesFromField(field) { | ||
@@ -293,2 +306,5 @@ var variables = []; | ||
} | ||
if (field.directives) { | ||
variables = variables.concat(collectUsedVariablesFromDirectives(field.directives)); | ||
} | ||
return uniq(variables); | ||
@@ -295,0 +311,0 @@ } |
import { NetworkInterface, createNetworkInterface, addQueryMerging } from './networkInterface'; | ||
import { Document, FragmentDefinition, SelectionSet } from 'graphql'; | ||
import { Document, FragmentDefinition } from 'graphql'; | ||
import { print } from 'graphql-tag/printer'; | ||
@@ -12,3 +12,3 @@ import { createApolloStore, ApolloStore, createApolloReducer, ApolloReducerConfig } from './store'; | ||
import { QueryTransformer, addTypenameToSelectionSet } from './queries/queryTransform'; | ||
import { MutationBehaviorReducerMap } from './data/mutationResults'; | ||
import { MutationBehavior, MutationBehaviorReducerMap, MutationQueryReducersMap } from './data/mutationResults'; | ||
export { createNetworkInterface, addQueryMerging, createApolloStore, createApolloReducer, readQueryFromStore, readFragmentFromStore, addTypenameToSelectionSet as addTypename, writeQueryToStore, writeFragmentToStore, print as printAST }; | ||
@@ -51,47 +51,17 @@ export declare type ApolloQueryResult = { | ||
}); | ||
watchQuery: (options: WatchQueryOptions) => ObservableQuery; | ||
query: (options: WatchQueryOptions) => Promise<{ | ||
data: any; | ||
loading: boolean; | ||
}>; | ||
mutate: (options: { | ||
watchQuery(options: WatchQueryOptions): ObservableQuery; | ||
query(options: WatchQueryOptions): Promise<ApolloQueryResult>; | ||
mutate(options: { | ||
mutation: Document; | ||
variables?: Object; | ||
resultBehaviors?: ({ | ||
type: "ARRAY_INSERT"; | ||
resultPath: (string | number)[]; | ||
storePath: (string | number)[]; | ||
where: "PREPEND" | "APPEND"; | ||
} | { | ||
type: "ARRAY_DELETE"; | ||
storePath: (string | number)[]; | ||
dataId: string; | ||
} | { | ||
type: "DELETE"; | ||
dataId: string; | ||
} | { | ||
type: "QUERY_RESULT"; | ||
queryVariables: any; | ||
querySelectionSet: SelectionSet; | ||
queryFragments: FragmentDefinition[]; | ||
newResult: Object; | ||
})[]; | ||
resultBehaviors?: MutationBehavior[]; | ||
fragments?: FragmentDefinition[]; | ||
optimisticResponse?: Object; | ||
updateQueries?: { | ||
[queryName: string]: (previousResult: Object, options: { | ||
mutationResult: Object; | ||
queryName: Object; | ||
queryVariables: Object; | ||
}) => Object; | ||
}; | ||
updateQueries?: MutationQueryReducersMap; | ||
refetchQueries?: string[]; | ||
}) => Promise<{ | ||
data: any; | ||
loading: boolean; | ||
}>; | ||
}): Promise<ApolloQueryResult>; | ||
reducer(): Function; | ||
middleware: () => (store: ApolloStore) => (next: any) => (action: any) => any; | ||
initStore(): void; | ||
private setStore; | ||
private setStore(store); | ||
} |
84
index.js
@@ -62,26 +62,2 @@ "use strict"; | ||
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; | ||
this.watchQuery = function (options) { | ||
_this.initStore(); | ||
if (!_this.shouldForceFetch && options.forceFetch) { | ||
options = assign({}, options, { | ||
forceFetch: false, | ||
}); | ||
} | ||
createFragment(options.query); | ||
return _this.queryManager.watchQuery(options); | ||
}; | ||
this.query = function (options) { | ||
_this.initStore(); | ||
if (!_this.shouldForceFetch && options.forceFetch) { | ||
options = assign({}, options, { | ||
forceFetch: false, | ||
}); | ||
} | ||
createFragment(options.query); | ||
return _this.queryManager.query(options); | ||
}; | ||
this.mutate = function (options) { | ||
_this.initStore(); | ||
return _this.queryManager.mutate(options); | ||
}; | ||
this.middleware = function () { | ||
@@ -97,16 +73,2 @@ return function (store) { | ||
}; | ||
this.setStore = function (store) { | ||
if (isUndefined(store.getState()[_this.reduxRootKey])) { | ||
throw new Error("Existing store does not use apolloReducer for " + _this.reduxRootKey); | ||
} | ||
_this.store = store; | ||
_this.queryManager = new QueryManager_1.QueryManager({ | ||
networkInterface: _this.networkInterface, | ||
reduxRootKey: _this.reduxRootKey, | ||
store: store, | ||
queryTransformer: _this.queryTransformer, | ||
shouldBatch: _this.shouldBatch, | ||
batchInterval: _this.batchInterval, | ||
}); | ||
}; | ||
this.reduxRootKey = reduxRootKey ? reduxRootKey : 'apollo'; | ||
@@ -129,3 +91,34 @@ this.initialState = initialState ? initialState : {}; | ||
}; | ||
this.watchQuery = this.watchQuery.bind(this); | ||
this.query = this.query.bind(this); | ||
this.mutate = this.mutate.bind(this); | ||
this.setStore = this.setStore.bind(this); | ||
} | ||
ApolloClient.prototype.watchQuery = function (options) { | ||
this.initStore(); | ||
if (!this.shouldForceFetch && options.forceFetch) { | ||
options = assign({}, options, { | ||
forceFetch: false, | ||
}); | ||
} | ||
createFragment(options.query); | ||
return this.queryManager.watchQuery(options); | ||
}; | ||
; | ||
ApolloClient.prototype.query = function (options) { | ||
this.initStore(); | ||
if (!this.shouldForceFetch && options.forceFetch) { | ||
options = assign({}, options, { | ||
forceFetch: false, | ||
}); | ||
} | ||
createFragment(options.query); | ||
return this.queryManager.query(options); | ||
}; | ||
; | ||
ApolloClient.prototype.mutate = function (options) { | ||
this.initStore(); | ||
return this.queryManager.mutate(options); | ||
}; | ||
; | ||
ApolloClient.prototype.reducer = function () { | ||
@@ -145,2 +138,17 @@ return store_1.createApolloReducer(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); | ||
} | ||
this.store = store; | ||
this.queryManager = new QueryManager_1.QueryManager({ | ||
networkInterface: this.networkInterface, | ||
reduxRootKey: this.reduxRootKey, | ||
store: store, | ||
queryTransformer: this.queryTransformer, | ||
shouldBatch: this.shouldBatch, | ||
batchInterval: this.batchInterval, | ||
}); | ||
}; | ||
; | ||
return ApolloClient; | ||
@@ -147,0 +155,0 @@ }()); |
@@ -86,2 +86,3 @@ "use strict"; | ||
_this.updateQuery(mapFn); | ||
return fetchMoreResult; | ||
}); | ||
@@ -95,3 +96,3 @@ }; | ||
handler: function (error, result) { | ||
var reducer = graphQLSubscriptionOptions.updateFunction; | ||
var reducer = graphQLSubscriptionOptions.updateQuery; | ||
if (error) { | ||
@@ -98,0 +99,0 @@ throw new Error(JSON.stringify(error)); |
{ | ||
"name": "apollo-client", | ||
"version": "0.4.12", | ||
"version": "0.4.13", | ||
"description": "A simple yet functional GraphQL client.", | ||
@@ -61,3 +61,3 @@ "main": "index.js", | ||
"isomorphic-fetch": "^2.2.1", | ||
"istanbul": "^0.4.2", | ||
"istanbul": "^0.4.5", | ||
"lodash": "^4.6.1", | ||
@@ -75,3 +75,3 @@ "lodash.mapvalues": "^4.3.0", | ||
"source-map-support": "^0.4.0", | ||
"tslint": "3.14.0", | ||
"tslint": "3.15.1", | ||
"typescript": "^2.0.0", | ||
@@ -78,0 +78,0 @@ "typings": "^1.0.0", |
@@ -22,3 +22,3 @@ # Apollo client | ||
## Contributing | ||
### Contributing | ||
@@ -29,2 +29,4 @@ [![Build status](https://travis-ci.org/apollostack/apollo-client.svg?branch=master)](https://travis-ci.org/apollostack/apollo-client) | ||
[Read the Apollo Contributor Guidelines.](CONTRIBUTING.md) | ||
Running tests locally: | ||
@@ -31,0 +33,0 @@ |
@@ -69,3 +69,3 @@ "use strict"; | ||
var interval = queryOptions.pollInterval; | ||
if (this.intervalQueries.hasOwnProperty(interval.toString())) { | ||
if (this.intervalQueries.hasOwnProperty(interval.toString()) && this.intervalQueries[interval].length > 0) { | ||
this.intervalQueries[interval].push(queryId); | ||
@@ -72,0 +72,0 @@ } |
@@ -25,3 +25,3 @@ import { Document, FragmentDefinition } from 'graphql'; | ||
fragments?: FragmentDefinition[]; | ||
updateFunction: (previousQueryResult: Object, options: { | ||
updateQuery: (previousQueryResult: Object, options: { | ||
subscriptionResult: Object; | ||
@@ -28,0 +28,0 @@ queryVariables: Object; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
273018
54
4012