How to use offix-conflicts-client - 3 common examples

To help you get started, we’ve selected a few offix-conflicts-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aerogear / offix / packages / offix-client / src / apollo / conflicts / baseHelpers.ts View on Github external
export function getBaseStateFromCache(
  cache: ApolloCacheWithData,
  objectState: ObjectState,
  mutationOptions: MutationOptions
): ConflictResolutionData {
  const context = mutationOptions.context;

  if (!context.conflictBase) {
    // do nothing
    const conflictBase = getObjectFromCache(cache, context.returnType, mutationOptions);
    if (conflictBase && Object.keys(conflictBase).length !== 0) {
      if (objectState.hasConflict(mutationOptions.variables, conflictBase)) {
        // 🙊 Input data is conflicted with the latest server projection
        throw new LocalConflictError(conflictBase, mutationOptions.variables);
      }
      return conflictBase;
    }
  }
}
github aerogear / offix / packages / offix-client / src / apollo / conflicts / ConflictLink.ts View on Github external
private conflictHandler(errorResponse: ErrorResponse): Observable {
    const { response, operation, forward, graphQLErrors } = errorResponse;
    const data = this.getConflictData(graphQLErrors);
    const individualStrategy = this.strategy || UseClient;
    if (data && operation.getContext().returnType) {
      const base = operation.getContext().conflictBase;
      const conflictHandler = new ConflictHandler({
        base,
        client: data.clientState,
        server: data.serverState,
        strategy: individualStrategy,
        listener: this.listener,
        objectState: this.config.conflictProvider as ObjectState,
        operationName: operation.operationName
      });
      const resolvedConflict = conflictHandler.executeStrategy();
      if (resolvedConflict) {
        operation.variables = resolvedConflict;
      }
    }
    return forward(operation);

  }
github aerogear / offix / packages / offix-client / src / config / ApolloOfflineClientConfig.ts View on Github external
constructor(options = {} as ApolloOfflineClientOptions) {
    Object.assign(this, options);

    this.cacheStorage = options.cacheStorage || createDefaultCacheStorage();
    this.offlineStorage = options.offlineStorage || createDefaultOfflineStorage();
    this.conflictStrategy = options.conflictStrategy || UseClient;
    this.conflictProvider = options.conflictProvider || new VersionedState();
    this.link = createDefaultLink(this);
  }
}

offix-conflicts-client

adds client side conflict detection and resolution

Apache-2.0
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis

Similar packages