<commit_before>
import { Meteor } from "meteor/meteor";
// eslint-disable-next-line
import { DDP } from "meteor/ddp";
import { Accounts } from "meteor/accounts-base";

import ApolloClient, { createNetworkInterface } from "apollo-client";

const networkInterface = createNetworkInterface({ uri: Meteor.settings.public.heighliner });

const authMiddleware = {
  applyMiddleware(req, next) {
    const request = req;
    let currentUserToken;

    // on the server
    // eslint-disable-next-line
    const status = DDP._CurrentInvocation.get();
    if (status && status.connection && status.connection.id) {
      // eslint-disable-next-line
      currentUserToken = Accounts._getLoginToken(status.connection.id);
    }

    // on the client
    // eslint-disable-next-line
    if (Accounts._storedLoginToken) currentUserToken = Accounts._storedLoginToken();
    if (!currentUserToken) {
      next();
      return;
    }

    if (!request.options.headers) {
      if (fetch.Headers) {
        request.options.headers = new fetch.Headers();
      } else {
        request.options.headers = new Headers();
      }
    }

    request.options.headers.Authorization = currentUserToken;

    next();
  },
};

networkInterface.use([
  authMiddleware,
]);<commit_msg>added platform and version headers to graphql<commit_after>
import { Meteor } from "meteor/meteor";
// eslint-disable-next-line
import { DDP } from "meteor/ddp";
import { Accounts } from "meteor/accounts-base";

import ApolloClient, { createNetworkInterface } from "apollo-client";

const networkInterface = createNetworkInterface({ uri: Meteor.settings.public.heighliner });

const authMiddleware = {
  applyMiddleware(req, next) {
    const request = req;
    let currentUserToken;

    // on the server
    // eslint-disable-next-line
    const status = DDP._CurrentInvocation.get();
    if (status && status.connection && status.connection.id) {
      // eslint-disable-next-line
      currentUserToken = Accounts._getLoginToken(status.connection.id);
    }

    // on the client
    // eslint-disable-next-line
    if (Accounts._storedLoginToken) currentUserToken = Accounts._storedLoginToken();
    if (!currentUserToken) {
      next();
      return;
    }

    if (!request.options.headers) {
      if (fetch.Headers) {
        request.options.headers = new fetch.Headers();
      } else {
        request.options.headers = new Headers();
      }
    }

    request.options.headers.Authorization = currentUserToken;
    request.options.headers.Platform = Meteor.isCordova ? "Native" : "Web";
    request.options.headers.Version = Meteor.settings.public.release;

    next();
  },
};

networkInterface.use([
  authMiddleware,
]);
{'fraction_non_alphanumeric': 0.12546399406087602, 'fraction_numerical': 0.0, 'mean_word_length': 3.1653786707882534, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7364944', 'n_tokens_mistral': 820, 'n_tokens_neox': 797, 'n_words': 162}