Giter Club home page Giter Club logo

Comments (5)

fubhy avatar fubhy commented on May 31, 2024 1

Sorry for the delay. I am currently not actively using this myself. I reviewed & merged it and updated some dependencies along the way. Tagged v2.0.0 including this.

from graphql-transport-electron.

xEcEz avatar xEcEz commented on May 31, 2024

Seems like this is the issue:

context: JSON.parse(JSON.stringify(operation.getContext())),

from graphql-transport-electron.

fubhy avatar fubhy commented on May 31, 2024

It seems like we should allow passing a context serializer as a callback to the ApolloIpcLink options. That way, by default we could simply ignore the context (context: undefined) but allow implementations that depend on it to send custom values to the main process to control how they are serialized.

Would you mind submitting a PR for this? You could also consider upgrading the dependencies for apollo to v3. I currently don't use this library myself so would appreciate a PR for this! Thanks

from graphql-transport-electron.

megahertz avatar megahertz commented on May 31, 2024

While we're waiting for merging the PR above, here's a monkey patch

IpcLinkPatched.ts

/* eslint-disable */

import { FetchResult, Observable, Operation } from '@apollo/client';
import { print } from 'graphql';
import { IpcLink as IpcLinkOriginal } from 'graphql-transport-electron';

// @ts-ignore
export class IpcLink extends IpcLinkOriginal {
  private counter;
  private observers;
  private ipc;
  private channel;

  request(operation: Operation): any {
    return new Observable(
      (observer: ZenObservable.SubscriptionObserver<FetchResult>) => {
        const current = `${++this.counter}`;
        const request = {
          operationName: operation.operationName,
          variables: operation.variables,
          query: print(operation.query),
          context: JSON.parse(
            JSON.stringify(operation.getContext(), createSerializer())
          ),
        };

        this.observers.set(current, observer);
        this.ipc.send(this.channel, current, request);
      },
    );
  }
}

export function createIpcLink(options) {
  return new IpcLink(options);
}

function createSerializer() {
  var seen = new WeakSet();

  return function (key, value) {
    if (typeof value === 'object' && value !== null) {
      if (seen.has(value)) {
        return undefined;
      }

      seen.add(value);
    }

    return value;
  };
}

from graphql-transport-electron.

megahertz avatar megahertz commented on May 31, 2024

@fubhy could you please review the PR made by @xEcEz ?

from graphql-transport-electron.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.