@apollo-elements/mixins
Advanced tools
Comparing version 3.4.3 to 3.5.0-alpha.0
import type { ApolloClient, NormalizedCacheObject } from '@apollo/client/core'; | ||
import type { ApolloElementInterface, CustomElement, Constructor } from '@apollo-elements/interfaces'; | ||
export declare function ApolloClientMixin<B extends Constructor<ApolloElementInterface & CustomElement>>(client: ApolloClient<NormalizedCacheObject>, superclass: B): B; | ||
import type { ApolloElementElement, Constructor } from '@apollo-elements/interfaces'; | ||
export declare function ApolloClientMixin<B extends Constructor<ApolloElementElement>>(client: ApolloClient<NormalizedCacheObject>, superclass: B): B; |
@@ -5,2 +5,3 @@ import { ApolloElementElement } from '@apollo-elements/interfaces'; | ||
import { ApolloClientMixin } from './apollo-client-mixin'; | ||
import { assertType } from '@apollo-elements/test-helpers'; | ||
describe('ApolloClientMixin', function () { | ||
@@ -28,2 +29,23 @@ let element; | ||
}); | ||
const client = window.__APOLLO_CLIENT__; | ||
import * as FAST from '@apollo-elements/fast'; | ||
class TypeCheckFAST extends ApolloClientMixin(client, FAST.ApolloQuery) { | ||
check() { | ||
assertType(this); | ||
assertType(this); | ||
assertType(this); | ||
assertType(this.data); | ||
assertType(this.variables); | ||
} | ||
} | ||
import * as Gluon from '@apollo-elements/gluon'; | ||
class TypeCheckGluon extends ApolloClientMixin(client, Gluon.ApolloQuery) { | ||
check() { | ||
assertType(this); | ||
assertType(this); | ||
assertType(this); | ||
assertType(this.data); | ||
assertType(this.variables); | ||
} | ||
} | ||
//# sourceMappingURL=apollo-client-mixin.test.js.map |
@@ -20,5 +20,4 @@ import type { ApolloError } from '@apollo/client/core'; | ||
} | ||
declare type MixinInstance = { | ||
new <D = unknown, V = Record<string, any>>(...a: any[]): ApolloElementInterface<D, V>; | ||
documentType: 'document' | 'query' | 'mutation' | 'subscription'; | ||
declare type MixinInstance = Constructor<ApolloElementInterface> & Pick<typeof ApolloElementInterface, keyof typeof ApolloElementInterface> & { | ||
observedAttributes?: string[]; | ||
}; | ||
@@ -25,0 +24,0 @@ declare function ApolloElementMixinImplementation<B extends Constructor>(superclass: B): MixinInstance & B; |
@@ -23,7 +23,6 @@ import { gql } from '@apollo/client/core'; | ||
function ApolloElementMixinImplementation(superclass) { | ||
// @ts-expect-error: https://github.com/microsoft/TypeScript/issues/37142 | ||
class ApolloElement extends superclass { | ||
constructor() { | ||
constructor(...a) { | ||
var _a; | ||
super(...arguments); | ||
super(...a); | ||
/** The Apollo Client instance. */ | ||
@@ -50,3 +49,3 @@ this.client = (_a = window.__APOLLO_CLIENT__) !== null && _a !== void 0 ? _a : null; /* c8 ignore next */ // covered | ||
else if (!isValidGql(document)) | ||
throw new TypeError(`${capital((_a = this.constructor.documentType) !== null && _a !== void 0 ? _a : 'document')} must be a gql-parsed DocumentNode`); | ||
throw new TypeError(`${capital((_a = this.constructor.documentType) !== null && _a !== void 0 ? _a : 'document')} must be a gql-parsed DocumentNode`); /* c8 ignore next */ | ||
else { | ||
@@ -133,5 +132,5 @@ this._document = document; | ||
var _a; | ||
// @ts-ignore: This is essentially a class accessor, I'm working around some TS limitations | ||
// @ts-expect-error: This is essentially a class accessor, I'm working around some TS limitations | ||
if (this.mo) // element is connected | ||
// @ts-ignore: This is essentially a class accessor, I'm working around some TS limitations | ||
// @ts-expect-error: This is essentially a class accessor, I'm working around some TS limitations | ||
(_a = this.variablesChanged) === null || _a === void 0 ? void 0 : _a.call(// element is connected | ||
@@ -142,3 +141,3 @@ this, variables); | ||
}); | ||
// @ts-expect-error: Actually, it is. | ||
// @ts-expect-error: let's pretend it is | ||
return ApolloElement; | ||
@@ -145,0 +144,0 @@ } |
@@ -288,7 +288,3 @@ import { gql } from '@apollo/client/core'; | ||
assertType(this.errors); | ||
assertType(this.data); | ||
assertType(this.variables); | ||
assertType(this.error.message); | ||
assertType(this.data.a); | ||
assertType(this.data.b); | ||
if (isApolloError(this.error)) | ||
@@ -299,8 +295,2 @@ assertType(this.error.graphQLErrors); | ||
} | ||
class TDNTypeCheck extends Test { | ||
typeCheck() { | ||
assertType(this.data); | ||
assertType(this.variables); | ||
} | ||
} | ||
//# sourceMappingURL=apollo-element-mixin.test.js.map |
@@ -12,4 +12,5 @@ import type { FetchResult } from '@apollo/client/core'; | ||
documentType: 'mutation'; | ||
observedAttributes?: string[]; | ||
}; | ||
declare function ApolloMutationMixinImpl<B extends Constructor>(superclass: B): MixinInstance & B; | ||
declare function ApolloMutationMixinImpl<B extends Constructor>(base: B): B & MixinInstance; | ||
/** | ||
@@ -16,0 +17,0 @@ * `ApolloMutationMixin`: class mixin for apollo-mutation elements. |
import { gqlDocument, writable } from '@apollo-elements/lib/descriptors'; | ||
import { dedupeMixin } from '@open-wc/dedupe-mixin'; | ||
import { ApolloElementMixin } from './apollo-element-mixin'; | ||
function ApolloMutationMixinImpl(superclass) { | ||
class ApolloMutationElement extends ApolloElementMixin(superclass) { | ||
constructor() { | ||
function ApolloMutationMixinImpl(base) { | ||
class ApolloMutationElement extends ApolloElementMixin(base) { | ||
constructor(...a) { | ||
var _a, _b; | ||
super(); | ||
super(...a); | ||
this.ignoreResults = false; | ||
@@ -17,2 +17,11 @@ /** | ||
} | ||
static get observedAttributes() { | ||
var _a; | ||
return [...new Set([ | ||
...(_a = super.observedAttributes) !== null && _a !== void 0 ? _a : [], | ||
'await-refetch-queries', | ||
'fetch-policy', | ||
'refetch-queries', | ||
])]; | ||
} | ||
connectedCallback() { | ||
@@ -22,2 +31,24 @@ var _a; | ||
} | ||
attributeChangedCallback(name, oldVal, newVal) { | ||
var _a, _b, _c, _d; | ||
(_a = super.attributeChangedCallback) === null || _a === void 0 ? void 0 : _a.call(this, name, oldVal, newVal); | ||
// @ts-expect-error: ts is not tracking the static side | ||
if ((_d = (_c = (_b = super.constructor) === null || _b === void 0 ? void 0 : _b.observedAttributes) === null || _c === void 0 ? void 0 : _c.includes) === null || _d === void 0 ? void 0 : _d.call(_c, name)) | ||
return; /* c8 ignore next */ | ||
switch (name) { /* c8 ignore next */ | ||
case 'await-refetch-queries': | ||
this.awaitRefetchQueries = | ||
this.hasAttribute('await-refetch-queries'); | ||
break; /* c8 ignore next */ | ||
case 'refetch-queries': | ||
this.refetchQueries = | ||
!newVal ? null : newVal | ||
.split(',') | ||
.map(x => x.trim()); | ||
break; /* c8 ignore next */ | ||
case 'fetch-policy': | ||
this.fetchPolicy = newVal; | ||
break; | ||
} | ||
} | ||
/** | ||
@@ -75,3 +106,3 @@ * This resolves a single mutation according to the options specified and returns a Promise which is either resolved with the resulting data or rejected with an error. | ||
this.error = null; | ||
this.data = data !== null && data !== void 0 ? data : null; | ||
this.data = data !== null && data !== void 0 ? data : null; /* c8 ignore next */ | ||
this.errors = (_a = response.errors) !== null && _a !== void 0 ? _a : null; | ||
@@ -78,0 +109,0 @@ if (data) |
@@ -7,4 +7,4 @@ import { NetworkStatus } from '@apollo/client/core'; | ||
class ApolloQueryElement extends ApolloElementMixin(superclass) { | ||
constructor() { | ||
super(...arguments); | ||
constructor(...a) { | ||
super(...a); | ||
this.errorPolicy = 'none'; | ||
@@ -16,2 +16,30 @@ /** @private */ | ||
} | ||
static get observedAttributes() { | ||
var _a; | ||
return [...new Set([ | ||
...(_a = super.observedAttributes) !== null && _a !== void 0 ? _a : [], | ||
'fetch-policy', | ||
'next-fetch-policy', | ||
])]; | ||
} | ||
get canAutoSubscribe() { | ||
return (!!this.client && | ||
!this.noAutoSubscribe && | ||
this.shouldSubscribe()); | ||
} | ||
attributeChangedCallback(name, oldVal, newVal) { | ||
var _a, _b, _c, _d; | ||
(_a = super.attributeChangedCallback) === null || _a === void 0 ? void 0 : _a.call(this, name, oldVal, newVal); | ||
// @ts-expect-error: ts is not tracking the static side | ||
if ((_d = (_c = (_b = super.constructor) === null || _b === void 0 ? void 0 : _b.observedAttributes) === null || _c === void 0 ? void 0 : _c.includes) === null || _d === void 0 ? void 0 : _d.call(_c, name)) | ||
return; | ||
switch (name) { | ||
case 'fetch-policy': | ||
this.fetchPolicy = newVal; | ||
break; | ||
case 'next-fetch-policy': | ||
this.nextFetchPolicy = newVal; | ||
break; | ||
} | ||
} | ||
connectedCallback() { | ||
@@ -60,3 +88,2 @@ super.connectedCallback(); | ||
* Override to prevent subscribing unless your conditions are met. | ||
* @protected | ||
*/ | ||
@@ -63,0 +90,0 @@ shouldSubscribe(options) { |
@@ -12,3 +12,3 @@ import type { ApolloSubscriptionInterface, Constructor, OnSubscriptionDataParams } from '@apollo-elements/interfaces'; | ||
}; | ||
declare function ApolloSubscriptionMixinImpl<B extends Constructor>(superclass: B): MixinInstance & B; | ||
declare function ApolloSubscriptionMixinImpl<B extends Constructor>(base: B): MixinInstance & B; | ||
/** | ||
@@ -15,0 +15,0 @@ * `ApolloSubscriptionMixin`: class mixin for apollo-subscription elements. |
import { dedupeMixin } from '@open-wc/dedupe-mixin'; | ||
import { ApolloElementMixin } from './apollo-element-mixin'; | ||
import { booleanAttr, gqlDocument } from '@apollo-elements/lib/descriptors'; | ||
function ApolloSubscriptionMixinImpl(superclass) { | ||
// @ts-expect-error: it is though | ||
class ApolloSubscriptionElement extends ApolloElementMixin(superclass) { | ||
constructor() { | ||
super(...arguments); | ||
function ApolloSubscriptionMixinImpl(base) { | ||
class ApolloSubscriptionElement extends ApolloElementMixin(base) { | ||
constructor(...a) { | ||
super(...a); | ||
this.notifyOnNetworkStatusChange = false; | ||
@@ -13,2 +12,7 @@ this.shouldResubscribe = false; | ||
} | ||
get canAutoSubscribe() { | ||
return (!!this.client && | ||
!this.noAutoSubscribe && | ||
this.shouldSubscribe()); | ||
} | ||
connectedCallback() { | ||
@@ -42,3 +46,3 @@ var _a; | ||
if (this.observableSubscription && !((_a = params === null || params === void 0 ? void 0 : params.shouldResubscribe) !== null && _a !== void 0 ? _a : this.shouldResubscribe)) | ||
return; | ||
return; /* c8 ignore next */ | ||
this.loading = true; | ||
@@ -95,3 +99,3 @@ this.observableSubscription = (_b = this.observable) === null || _b === void 0 ? void 0 : _b.subscribe({ | ||
var _a, _b; | ||
const data = (_a = result.data) !== null && _a !== void 0 ? _a : null; | ||
const data = (_a = result.data) !== null && _a !== void 0 ? _a : null; /* c8 ignore next */ | ||
// If we got to this line without a client, it's because of user error | ||
@@ -98,0 +102,0 @@ const client = this.client; // eslint-disable-line @typescript-eslint/no-non-null-assertion |
@@ -6,2 +6,18 @@ # Change Log | ||
# [3.5.0-alpha.0](https://github.com/apollo-elements/apollo-elements/compare/@apollo-elements/mixins@3.4.3...@apollo-elements/mixins@3.5.0-alpha.0) (2021-01-17) | ||
### Bug Fixes | ||
* data and variable types ([a5c919b](https://github.com/apollo-elements/apollo-elements/commit/a5c919bed9c69fd164e8ef66c54f8413c4192a1b)) | ||
### Features | ||
* add observed attributes ([43bf154](https://github.com/apollo-elements/apollo-elements/commit/43bf1544ecda358f4478d482f5c4cb0e1da60781)) | ||
## [3.4.3](https://github.com/apollo-elements/apollo-elements/compare/@apollo-elements/mixins@3.4.2...@apollo-elements/mixins@3.4.3) (2021-01-14) | ||
@@ -8,0 +24,0 @@ |
{ | ||
"name": "@apollo-elements/mixins", | ||
"version": "3.4.3", | ||
"version": "3.5.0-alpha.0", | ||
"description": "👩🚀🌛 Custom Element class mixins for Apollo GraphQL 🚀👨🚀", | ||
@@ -64,4 +64,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"@apollo-elements/interfaces": "^1.4.3", | ||
"@apollo-elements/lib": "^4.0.3", | ||
"@apollo-elements/interfaces": "^1.5.0-alpha.0", | ||
"@apollo-elements/lib": "^4.0.4-alpha.0", | ||
"@apollo/client": ">= 3", | ||
@@ -72,3 +72,3 @@ "@open-wc/dedupe-mixin": "^1.3.0", | ||
}, | ||
"gitHead": "66063e0845d6f49834608050789649944950449d" | ||
"gitHead": "1e9c95d0af349d86b2bb12e600ab27494abc472b" | ||
} |
import type { TypePolicies } from '@apollo/client/core'; | ||
import type { Policies } from '@apollo/client/cache/inmemory/policies'; | ||
import type { ApolloElementInterface, Constructor } from '@apollo-elements/interfaces'; | ||
import type { Policies } from '@apollo/client/cache/inmemory/policies'; | ||
declare module '@apollo/client/cache' { | ||
@@ -9,3 +9,4 @@ interface ApolloCache<TSerialized> { | ||
} | ||
declare type MixinInstance = { | ||
declare class MixinInstance { | ||
constructor(...a: any[]); | ||
/** | ||
@@ -15,3 +16,3 @@ * TypePolicies for the component | ||
typePolicies?: TypePolicies; | ||
}; | ||
} | ||
declare function TypePoliciesMixinImpl<B extends Constructor<ApolloElementInterface>>(superclass: B): MixinInstance & B; | ||
@@ -18,0 +19,0 @@ /** |
import { dedupeMixin } from '@open-wc/dedupe-mixin'; | ||
function TypePoliciesMixinImpl(superclass) { | ||
// @ts-expect-error: https://github.com/microsoft/TypeScript/issues/37142 | ||
class TypePoliciesElement extends superclass { | ||
@@ -4,0 +5,0 @@ connectedCallback() { |
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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
228805
1703
1