How to use the apollo-utilities.hasDirectives function in apollo-utilities

To help you get started, we’ve selected a few apollo-utilities 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 / sync / src / links / OfflineQueueLink.ts View on Github external
public request(operation: Operation, forward: NextLink) {
    // TODO split this conditional and add a handler to notify of online only cases
    if (this.isOpen) {
      return forward(operation);
    }
    if (hasDirectives([Directives.ONLINE_ONLY], operation.query)) {
      return forward(operation);
    }

    if (this.shouldSkipOperation(operation, this.operationFilter)) {
      return forward(operation);
    }

    return new Observable(observer => {
      const operationEntry = { operation, forward, observer };
      this.enqueue(operationEntry);
      return () => this.cancelOperation(operationEntry);
    });
  }
github apollographql / apollo-client / packages / apollo-client / src / core / QueryManager.ts View on Github external
query,
        variables,
        returnPartialData: true,
        optimistic: false,
      });

      // If we're in here, only fetch if we have missing fields
      needToFetch = !complete || fetchPolicy === 'cache-and-network';
      storeResult = result;
    }

    let shouldFetch =
      needToFetch && fetchPolicy !== 'cache-only' && fetchPolicy !== 'standby';

    // we need to check to see if this is an operation that uses the @live directive
    if (hasDirectives(['live'], query)) shouldFetch = true;

    const requestId = this.idCounter++;

    // set up a watcher to listen to cache updates
    const cancel = fetchPolicy !== 'no-cache'
      ? this.updateQueryWatch(queryId, query, options)
      : undefined;

    // Initialize query in store with unique requestId
    this.setQuery(queryId, () => ({
      document: query,
      lastRequestId: requestId,
      invalidated: true,
      cancel,
    }));
github strvcom / dep-manager-web / src / utils / RestLink.ts View on Github external
public request (operation: Operation, forward?: NextLink) {
    const isRestQuery = hasDirectives(['rest'], operation.query)
    if (!isRestQuery && forward) return forward(operation)
    const nonRestQuery = removeRestDirective(operation.query)
    const typeNamedQuery = addTypenameToDocument(operation.query)
    const observable =
      nonRestQuery && forward
        ? // tslint:disable-next-line:prefer-object-spread
        forward(Object.assign(operation, { query: nonRestQuery }))
        : Observable.of<FetchResult>({ data: {} })
    return observable.flatMap(
      ({ data, ...rest }) =>
        new Observable<FetchResult>(subscriber => {
          graphql(
            resolver,
            typeNamedQuery,
            data,
            this.resolverMap,
github apollographql / apollo-client / packages / apollo-client / src / core / QueryManager.ts View on Github external
query,
        variables,
        returnPartialData: true,
        optimistic: false,
      });

      // If we're in here, only fetch if we have missing fields
      needToFetch = !complete || fetchPolicy === 'cache-and-network';
      storeResult = result;
    }

    let shouldFetch =
      needToFetch && fetchPolicy !== 'cache-only' && fetchPolicy !== 'standby';

    // we need to check to see if this is an operation that uses the @live directive
    if (hasDirectives(['live'], query)) shouldFetch = true;

    const requestId = this.generateRequestId();

    // set up a watcher to listen to cache updates
    const cancel = this.updateQueryWatch(queryId, query, options);

    // Initialize query in store with unique requestId
    this.setQuery(queryId, () => ({
      document: query,
      lastRequestId: requestId,
      invalidated: true,
      cancel,
    }));

    this.invalidate(true, fetchMoreForQueryId);
github apollographql / apollo-client / packages / apollo-client / src / core / ObservableQuery.ts View on Github external
loading: isNetworkRequestInFlight(networkStatus),
      networkStatus,
    } as ApolloQueryResult<TData>;

    if (
      queryStoreValue &&
      queryStoreValue.graphQLErrors &&
      this.options.errorPolicy === 'all'
    ) {
      result.errors = queryStoreValue.graphQLErrors;
    }

    if (queryStoreValue) {
      result.loadingState = queryStoreValue.compactedLoadingState;
    } else {
      if (hasDirectives(['defer'], this.options.query)) {
        // Make sure that we have loadingState for deferred queries
        // If the queryStore has not been initialized, set loading to true and
        // wait for the next update.
        result.loading = true;
      }
    }

    if (!partial) {
      const stale = false;
      this.lastResult = { ...result, stale };
    }

    return { ...result, partial } as ApolloCurrentResult<TData>;
  }
github DeltaCamp / apollo-link-ethereum / packages / apollo-link-ethereum / src / EthereumLink.ts View on Github external
public request(
    operation: Operation,
    forward: NextLink,
  ): Observable<FetchResult> {
    const { query } = operation

    const isEthereum = hasDirectives(['contract', 'block'], query)

    if (!isEthereum) {
      return forward ? forward(operation) : null
    }

    const nonContractQuery = removeEthereumSetsFromDocument(query)

    const defn = getMainDefinition(query)

    const isSubscription = defn.operation === 'subscription'

    if (nonContractQuery) operation.query = nonContractQuery;
    const obs =
      nonContractQuery && forward
        ? forward(operation)
        : Observable.of({
github apollographql / apollo-client / packages / apollo-client / src / core / LocalState.ts View on Github external
public clientQuery(document: DocumentNode) {
    if (hasDirectives(['client'], document)) {
      if (this.resolvers) {
        return document;
      }
      invariant.warn(
        'Found @client directives in a query but no ApolloClient resolvers ' +
        'were specified. This means ApolloClient local resolver handling ' +
        'has been disabled, and @client directives will be passed through ' +
        'to your link chain.',
      );
    }
    return null;
  }
github aerogear / offix / packages / sync / src / links / OfflineQueueLink.ts View on Github external
private enqueue(entry: OperationQueueEntry) {
    if (hasDirectives([Directives.NO_SQUASH], entry.operation.query)) {
      this.opQueue.push(entry);
    } else {
      this.opQueue = squashOperations(entry, this.opQueue);
    }
    this.storage.setItem(this.key, JSON.stringify(this.opQueue));
  }