@graphprotocol/client-polling-live 1.1.0-alpha-20230110145237-1560b86 → 1.1.0-alpha-20230227170651-0ce0309
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/index.js +12 -4
 - package/esm/index.js +12 -4
 - package/package.json +1 -1
 - package/typings/index.d.cts +2 -1
 - package/typings/index.d.ts +2 -1
 
    
        package/cjs/index.js
    CHANGED
    
    | 
         @@ -4,20 +4,20 @@ const core_1 = require("@envelop/core"); 
     | 
|
| 
       4 
4 
     | 
    
         
             
            const graphql_1 = require("graphql");
         
     | 
| 
       5 
5 
     | 
    
         
             
            const repeater_1 = require("@repeaterjs/repeater");
         
     | 
| 
       6 
6 
     | 
    
         
             
            const schema_1 = require("@graphql-tools/schema");
         
     | 
| 
       7 
     | 
    
         
            -
            function usePollingLive({ config: { defaultInterval = 1000 } = {} } = {}) {
         
     | 
| 
      
 7 
     | 
    
         
            +
            function usePollingLive({ config: { defaultInterval = 1000, defaultPauseOnBackground = true } = {}, } = {}) {
         
     | 
| 
       8 
8 
     | 
    
         
             
                return {
         
     | 
| 
       9 
9 
     | 
    
         
             
                    onSchemaChange({ schema, replaceSchema }) {
         
     | 
| 
       10 
10 
     | 
    
         
             
                        if (!schema.getDirective('live')) {
         
     | 
| 
       11 
11 
     | 
    
         
             
                            replaceSchema((0, schema_1.mergeSchemas)({
         
     | 
| 
       12 
12 
     | 
    
         
             
                                schemas: [schema],
         
     | 
| 
       13 
13 
     | 
    
         
             
                                typeDefs: /* GraphQL */ `
         
     | 
| 
       14 
     | 
    
         
            -
                          directive @live(interval: Int) on QUERY
         
     | 
| 
      
 14 
     | 
    
         
            +
                          directive @live(interval: Int = ${defaultInterval}, pauseOnBackground: Boolean = ${defaultPauseOnBackground}) on QUERY
         
     | 
| 
       15 
15 
     | 
    
         
             
                        `,
         
     | 
| 
       16 
16 
     | 
    
         
             
                            }));
         
     | 
| 
       17 
17 
     | 
    
         
             
                        }
         
     | 
| 
       18 
18 
     | 
    
         
             
                    },
         
     | 
| 
       19 
19 
     | 
    
         
             
                    onExecute({ args, executeFn, setExecuteFn }) {
         
     | 
| 
       20 
     | 
    
         
            -
                        var _a, _b;
         
     | 
| 
      
 20 
     | 
    
         
            +
                        var _a, _b, _c, _d;
         
     | 
| 
       21 
21 
     | 
    
         
             
                        let liveDirectiveNode;
         
     | 
| 
       22 
22 
     | 
    
         
             
                        args.document = (0, graphql_1.visit)(args.document, {
         
     | 
| 
       23 
23 
     | 
    
         
             
                            OperationDefinition(node) {
         
     | 
| 
         @@ -45,12 +45,20 @@ function usePollingLive({ config: { defaultInterval = 1000 } = {} } = {}) { 
     | 
|
| 
       45 
45 
     | 
    
         
             
                        });
         
     | 
| 
       46 
46 
     | 
    
         
             
                        if (liveDirectiveNode) {
         
     | 
| 
       47 
47 
     | 
    
         
             
                            const intervalArgNode = (_a = liveDirectiveNode.arguments) === null || _a === void 0 ? void 0 : _a.find((argNode) => argNode.name.value === 'interval');
         
     | 
| 
      
 48 
     | 
    
         
            +
                            let pauseOnBackground = defaultPauseOnBackground;
         
     | 
| 
      
 49 
     | 
    
         
            +
                            const pauseOnBackgroundArgNode = (_b = liveDirectiveNode.arguments) === null || _b === void 0 ? void 0 : _b.find((argNode) => argNode.name.value === 'pauseOnBackground');
         
     | 
| 
      
 50 
     | 
    
         
            +
                            if (((_c = pauseOnBackgroundArgNode === null || pauseOnBackgroundArgNode === void 0 ? void 0 : pauseOnBackgroundArgNode.value) === null || _c === void 0 ? void 0 : _c.kind) === graphql_1.Kind.BOOLEAN) {
         
     | 
| 
      
 51 
     | 
    
         
            +
                                pauseOnBackground = pauseOnBackgroundArgNode.value.value;
         
     | 
| 
      
 52 
     | 
    
         
            +
                            }
         
     | 
| 
       48 
53 
     | 
    
         
             
                            let intervalMs = defaultInterval;
         
     | 
| 
       49 
     | 
    
         
            -
                            if ((( 
     | 
| 
      
 54 
     | 
    
         
            +
                            if (((_d = intervalArgNode === null || intervalArgNode === void 0 ? void 0 : intervalArgNode.value) === null || _d === void 0 ? void 0 : _d.kind) === graphql_1.Kind.INT) {
         
     | 
| 
       50 
55 
     | 
    
         
             
                                intervalMs = parseInt(intervalArgNode.value.value);
         
     | 
| 
       51 
56 
     | 
    
         
             
                            }
         
     | 
| 
       52 
57 
     | 
    
         
             
                            function checkHidden() {
         
     | 
| 
       53 
58 
     | 
    
         
             
                                var _a, _b;
         
     | 
| 
      
 59 
     | 
    
         
            +
                                if (!pauseOnBackground) {
         
     | 
| 
      
 60 
     | 
    
         
            +
                                    return false;
         
     | 
| 
      
 61 
     | 
    
         
            +
                                }
         
     | 
| 
       54 
62 
     | 
    
         
             
                                return (_b = (_a = globalThis.document) === null || _a === void 0 ? void 0 : _a.hidden) !== null && _b !== void 0 ? _b : false;
         
     | 
| 
       55 
63 
     | 
    
         
             
                            }
         
     | 
| 
       56 
64 
     | 
    
         
             
                            setExecuteFn((args) => new repeater_1.Repeater((push, stop) => {
         
     | 
    
        package/esm/index.js
    CHANGED
    
    | 
         @@ -2,20 +2,20 @@ import { isAsyncIterable } from '@envelop/core'; 
     | 
|
| 
       2 
2 
     | 
    
         
             
            import { GraphQLError, Kind, visit } from 'graphql';
         
     | 
| 
       3 
3 
     | 
    
         
             
            import { Repeater } from '@repeaterjs/repeater';
         
     | 
| 
       4 
4 
     | 
    
         
             
            import { mergeSchemas } from '@graphql-tools/schema';
         
     | 
| 
       5 
     | 
    
         
            -
            export default function usePollingLive({ config: { defaultInterval = 1000 } = {} } = {}) {
         
     | 
| 
      
 5 
     | 
    
         
            +
            export default function usePollingLive({ config: { defaultInterval = 1000, defaultPauseOnBackground = true } = {}, } = {}) {
         
     | 
| 
       6 
6 
     | 
    
         
             
                return {
         
     | 
| 
       7 
7 
     | 
    
         
             
                    onSchemaChange({ schema, replaceSchema }) {
         
     | 
| 
       8 
8 
     | 
    
         
             
                        if (!schema.getDirective('live')) {
         
     | 
| 
       9 
9 
     | 
    
         
             
                            replaceSchema(mergeSchemas({
         
     | 
| 
       10 
10 
     | 
    
         
             
                                schemas: [schema],
         
     | 
| 
       11 
11 
     | 
    
         
             
                                typeDefs: /* GraphQL */ `
         
     | 
| 
       12 
     | 
    
         
            -
                          directive @live(interval: Int) on QUERY
         
     | 
| 
      
 12 
     | 
    
         
            +
                          directive @live(interval: Int = ${defaultInterval}, pauseOnBackground: Boolean = ${defaultPauseOnBackground}) on QUERY
         
     | 
| 
       13 
13 
     | 
    
         
             
                        `,
         
     | 
| 
       14 
14 
     | 
    
         
             
                            }));
         
     | 
| 
       15 
15 
     | 
    
         
             
                        }
         
     | 
| 
       16 
16 
     | 
    
         
             
                    },
         
     | 
| 
       17 
17 
     | 
    
         
             
                    onExecute({ args, executeFn, setExecuteFn }) {
         
     | 
| 
       18 
     | 
    
         
            -
                        var _a, _b;
         
     | 
| 
      
 18 
     | 
    
         
            +
                        var _a, _b, _c, _d;
         
     | 
| 
       19 
19 
     | 
    
         
             
                        let liveDirectiveNode;
         
     | 
| 
       20 
20 
     | 
    
         
             
                        args.document = visit(args.document, {
         
     | 
| 
       21 
21 
     | 
    
         
             
                            OperationDefinition(node) {
         
     | 
| 
         @@ -43,12 +43,20 @@ export default function usePollingLive({ config: { defaultInterval = 1000 } = {} 
     | 
|
| 
       43 
43 
     | 
    
         
             
                        });
         
     | 
| 
       44 
44 
     | 
    
         
             
                        if (liveDirectiveNode) {
         
     | 
| 
       45 
45 
     | 
    
         
             
                            const intervalArgNode = (_a = liveDirectiveNode.arguments) === null || _a === void 0 ? void 0 : _a.find((argNode) => argNode.name.value === 'interval');
         
     | 
| 
      
 46 
     | 
    
         
            +
                            let pauseOnBackground = defaultPauseOnBackground;
         
     | 
| 
      
 47 
     | 
    
         
            +
                            const pauseOnBackgroundArgNode = (_b = liveDirectiveNode.arguments) === null || _b === void 0 ? void 0 : _b.find((argNode) => argNode.name.value === 'pauseOnBackground');
         
     | 
| 
      
 48 
     | 
    
         
            +
                            if (((_c = pauseOnBackgroundArgNode === null || pauseOnBackgroundArgNode === void 0 ? void 0 : pauseOnBackgroundArgNode.value) === null || _c === void 0 ? void 0 : _c.kind) === Kind.BOOLEAN) {
         
     | 
| 
      
 49 
     | 
    
         
            +
                                pauseOnBackground = pauseOnBackgroundArgNode.value.value;
         
     | 
| 
      
 50 
     | 
    
         
            +
                            }
         
     | 
| 
       46 
51 
     | 
    
         
             
                            let intervalMs = defaultInterval;
         
     | 
| 
       47 
     | 
    
         
            -
                            if ((( 
     | 
| 
      
 52 
     | 
    
         
            +
                            if (((_d = intervalArgNode === null || intervalArgNode === void 0 ? void 0 : intervalArgNode.value) === null || _d === void 0 ? void 0 : _d.kind) === Kind.INT) {
         
     | 
| 
       48 
53 
     | 
    
         
             
                                intervalMs = parseInt(intervalArgNode.value.value);
         
     | 
| 
       49 
54 
     | 
    
         
             
                            }
         
     | 
| 
       50 
55 
     | 
    
         
             
                            function checkHidden() {
         
     | 
| 
       51 
56 
     | 
    
         
             
                                var _a, _b;
         
     | 
| 
      
 57 
     | 
    
         
            +
                                if (!pauseOnBackground) {
         
     | 
| 
      
 58 
     | 
    
         
            +
                                    return false;
         
     | 
| 
      
 59 
     | 
    
         
            +
                                }
         
     | 
| 
       52 
60 
     | 
    
         
             
                                return (_b = (_a = globalThis.document) === null || _a === void 0 ? void 0 : _a.hidden) !== null && _b !== void 0 ? _b : false;
         
     | 
| 
       53 
61 
     | 
    
         
             
                            }
         
     | 
| 
       54 
62 
     | 
    
         
             
                            setExecuteFn((args) => new Repeater((push, stop) => {
         
     | 
    
        package/package.json
    CHANGED
    
    
    
        package/typings/index.d.cts
    CHANGED
    
    | 
         @@ -1,6 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            import { Plugin } from '@envelop/core';
         
     | 
| 
       2 
     | 
    
         
            -
            export default function usePollingLive({ config: { defaultInterval } }?: {
         
     | 
| 
      
 2 
     | 
    
         
            +
            export default function usePollingLive({ config: { defaultInterval, defaultPauseOnBackground }, }?: {
         
     | 
| 
       3 
3 
     | 
    
         
             
                config?: {
         
     | 
| 
       4 
4 
     | 
    
         
             
                    defaultInterval?: number | undefined;
         
     | 
| 
      
 5 
     | 
    
         
            +
                    defaultPauseOnBackground?: boolean | undefined;
         
     | 
| 
       5 
6 
     | 
    
         
             
                } | undefined;
         
     | 
| 
       6 
7 
     | 
    
         
             
            }): Plugin<{}>;
         
     | 
    
        package/typings/index.d.ts
    CHANGED
    
    | 
         @@ -1,6 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            import { Plugin } from '@envelop/core';
         
     | 
| 
       2 
     | 
    
         
            -
            export default function usePollingLive({ config: { defaultInterval } }?: {
         
     | 
| 
      
 2 
     | 
    
         
            +
            export default function usePollingLive({ config: { defaultInterval, defaultPauseOnBackground }, }?: {
         
     | 
| 
       3 
3 
     | 
    
         
             
                config?: {
         
     | 
| 
       4 
4 
     | 
    
         
             
                    defaultInterval?: number | undefined;
         
     | 
| 
      
 5 
     | 
    
         
            +
                    defaultPauseOnBackground?: boolean | undefined;
         
     | 
| 
       5 
6 
     | 
    
         
             
                } | undefined;
         
     | 
| 
       6 
7 
     | 
    
         
             
            }): Plugin<{}>;
         
     |