GithubHelp home page GithubHelp logo

apollo-link-queue's People

Contributors

bennyhobart avatar danielkcz avatar dependabot[bot] avatar e41q avatar helfer avatar mxstbr avatar palmithor avatar sync avatar wtrocki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apollo-link-queue's Issues

offlineLink + stateLink and split socket wont work together

	const httpLinks = middlewareLink.concat(
			afterwareLink.concat(httpLink)
		);

		const link = split(
			({ query }) => {
				const { kind, operation } = getMainDefinition(query);
				return kind === 'OperationDefinition' && operation === 'subscription';
			},
			webSocketLink,
			httpLinks

		);

		const loggerLink = new ApolloLink((operation, forward) => {
			console.log(`loggerLink: ${operation.operationName}`);
			return forward(operation).map((result) => {
				console.log(`received result from loggerLink: ${operation.operationName}`);
				return result;
			});
		});

		const cache = new InMemoryCache();

		// const stateLink = withClientState({ ...merge(networkStatusResolver), cache });
		const stateLink = withClientState({
			cache,
			resolvers,
			defaults: {
				show_type: 'BELOW_15'
			}
		});

		const ApolloClient = apollo.create({
			cache,
			link: ApolloLink.from([
				stateLink,
				new RetryLink(),
				offlineLink, //Type 'QueueLink' is not assignable to type 'ApolloLink'.
				link /*loggerLink*/, /*stateLink*/
				
			]),
```

Persist queued queries

Hi this looks very promising. However to create a full offline support what is missing is a way to persist the queued queries, so when a user is for example on holiday and doesn’t have internet, the local state of the app Including his mutations will be save when the app is restarted. Would you have any idea how to persist the queued queries, could the operation simply be serialized?

Add delete duplicate queries

If we have a request that is re-requested every 10 seconds, then there will be 6 instances of one request in a minute in the queue. If the variables have not changed, you need to delete duplicates

Named queues and discard

This link looks really interesting :-). I'm working on an app where the user can make several changes to data but the changes are only done locally in the client and not persisted to the server until the user hits a save button. I don't really like this model but it's the way the legacy app works so I'm required to do it this way.

So my scenario is not really offline but offline-ish. But it shares a lot of problems with offline. We could consider the user to be offline until he hits save, then he goes online.

I've got an idea how to solve this. I'm thinking I could make mutations for every change with optimistic updates, the way you are supposed to with apollo (by writing to the store with writeQuery). But since the mutation should not happen until the user hits save, I need to delay them. So apollo-link-queue looks like a good fit :-). However in order to make it work I think I would need two more features:

  1. Having named queues, for example if editing several documents, each document could have it's own named queue (using the document id for the queue name). The queue name could be sent in the context parameter. If there is no queue name then just let the mutation pass. The current close/open methods could set a default queue name instead. So instead of .close()/.open() you could do .defaultQueue("offline")/.defaultQueue().

  2. Having the ability to discard all queued mutations. If the user presses cancel instead of save then the mutations should not be sent to the server at all. At this point it would be nice if the optimistic updates automatically got reverted too, not sure if this could work.

Not sure this would work though. Happy for any thoughts on this!

Query batching support

It would be great to add an option to query batching the queued requests, in this way we can assure the reports are getting executed sequentially, I mean transport level query batching, get all the requests that are queued and send an array of mutations to the server, any thoughs on this?

I would be more than happy to help you figure it out something 👍

Support for apollo 3.4

I would like to use this with apollo 3.4.x, but I am getting the following error:

Metro has encountered an error: While trying to resolve module `@apollo/client/utilities` from file `/Users/MY/APP/node_modules/apollo-link-queue/build/dist/QueueLink.js`, the package `/Users/MY/APP/node_modules/apollo-link-queue/node_modules/@apollo/client/utilities/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/MY/APP/node_modules/apollo-link-queue/node_modules/@apollo/client/utilities/utilities.cjs`. Indeed, none of these files exist:

  * /Users/MY/APP/node_modules/apollo-link-queue/node_modules/@apollo/client/utilities/utilities.cjs(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
  * /Users/MY/APP/node_modules/apollo-link-queue/node_modules/@apollo/client/utilities/utilities.cjs/index(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx): /Users/MY/APP/node_modules/metro/src/node-haste/DependencyGraph.js (436:17)

  434 |
  435 |         if (error instanceof InvalidPackageError) {
> 436 |           throw new PackageResolutionError({
      |                 ^
  437 |             packageError: error,
  438 |             originModulePath: from,
  439 |             targetModuleName: to

RCTFatal
__28-[RCTCxxBridge handleError:]_block_invoke
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_main_queue_drain
_dispatch_main_queue_callback_4CF
__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
__CFRunLoopRun
CFRunLoopRunSpecific
GSEventRunModal
-[UIApplication _run]
UIApplicationMain
main
start_sim
0x0

Is there work to get this to work with the latest version of Apollo?

Delay Between Queued Requests

Is it possible to add in a delay between requests after the queue is opened? I've been able to trace all requests being sent to the server in the correct order but need to create a delay between them since the latter requests depend on the earlier ones.

It'd be great to customize that on a per requests basis.

Type 'QueueLink' is not assignable to type 'ApolloLink | RequestHandler'

Hey there,

This is the code.

import QueueLink from "apollo-link-queue";
const queueLink = new QueueLink();

const client = (hostName: string, initialState?: any) => {
  return new ApolloClient({
    link: ApolloLink.from([
      errorLink,
      queueLink,
      retryLink,
      authLink.concat(createUploadLink({ uri: `${hostName}/api/graphql` })),
    ]),
    cache: cache.restore(initialState || {}),
  });
};

i am having the following error:

Bildschirmfoto 2021-11-24 um 14 45 45

Type 'QueueLink' is not assignable to type 'ApolloLink | RequestHandler'.
  Type 'QueueLink' is not assignable to type 'ApolloLink'.
    Types of property 'split' are incompatible.
      Type '(test: (op: import("/Users/gilga/Projekte/bliks/app/node_modules/apollo-link-queue/node_modules/@apollo/client/link/core/types").Operation) => boolean, left: import("/Users/gilga/Projekte/bliks/app/node_modules/apollo-link-queue/node_modules/@apollo/client/link/core/ApolloLink").ApolloLink | import("/Users/gilga/Pro...' is not assignable to type '(test: (op: import("/Users/gilga/Projekte/bliks/app/node_modules/@apollo/client/link/core/types").Operation) => boolean, left: import("/Users/gilga/Projekte/bliks/app/node_modules/@apollo/client/link/core/ApolloLink").ApolloLink | import("/Users/gilga/Projekte/bliks/app/node_modules/@apollo/client/link/core/types")....'.
        Types of parameters 'left' and 'left' are incompatible.
          Type 'import("/Users/gilga/Projekte/bliks/app/node_modules/@apollo/client/link/core/ApolloLink").ApolloLink | import("/Users/gilga/Projekte/bliks/app/node_modules/@apollo/client/link/core/types").RequestHandler' is not assignable to type 'import("/Users/gilga/Projekte/bliks/app/node_modules/apollo-link-queue/node_modules/@apollo/client/link/core/ApolloLink").ApolloLink | import("/Users/gilga/Projekte/bliks/app/node_modules/apollo-link-queue/node_modules/@apollo/client/link/core/types").RequestHandler'.
            Type 'ApolloLink' is not assignable to type 'ApolloLink | RequestHandler'.
              Type 'import("/Users/gilga/Projekte/bliks/app/node_modules/@apollo/client/link/core/ApolloLink").ApolloLink' is not assignable to type 'import("/Users/gilga/Projekte/bliks/app/node_modules/apollo-link-queue/node_modules/@apollo/client/link/core/ApolloLink").ApolloLink'.
                Types of property 'split' are incompatible.
                  Type '(test: (op: import("/Users/gilga/Projekte/bliks/app/node_modules/@apollo/client/link/core/types").Operation) => boolean, left: import("/Users/gilga/Projekte/bliks/app/node_modules/@apollo/client/link/core/ApolloLink").ApolloLink | import("/Users/gilga/Projekte/bliks/app/node_modules/@apollo/client/link/core/types")....' is not assignable to type '(test: (op: import("/Users/gilga/Projekte/bliks/app/node_modules/apollo-link-queue/node_modules/@apollo/client/link/core/types").Operation) => boolean, left: import("/Users/gilga/Projekte/bliks/app/node_modules/apollo-link-queue/node_modules/@apollo/client/link/core/ApolloLink").ApolloLink | import("/Users/gilga/Pro...'.
                    Types of parameters 'left' and 'left' are incompatible.
                      Type 'import("/Users/gilga/Projekte/bliks/app/node_modules/apollo-link-queue/node_modules/@apollo/client/link/core/ApolloLink").ApolloLink | import("/Users/gilga/Projekte/bliks/app/node_modules/apollo-link-queue/node_modules/@apollo/client/link/core/types").RequestHandler' is not assignable to type 'import("/Users/gilga/Projekte/bliks/app/node_modules/@apollo/client/link/core/ApolloLink").ApolloLink | import("/Users/gilga/Projekte/bliks/app/node_modules/@apollo/client/link/core/types").RequestHandler'.
                        Type 'ApolloLink' is not assignable to type 'ApolloLink | RequestHandler'.
                          Type 'import("/Users/gilga/Projekte/bliks/app/node_modules/apollo-link-queue/node_modules/@apollo/client/link/core/ApolloLink").ApolloLink' is not assignable to type 'import("/Users/gilga/Projekte/bliks/app/node_modules/@apollo/client/link/core/ApolloLink").ApolloLink'.
                            Property 'onError' is protected but type 'ApolloLink' is not a class derived from 'ApolloLink'.ts(2322)

The packages:

    "@apollo/client": "^3.3.11",
    "apollo-link-queue": "^3.1.0",

When i do a pm list | grep apollo-link i ll get the following:

Bildschirmfoto 2021-11-24 um 14 47 26

Any clue?
Thank you :)

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.