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

@graphql-live/client

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-live/client - npm Package Compare versions

Comparing version 0.1.6 to 0.1.7

dist/types.d.ts

36

dist/createClient.d.ts

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

import { ManagerOptions, SocketOptions } from "socket.io-client";
import { ExecutionResult } from "graphql";
import { Operation as PatchOperation } from "fast-json-patch";
export declare type ClientOptions = {
url?: string;
context?(operation: Operation): any;
socketOptions?: Partial<ManagerOptions & SocketOptions>;
};
export declare type OperationRecord = {
observer: ResultObserver;
latestResult: ExecutionResult;
execute(): void;
};
export declare type ResultObserver = {
next(value: ExecutionResult): void;
error(error: any): void;
complete(): void;
};
export declare type OperationPayload = {
id: number;
context?: any;
operation: Operation;
};
export declare type ResultPayload = {
id: number;
patch: Array<PatchOperation>;
isFinal?: boolean;
};
export declare type Operation = {
operation: string;
operationName?: string | null;
variables?: Record<string, any>;
};
export declare function createClient({ url, context, socketOptions }?: ClientOptions): {
import { ClientOptions, Operation, ResultObserver } from ".";
export declare function createClient<TContext = any>({ url, socketOptions, context }?: ClientOptions<TContext>): {
socket: import("socket.io-client").Socket<import("socket.io-client/build/typed-events").DefaultEventsMap, import("socket.io-client/build/typed-events").DefaultEventsMap>;

@@ -36,0 +4,0 @@ destroy: () => void;

@@ -12,3 +12,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

import { applyPatch, deepClone } from "fast-json-patch";
export function createClient({ url, context, socketOptions } = {}) {
export function createClient({ url, socketOptions, context = () => undefined } = {}) {
const socket = url ? io(url, socketOptions) : io(socketOptions);

@@ -63,6 +63,9 @@ let disconnected = false;

return __awaiter(this, void 0, void 0, function* () {
// The only cases where this function is called is on first execution or on re-execution.
// Re-execution can be caused by the server going down or the connection being lost temporarily.
// In all those cases, state will be set to {} on the server, so it needs to be in sync here :
record.latestResult = {};
const payload = {
id,
context: yield (context === null || context === void 0 ? void 0 : context(operation)),
context: yield context({ socket, operation }),
operation

@@ -69,0 +72,0 @@ };

export * from "./createClient";
export * from "./urql";
export * from "./types";
export * from "./createClient";
export * from "./urql";
export * from "./types";
//# sourceMappingURL=index.js.map
import { ClientOptions } from ".";
export declare function liveExchange(options: ClientOptions): import("urql").Exchange;
export declare function liveExchange<TContext = any>(options: ClientOptions<TContext>): import("urql").Exchange;
{
"name": "@graphql-live/client",
"version": "0.1.6",
"version": "0.1.7",
"description": "The client part of the GraphQLive package",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -1,50 +0,17 @@

import { io, ManagerOptions, SocketOptions } from "socket.io-client";
import { ExecutionResult } from "graphql";
import { io } from "socket.io-client";
import { applyPatch, deepClone } from "fast-json-patch";
import {
applyPatch,
deepClone,
Operation as PatchOperation
} from "fast-json-patch";
ClientOptions,
Operation,
OperationPayload,
OperationRecord,
ResultObserver,
ResultPayload
} from ".";
export type ClientOptions = {
url?: string;
context?(operation: Operation): any;
socketOptions?: Partial<ManagerOptions & SocketOptions>;
};
export type OperationRecord = {
observer: ResultObserver;
latestResult: ExecutionResult;
execute(): void;
};
export type ResultObserver = {
next(value: ExecutionResult): void;
error(error: any): void;
complete(): void;
};
export type OperationPayload = {
id: number;
context?: any;
operation: Operation;
};
export type ResultPayload = {
id: number;
patch: Array<PatchOperation>;
isFinal?: boolean;
};
export type Operation = {
operation: string;
operationName?: string | null;
variables?: Record<string, any>;
};
export function createClient({
export function createClient<TContext = any>({
url,
context,
socketOptions
}: ClientOptions = {}) {
socketOptions,
context = () => undefined as any
}: ClientOptions<TContext> = {}) {
const socket = url ? io(url, socketOptions) : io(socketOptions);

@@ -106,6 +73,9 @@ let disconnected = false;

async execute() {
// The only cases where this function is called is on first execution or on re-execution.
// Re-execution can be caused by the server going down or the connection being lost temporarily.
// In all those cases, state will be set to {} on the server, so it needs to be in sync here :
record.latestResult = {};
const payload: OperationPayload = {
const payload: OperationPayload<TContext> = {
id,
context: await context?.(operation),
context: await context({ socket, operation }),
operation

@@ -112,0 +82,0 @@ };

export * from "./createClient";
export * from "./urql";
export * from "./types";
import { subscriptionExchange } from "urql";
import { ClientOptions, createClient } from ".";
export function liveExchange(options: ClientOptions) {
export function liveExchange<TContext = any>(options: ClientOptions<TContext>) {
const { execute } = createClient(options);

@@ -6,0 +6,0 @@ return subscriptionExchange({

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