Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@apollo-elements/atomico

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apollo-elements/atomico - npm Package Compare versions

Comparing version 1.0.1-next.0 to 2.0.0

14

package.json
{
"name": "@apollo-elements/atomico",
"version": "1.0.1-next.0",
"version": "2.0.0",
"description": "👩‍🚀 Atomico Hooks for Apollo GraphQL 🌛",

@@ -34,8 +34,4 @@ "main": "index.js",

"prepublishOnly": "tsc -b .",
"build": "tsc",
"analyze": "custom-elements-manifest analyze",
"lint": "run-s lint:*",
"lint:types": "tsc --noEmit",
"start": "tsc -w --noEmit",
"test": "echo \"Please run tests from the repository root\" && exit 1"
"test": "wtr --coverage --config ../../web-test-runner.config.js --root-dir '../..' './*.test.ts'"
},

@@ -58,7 +54,7 @@ "repository": {

"dependencies": {
"@apollo-elements/core": "^1.0.1-next.0",
"@atomico/hooks": "^3.10.5",
"atomico": "^1.26.1"
"@apollo-elements/core": "^2.0.0",
"@atomico/hooks": "^3.20.2",
"atomico": "^1.34.0"
},
"customElements": "custom-elements.json"
}

@@ -1,7 +0,7 @@

