<commit_before>import {
  NetworkInterface,
  createNetworkInterface,
} from './networkInterface';

import {
  GraphQLResult,
} from 'graphql';

import {
  createApolloStore,
  ApolloStore,
  apolloReducer,
} from './store';

import {
  QueryManager,
  WatchedQueryHandle,
  WatchQueryOptions,
} from './QueryManager';

import {
  isUndefined,
} from 'lodash';

export {
  createNetworkInterface,
  createApolloStore,
  apolloReducer,
};

export default class ApolloClient {
  public networkInterface: NetworkInterface;
  public store: ApolloStore;
  public reduxRootKey: string;
  public queryManager: QueryManager;

  constructor({
    networkInterface,
    reduxRootKey,
  }: {
    networkInterface?: NetworkInterface,
    reduxRootKey?: string,
  } = {}) {
    this.reduxRootKey = reduxRootKey ? reduxRootKey : 'apollo';

    this.networkInterface = networkInterface ? networkInterface :
      createNetworkInterface('/graphql');
  }

  public watchQuery(options: WatchQueryOptions): WatchedQueryHandle {
    this.initStore();

    return this.queryManager.watchQuery(options);
  }

  public query(options: WatchQueryOptions): Promise<GraphQLResult | Error> {

    if (options.returnPartialData) {
      throw new Error('returnPartialData option only supported on watchQuery.');
    }

    this.initStore();

    return new Promise((resolve, reject) => {
      const handle = this.queryManager.watchQuery(options);
      handle.onResult((result) => {
        resolve(result);
        // remove the listeners
        handle.stop();
      });
    });
  }

  public mutate(options: {
    mutation: string,
    variables?: Object,
  }): Promise<GraphQLResult> {
    this.initStore();
    return this.queryManager.mutate(options);
  }

  public reducer() {
    return apolloReducer;
  }

  public middleware() {
    return (store: ApolloStore) => {
      this.setStore(store);

      // Pass through. Eventually we should use this instead of subscribe, and get rid of setStore
      return next => (action) => {
        if (action.isApolloAction) {
          const returnValue = next(action);
          this.queryManager.broadcastNewStore(store.getState());
          return returnValue;
        }

        return next(action);
      };<commit_msg>Remove comment<commit_after>import {
  NetworkInterface,
  createNetworkInterface,
} from './networkInterface';

import {
  GraphQLResult,
} from 'graphql';

import {
  createApolloStore,
  ApolloStore,
  apolloReducer,
} from './store';

import {
  QueryManager,
  WatchedQueryHandle,
  WatchQueryOptions,
} from './QueryManager';

import {
  isUndefined,
} from 'lodash';

export {
  createNetworkInterface,
  createApolloStore,
  apolloReducer,
};

export default class ApolloClient {
  public networkInterface: NetworkInterface;
  public store: ApolloStore;
  public reduxRootKey: string;
  public queryManager: QueryManager;

  constructor({
    networkInterface,
    reduxRootKey,
  }: {
    networkInterface?: NetworkInterface,
    reduxRootKey?: string,
  } = {}) {
    this.reduxRootKey = reduxRootKey ? reduxRootKey : 'apollo';

    this.networkInterface = networkInterface ? networkInterface :
      createNetworkInterface('/graphql');
  }

  public watchQuery(options: WatchQueryOptions): WatchedQueryHandle {
    this.initStore();

    return this.queryManager.watchQuery(options);
  }

  public query(options: WatchQueryOptions): Promise<GraphQLResult | Error> {

    if (options.returnPartialData) {
      throw new Error('returnPartialData option only supported on watchQuery.');
    }

    this.initStore();

    return new Promise((resolve, reject) => {
      const handle = this.queryManager.watchQuery(options);
      handle.onResult((result) => {
        resolve(result);
        // remove the listeners
        handle.stop();
      });
    });
  }

  public mutate(options: {
    mutation: string,
    variables?: Object,
  }): Promise<GraphQLResult> {
    this.initStore();
    return this.queryManager.mutate(options);
  }

  public reducer() {
    return apolloReducer;
  }

  public middleware() {
    return (store: ApolloStore) => {
      this.setStore(store);

      return (next) => {
        return (action) => {
          if (action.isApolloAction) {
            const returnValue = next(action);
            this.queryManager.broadcastNewStore(store.getState());
            return returnValue;
          }

          return next(action);
        }
      };
{'fraction_non_alphanumeric': 0.11088573360378634, 'fraction_numerical': 0.0, 'mean_word_length': 3.2186311787072244, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5672459', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1261, 'n_words': 275}