@apollo-elements/mixins
Advanced tools
Comparing version 0.0.11 to 1.0.0
import { ApolloElementMixin } from './apollo-element-mixin'; | ||
import { ApolloError } from 'apollo-client'; | ||
import { stripUndefinedValues } from '@apollo-elements/lib/helpers.js'; | ||
import pick from 'crocks/helpers/pick'; | ||
import compose from 'crocks/helpers/compose'; | ||
const pickOptions = compose( | ||
stripUndefinedValues, | ||
pick([ | ||
'context', | ||
'errorPolicy', | ||
'fetchPolicy', | ||
'mutation', | ||
'optimisticResponse', | ||
'refetchQueries', | ||
'update', | ||
'awaitRefetchQueries', | ||
'variables', | ||
]) | ||
); | ||
/** | ||
@@ -36,2 +54,8 @@ * `ApolloMutationMixin`: class mixin for apollo-mutation elements. | ||
/** | ||
* Whether the mutation has been called | ||
* @type {Boolean} | ||
*/ | ||
this.called = false; | ||
/** | ||
* Whether to ignore the results of the mutation. | ||
@@ -111,25 +135,19 @@ * @type {Boolean} | ||
* | ||
* @param {Object} params | ||
* @param {Object} params.context | ||
* @param {ErrorPolicy} params.errorPolicy | ||
* @param {FetchPolicy} params.fetchPolicy | ||
* @param {DocumentNode} params.mutation | ||
* @param {Object|Function} params.optimisticResponse | ||
* @param {Array<DocumentNode>} params.refetchQueries | ||
* @param {UpdateFunction} params.update | ||
* @param {boolean} params.awaitRefetchQueries | ||
* @param {Object} params.variables | ||
* @param {Object} options | ||
* @param {Object} options.context | ||
* @param {ErrorPolicy} options.errorPolicy | ||
* @param {FetchPolicy} options.fetchPolicy | ||
* @param {DocumentNode} options.mutation | ||
* @param {Object|Function} options.optimisticResponse | ||
* @param {Array<DocumentNode>} options.refetchQueries | ||
* @param {UpdateFunction} options.update | ||
* @param {boolean} options.awaitRefetchQueries | ||
* @param {Object} options.variables | ||
* @return {Promise<FetchResult>} | ||
*/ | ||
async mutate({ | ||
context = this.context, | ||
errorPolicy = this.errorPolicy, | ||
fetchPolicy = this.fetchPolicy, | ||
mutation = this.mutation, | ||
optimisticResponse = this.optimisticResponse, | ||
refetchQueries = this.refetchQueries, | ||
update = this.update, | ||
awaitRefetchQueries = this.awaitRefetchQueries, | ||
variables = this.variables, | ||
} = {}) { | ||
...options | ||
} = this) { | ||
const mutationId = this.generateMutationId(); | ||
@@ -143,14 +161,8 @@ | ||
try { | ||
const response = await this.client.mutate({ | ||
context, | ||
errorPolicy, | ||
fetchPolicy, | ||
mutation, | ||
optimisticResponse, | ||
refetchQueries, | ||
update, | ||
awaitRefetchQueries, | ||
variables, | ||
}); | ||
const response = | ||
await this.client.mutate(pickOptions({ | ||
mutation, | ||
variables, | ||
...options, | ||
})); | ||
this.onCompletedMutation(response, mutationId); | ||
@@ -157,0 +169,0 @@ return response; |
import { ApolloElementMixin } from './apollo-element-mixin.js'; | ||
import { stripUndefinedValues } from '@apollo-elements/lib/helpers.js'; | ||
import hasAllVariables from '@apollo-elements/lib/has-all-variables.js'; | ||
import pick from 'crocks/helpers/pick'; | ||
import compose from 'crocks/helpers/compose'; | ||
const pickExecuteQueryOpts = compose( | ||
stripUndefinedValues, | ||
pick([ | ||
'context', | ||
'errorPolicy', | ||
'fetchPolicy', | ||
'fetchResults', | ||
'metadata', | ||
'query', | ||
'variables', | ||
]) | ||
); | ||
const pickOpts = compose( | ||
stripUndefinedValues, | ||
pick([ | ||
'context', | ||
'errorPolicy', | ||
'fetchPolicy', | ||
'fetchResults', | ||
'metadata', | ||
'notifyOnNetworkStatusChange', | ||
'pollInterval', | ||
'query', | ||
'variables', | ||
]) | ||
); | ||
/** | ||
@@ -190,21 +221,11 @@ * `ApolloQueryMixin`: class mixin for apollo-query elements. | ||
executeQuery({ | ||
metadata, | ||
context, | ||
query = this.query, | ||
variables = this.variables, | ||
fetchPolicy = this.fetchPolicy, | ||
errorPolicy = this.errorPolicy, | ||
fetchResults = this.fetchResults, | ||
...options | ||
} = this) { | ||
const opts = pickExecuteQueryOpts({ ...this, ...options, query, variables }); | ||
const queryPromise = | ||
this.client | ||
.query({ | ||
context, | ||
errorPolicy, | ||
fetchPolicy, | ||
fetchResults, | ||
metadata, | ||
query, | ||
variables, | ||
}) | ||
.query(opts) | ||
.catch(this.nextError.bind(this)); | ||
@@ -269,23 +290,8 @@ | ||
watchQuery({ | ||
context = this.context, | ||
errorPolicy = this.errorPolicy, | ||
fetchPolicy = this.fetchPolicy, | ||
fetchResults = this.fetchResults, | ||
metadata = this.metadata, | ||
notifyOnNetworkStatusChange = this.notifyOnNetworkStatusChange, | ||
pollInterval = this.pollInterval, | ||
query = this.query, | ||
variables = this.variables, | ||
...options | ||
} = this) { | ||
return this.client.watchQuery({ | ||
context, | ||
errorPolicy, | ||
fetchPolicy, | ||
fetchResults, | ||
metadata, | ||
notifyOnNetworkStatusChange, | ||
pollInterval, | ||
query, | ||
variables, | ||
}); | ||
const opts = pickOpts({ ...this, ...options, query, variables }); | ||
return this.client.watchQuery(opts); | ||
} | ||
@@ -292,0 +298,0 @@ |
@@ -309,3 +309,4 @@ import { chai, expect, html } from '@open-wc/testing'; | ||
const el = await getElement({ client, query }); | ||
expect(el.watchQuery()).to.be.an.instanceof(ObservableQuery); | ||
const actual = el.watchQuery(); | ||
expect(actual).to.be.an.instanceof(ObservableQuery); | ||
}); | ||
@@ -330,2 +331,27 @@ | ||
}); | ||
it('uses default options', async function() { | ||
const cache = client.defaultOptions; | ||
client.defaultOptions = { | ||
watchQuery: { | ||
notifyOnNetworkStatusChange: true, | ||
SOMETHING_SILLY: true, | ||
}, | ||
}; | ||
// HACK: oof | ||
client.initQueryManager(); | ||
const watchQueryStub = stub(client.queryManager, 'watchQuery'); | ||
const query = gql`query { foo }`; | ||
const el = await getElement({ client, query }); | ||
el.watchQuery({ query: undefined }); | ||
expect(watchQueryStub).to.have.been.calledWith(match({ | ||
query, | ||
notifyOnNetworkStatusChange: true, | ||
SOMETHING_SILLY: true, | ||
})); | ||
watchQueryStub.restore(); | ||
client.defaultOptions = cache; | ||
}); | ||
}); | ||
@@ -332,0 +358,0 @@ |
import isFunction from 'crocks/predicates/isFunction'; | ||
import hasAllVariables from '@apollo-elements/lib/has-all-variables.js'; | ||
import { stripUndefinedValues } from '@apollo-elements/lib/helpers.js'; | ||
import { ApolloElementMixin } from './apollo-element-mixin.js'; | ||
import hasAllVariables from '@apollo-elements/lib/has-all-variables.js'; | ||
@@ -109,3 +109,5 @@ /** | ||
if (!hasAllVariables({ query, variables })) return; | ||
this.observable = this.client.subscribe({ query, variables, fetchPolicy }); | ||
this.observable = this.client.subscribe( | ||
stripUndefinedValues({ query, variables, fetchPolicy }) | ||
); | ||
return this.observable.subscribe({ | ||
@@ -112,0 +114,0 @@ next: this.nextData, |
@@ -6,2 +6,13 @@ # Change Log | ||
# [1.0.0](https://github.com/apollo-elements/apollo-elements/compare/@apollo-elements/mixins@0.0.11...@apollo-elements/mixins@1.0.0) (2019-04-03) | ||
### Bug Fixes | ||
* **mixins:** allow default options in queries ([4a8895e](https://github.com/apollo-elements/apollo-elements/commit/4a8895e)) | ||
## [0.0.11](https://github.com/apollo-elements/apollo-elements/compare/@apollo-elements/mixins@0.0.10...@apollo-elements/mixins@0.0.11) (2019-03-01) | ||
@@ -8,0 +19,0 @@ |
{ | ||
"name": "@apollo-elements/mixins", | ||
"version": "0.0.11", | ||
"version": "1.0.0", | ||
"description": "👩🚀🌛 Custom Element class mixins for Apollo GraphQL 🚀👨🚀", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"docs": "polymer analyze -i index.js > docs/analysis.json", | ||
"test": "karma start karma.conf.js" | ||
"test": "echo \"Please run tests from the repository root\" && exit 1" | ||
}, | ||
@@ -32,3 +32,3 @@ "publishConfig": { | ||
"dependencies": { | ||
"@apollo-elements/lib": "^0.0.6", | ||
"@apollo-elements/lib": "^1.0.0", | ||
"apollo-client": "^2.4.12", | ||
@@ -42,3 +42,3 @@ "crocks": "^0.11.1" | ||
}, | ||
"gitHead": "6dd5f72ca26b577da2a0248e296d2260614ddb0d" | ||
"gitHead": "36a6a137c69795087edb47cb780008f4a43b06ee" | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
220436
31
2208
0
+ Added@apollo-elements/lib@1.1.3(transitive)
+ Addedgraphql@14.7.0(transitive)
+ Addediterall@1.3.0(transitive)
- Removed@apollo-elements/lib@0.0.6(transitive)
- Removedgraphql@15.10.1(transitive)
Updated@apollo-elements/lib@^1.0.0