import type { ComponentDocument, Data, MaybeTDN, MaybeVariables, Variables } from '@apollo-elements/core/types';
import type { ComponentDocument, Data, Variables } from '@apollo-elements/core/types';
import type { FetchResult, MutationOptions } from '@apollo/client/core';
import { ApolloMutationController, ApolloMutationControllerOptions } from '@apollo-elements/core/apollo-mutation-controller';
export declare function useMutation<D extends MaybeTDN = MaybeTDN, V = MaybeVariables<D>>(mutation: ComponentDocument<D>, options?: ApolloMutationControllerOptions<D, V>): [
export declare function useMutation<D, V>(mutation: ComponentDocument<D, V>, options?: ApolloMutationControllerOptions<D, V>): [
(params?: Partial<MutationOptions<Data<D>, Variables<D, V>>>) => Promise<FetchResult<Data<D>>>,
ApolloMutationController<D, V>
];

@@ -21,3 +21,2 @@ import * as S from '@apollo-elements/test/schema';

function Renderer() {
var _a, _b;
const [username, setUsername] = useState('');

@@ -45,3 +44,3 @@ const [haircolor, setHaircolor] = useState('');

<output id="output">We'll call you ${(_b = (_a = data === null || data === void 0 ? void 0 : data.updateUser) === null || _a === void 0 ? void 0 : _a.nickname) !== null && _b !== void 0 ? _b : 'nothing'}!</output>
<output id="output">We'll call you ${data?.updateUser?.nickname ?? 'nothing'}!</output>
</host>

@@ -48,0 +47,0 @@ `;

@@ -1,3 +0,3 @@

import type { ComponentDocument, MaybeTDN, MaybeVariables } from '@apollo-elements/core/types';
import type { ComponentDocument } from '@apollo-elements/core/types';
import { ApolloQueryController, ApolloQueryControllerOptions } from '@apollo-elements/core/apollo-query-controller';
export declare function useQuery<D extends MaybeTDN = MaybeTDN, V = MaybeVariables<D>>(query: ComponentDocument<D>, options?: ApolloQueryControllerOptions<D, V>): ApolloQueryController<D, V>;
export declare function useQuery<D, V>(query: ComponentDocument<D, V>, options?: ApolloQueryControllerOptions<D, V>): ApolloQueryController<D, V>;

@@ -1,2 +0,1 @@

import { ObservableQuery, } from '@apollo/client/core';
import * as S from '@apollo-elements/test/schema';

@@ -9,3 +8,3 @@ import { gql } from '@apollo/client/core';

import { sendKeys } from '@web/test-runner-commands';
import { assertType, makeClient, nextNAsync, resetMessages, setupClient, teardownClient, } from '@apollo-elements/test';
import { assertType, resetMessages, setupClient, teardownClient } from '@apollo-elements/test';
import { spy, useFakeTimers } from 'sinon';

@@ -24,10 +23,16 @@ describe('[atomico] useQuery', function () {

let element;
let refetchSpy;
let startPolling;
let stopPolling;
let executeQuery;
afterEach(function () {
refetchSpy?.restore?.();
});
beforeEach(async function define() {
function Hello() {
var _a, _b;
const con = useQuery(S.HelloQuery);
const { data, error, loading } = con;
useEffect(() => {
({ executeQuery } = con);
({ executeQuery, stopPolling, startPolling } = con);
refetchSpy = spy(con, 'refetch');
}, [con]);

@@ -39,5 +44,5 @@ return html `

<h2>${'😢 Such Sad, Very Error! 😰'}</h2>
<pre><code>${error === null || error === void 0 ? void 0 : error.message}</code></pre>
<pre><code>${error?.message}</code></pre>
</article>
<p>${(_a = data === null || data === void 0 ? void 0 : data.helloWorld) === null || _a === void 0 ? void 0 : _a.greeting}, ${(_b = data === null || data === void 0 ? void 0 : data.helloWorld) === null || _b === void 0 ? void 0 : _b.name}!</p>
<p>${data?.helloWorld?.greeting}, ${data?.helloWorld?.name}!</p>
</host>

@@ -51,2 +56,19 @@ `;

beforeEach(nextFrame);
describe('calling startPolling then stopPolling', function () {
let clock;
beforeEach(() => clock = useFakeTimers());
afterEach(() => clock.restore());
beforeEach(() => startPolling(1000));
beforeEach(() => clock.tick(3500));
it('refetches', function () {
expect(refetchSpy).to.have.been.calledThrice;
});
describe('then stopPolling', function () {
beforeEach(() => stopPolling());
beforeEach(() => clock.tick(5000));
it('stops calling refetch', function () {
expect(refetchSpy).to.have.been.calledThrice;
});
});
});
describe('calling executeQuery', function () {

@@ -77,3 +99,2 @@ beforeEach(async function () {

function Hello() {
var _a;
const { data, error, executeQuery } = useQuery(S.NullableParamQuery, {

@@ -87,4 +108,4 @@ onData, onError,

<host shadowDom>
<p id="data">${(_a = data === null || data === void 0 ? void 0 : data.nullableParam) === null || _a === void 0 ? void 0 : _a.nullable}</p>
<p id="error">${error === null || error === void 0 ? void 0 : error.message}</p>
<p id="data">${data?.nullableParam?.nullable}</p>
<p id="error">${error?.message}</p>
</host>

@@ -130,3 +151,2 @@ `;

function Hello() {
var _a, _b;
[offset, setOffset] = useState(0);

@@ -142,3 +162,3 @@ ({ data, fetchMore } = useQuery(S.PaginatedQuery, {

<host shadowDom>
<p id="data">${(_b = (_a = data === null || data === void 0 ? void 0 : data.pages) === null || _a === void 0 ? void 0 : _a.join) === null || _b === void 0 ? void 0 : _b.call(_a, ',')}</p>
<p id="data">${data?.pages?.join?.(',')}</p>
</host>

@@ -182,6 +202,5 @@ `;

function Hello() {
var _a;
const { data, subscribeToMore: s } = useQuery(S.MessagesQuery);
useEffect(() => { subscribeToMore = s; }, [s]);
const messages = (_a = data === null || data === void 0 ? void 0 : data.messages) !== null && _a !== void 0 ? _a : [];
const messages = data?.messages ?? [];
return html `

@@ -232,3 +251,2 @@ <host shadowDom>

function Hello() {
var _a, _b;
const [name, setName] = useState('');

@@ -242,3 +260,3 @@ const [greeting, setGreeting] = useState('');

useEffect(() => {
if (variables !== (options === null || options === void 0 ? void 0 : options.variables))
if (variables !== options?.variables)
refetch(variables);

@@ -251,5 +269,5 @@ }, [variables]);

<h2>${'😢 Such Sad, Very Error! 😰'}</h2>
<pre><code>${error === null || error === void 0 ? void 0 : error.message}</code></pre>
<pre><code>${error?.message}</code></pre>
</article>
<p>${(_a = data === null || data === void 0 ? void 0 : data.helloWorld.greeting) !== null && _a !== void 0 ? _a : 'Hello'}, ${(_b = data === null || data === void 0 ? void 0 : data.helloWorld.name) !== null && _b !== void 0 ? _b : 'Friend'}!</p>
<p>${data?.helloWorld.greeting ?? 'Hello'}, ${data?.helloWorld.name ?? 'Friend'}!</p>
<input id="name" oninput=${onInput(setName)}/>

@@ -304,3 +322,2 @@ <input id="greeting" oninput=${onInput(setGreeting)}/>

function Hello() {
var _a, _b;
const { data } = useQuery(S.HelloQuery, {

@@ -314,3 +331,3 @@ variables: {

<host shadowDom>
<p>${(_a = data === null || data === void 0 ? void 0 : data.helloWorld) === null || _a === void 0 ? void 0 : _a.greeting}, ${(_b = data === null || data === void 0 ? void 0 : data.helloWorld) === null || _b === void 0 ? void 0 : _b.name}!</p>
<p>${data?.helloWorld?.greeting}, ${data?.helloWorld?.name}!</p>
</host>

@@ -334,7 +351,6 @@ `;

function Hello() {
var _a;
const { data, subscribe } = useQuery(S.HelloQuery, { shouldSubscribe: () => false });
return html `
<host shadowDom>
<output>${(_a = data === null || data === void 0 ? void 0 : data.helloWorld) === null || _a === void 0 ? void 0 : _a.greeting}</output>
<output>${data?.helloWorld?.greeting}</output>
<button onclick=${() => subscribe()}></button>

@@ -363,43 +379,5 @@ </host>

});
describe('polling', function () {
let clock;
let element;
let pollSpy;
let startPolling;
let stopPolling;
beforeEach(teardownClient);
beforeEach(() => clock = useFakeTimers(new Date()));
beforeEach(async function define() {
const Component = defineCE(c(function Poller() {
var _a;
const con = useQuery(S.HelloQuery, { client: makeClient(), noAutoSubscribe: true });
useEffect(() => {
({ stopPolling, startPolling } = con);
pollSpy = spy(ObservableQuery.prototype, 'reobserve');
}, [con]);
return html `${JSON.stringify((_a = con.data) !== null && _a !== void 0 ? _a : null)}`;
}));
element = fixture(html `<${Component}></${Component}>`);
await element.updated;
});
afterEach(() => { var _a; return (_a = pollSpy === null || pollSpy === void 0 ? void 0 : pollSpy.restore) === null || _a === void 0 ? void 0 : _a.call(pollSpy); });
afterEach(() => clock.restore());
describe('calling startPolling then stopPolling', function () {
beforeEach(() => startPolling(1000));
beforeEach(() => nextNAsync(clock, 2));
it('polls', function () {
expect(pollSpy).to.have.been.calledThrice;
});
describe('then stopPolling', function () {
beforeEach(() => stopPolling());
beforeEach(() => nextNAsync(clock, 5));
it('stops polling', function () {
expect(pollSpy).to.have.been.calledThrice;
});
});
});
});
});
const TDN = gql `query TypedQuery($c: String, $d: Int) { a b }`;
(function () {
function TDNTypeCheck() {
const { called, client, data, error, fetchMore, loading, networkStatus, variables, refetch, startPolling, stopPolling, subscribeToMore, } = useQuery(TDN);

@@ -435,3 +413,3 @@ assertType(called);

});
});
}
//# sourceMappingURL=useQuery.test.js.map

@@ -1,3 +0,3 @@

import type { ComponentDocument, MaybeTDN, MaybeVariables } from '@apollo-elements/core/types';
import type { ComponentDocument, VariablesOf } from '@apollo-elements/core/types';
import { ApolloSubscriptionController, ApolloSubscriptionControllerOptions } from '@apollo-elements/core/apollo-subscription-controller';
export declare function useSubscription<D extends MaybeTDN, V = MaybeVariables<D>>(query: ComponentDocument<D>, options?: ApolloSubscriptionControllerOptions<D, V>): ApolloSubscriptionController<D, V>;
export declare function useSubscription<D, V = VariablesOf<D>>(query: ComponentDocument<D, V>, options?: ApolloSubscriptionControllerOptions<D, V>): ApolloSubscriptionController<D, V>;

@@ -14,5 +14,4 @@ import * as S from '@apollo-elements/test/schema';

function Renderer() {
var _a, _b;
const { data } = useSubscription(S.NullableParamSubscription, { noAutoSubscribe: true });
return html `<host shadowDom>${(_b = (_a = data === null || data === void 0 ? void 0 : data.nullableParam) === null || _a === void 0 ? void 0 : _a.nullable) !== null && _b !== void 0 ? _b : 'nothing'}</host>`;
return html `<host shadowDom>${data?.nullableParam?.nullable ?? 'nothing'}</host>`;
}

@@ -54,3 +53,2 @@ const Component = c(Renderer);

function Renderer() {
var _a, _b;
const { data, subscribe } = useSubscription(S.NullableParamSubscription, {

@@ -60,3 +58,3 @@ shouldSubscribe: () => false,

doSubscribe = subscribe;
return html `<host shadowDom>${(_b = (_a = data === null || data === void 0 ? void 0 : data.nullableParam) === null || _a === void 0 ? void 0 : _a.nullable) !== null && _b !== void 0 ? _b : 'nothing'}</host>`;
return html `<host shadowDom>${data?.nullableParam?.nullable ?? 'nothing'}</host>`;
}

@@ -90,3 +88,2 @@ const Component = c(Renderer);

function Renderer() {
var _a;
const { data, error, loading, subscribe } = useSubscription(S.NoParamSubscription, {

@@ -105,5 +102,5 @@ noAutoSubscribe: true,

<h2>${'😢 Such Sad, Very Error! 😰'}</h2>
<pre><code>${error === null || error === void 0 ? void 0 : error.message}</code></pre>
<pre><code>${error?.message}</code></pre>
</article>
<p>${(_a = data === null || data === void 0 ? void 0 : data.noParam.noParam) !== null && _a !== void 0 ? _a : 'fail'}</p>
<p>${data?.noParam.noParam ?? 'fail'}</p>
</host>

@@ -150,3 +147,2 @@ `;

function Renderer() {
var _a;
const { data, error, loading, subscribe } = useSubscription(S.NullableParamSubscription, {

@@ -165,3 +161,3 @@ noAutoSubscribe: true,

}, [loading]);
const nullable = (_a = data === null || data === void 0 ? void 0 : data.nullableParam.nullable) !== null && _a !== void 0 ? _a : 'NullableParam';
const nullable = data?.nullableParam.nullable ?? 'NullableParam';
return html `

@@ -172,3 +168,3 @@ <host shadowDom>

<h2>${'😢 Such Sad, Very Error! 😰'}</h2>
<pre><code>${error === null || error === void 0 ? void 0 : error.message}</code></pre>
<pre><code>${error?.message}</code></pre>
</article>

@@ -249,4 +245,3 @@ <p>${nullable}</p>

it('refetches', function () {
var _a, _b;
expect((_b = (_a = subscription.data) === null || _a === void 0 ? void 0 : _a.nullableParam) === null || _b === void 0 ? void 0 : _b.nullable).to.be.a.string;
expect(subscription.data?.nullableParam?.nullable).to.be.a.string;
});

@@ -261,5 +256,4 @@ it('unsets loading', function () {

it('does not fetch data', function () {
var _a, _b;
expect((_a = subscription === null || subscription === void 0 ? void 0 : subscription.options) === null || _a === void 0 ? void 0 : _a.onData).to.not.have.been.called;
expect((_b = subscription === null || subscription === void 0 ? void 0 : subscription.options) === null || _b === void 0 ? void 0 : _b.onError).to.not.have.been.called;
expect(subscription?.options?.onData).to.not.have.been.called;
expect(subscription?.options?.onError).to.not.have.been.called;
});

@@ -304,4 +298,3 @@ describe('when query will reject', function () {

afterEach(function restoreClientSubscription() {
var _a, _b, _c;
(_c = (_b = (_a = s.client) === null || _a === void 0 ? void 0 : _a.subscribe).restore) === null || _c === void 0 ? void 0 : _c.call(_b);
s.client?.subscribe.restore?.();
});

@@ -314,4 +307,3 @@ afterEach(function teardownElement() {

it('does not subscribe', function () {
var _a;
expect((_a = s.options) === null || _a === void 0 ? void 0 : _a.onData).to.not.have.been.called;
expect(s.options?.onData).to.not.have.been.called;
});

@@ -326,4 +318,3 @@ describe('when subscribe() rejects', function () {

it('sets error', function () {
var _a;
expect((_a = s.error) === null || _a === void 0 ? void 0 : _a.message, 'message').to.equal('error');
expect(s.error?.message, 'message').to.equal('error');
expect(s.options.onError).to.have.been.calledWithMatch({

@@ -375,3 +366,3 @@ message: 'error',

const context = {};
beforeEach(() => { var _a, _b; return (_b = (_a = s.client.subscribe).resetHistory) === null || _b === void 0 ? void 0 : _b.call(_a); });
beforeEach(() => s.client.subscribe.resetHistory?.());
beforeEach(() => s.subscribe({ context }));

@@ -398,3 +389,3 @@ it('uses provided context', function () {

describe('subscribe({ errorPolicy })', function () {
beforeEach(() => { var _a, _b; return (_b = (_a = s.client.subscribe).resetHistory) === null || _b === void 0 ? void 0 : _b.call(_a); });
beforeEach(() => s.client.subscribe.resetHistory?.());
beforeEach(() => s.subscribe({ errorPolicy: 'all' }));

@@ -439,4 +430,3 @@ it('uses provided errorPolicy', function () {

it('calls client.subscribe() twice', function () {
var _a;
expect((_a = s.client) === null || _a === void 0 ? void 0 : _a.subscribe).to.have.been.calledTwice;
expect(s.client?.subscribe).to.have.been.calledTwice;
});

@@ -451,4 +441,3 @@ });

it('calls client.subscribe() with controller subscription', function () {
var _a;
expect((_a = s.client) === null || _a === void 0 ? void 0 : _a.subscribe).to.have.been.calledWithMatch({
expect(s.client?.subscribe).to.have.been.calledWithMatch({
query: S.NullableParamSubscription,

@@ -478,4 +467,3 @@ });

it('does not call client.subscribe() a second time', function () {
var _a;
expect((_a = s.client) === null || _a === void 0 ? void 0 : _a.subscribe).to.have.been.calledOnce;
expect(s.client?.subscribe).to.have.been.calledOnce;
});

@@ -490,4 +478,3 @@ });

it('calls client.subscribe() with passed subscribe', function () {
var _a;
expect((_a = s.client) === null || _a === void 0 ? void 0 : _a.subscribe).to.have.been.calledWithMatch({
expect(s.client?.subscribe).to.have.been.calledWithMatch({
subscription: S.NullableParamSubscription,

@@ -546,4 +533,3 @@ });

it('sets data, error, and loading', function () {
var _a, _b;
expect((_b = (_a = subscription.data) === null || _a === void 0 ? void 0 : _a.nullableParam) === null || _b === void 0 ? void 0 : _b.nullable, 'data.nullableParam.nullable')
expect(subscription.data?.nullableParam?.nullable, 'data.nullableParam.nullable')
.to.equal('Hello World');

@@ -618,4 +604,3 @@ expect(subscription.loading, 'loading')

useEffect(() => {
var _a;
if ((_a = data === null || data === void 0 ? void 0 : data.messageSent) === null || _a === void 0 ? void 0 : _a.message)
if (data?.messageSent?.message)
setMessages([...messages, data.messageSent.message]);

@@ -622,0 +607,0 @@ }, [data]);

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc