)
         .then((oper) => request(oper))
         .then(() => {
            handle = forward(operation).subscribe({
              next: observer.next.bind(observer),
              error: observer.error.bind(observer),
              complete: observer.complete.bind(observer),
            });
          })
         .catch(observer.error.bind(observer));

        return () => {
          if (handle) handle.unsubscribe();
        };
      })
  );
};

/**
 * Helper functions that handles error cases
 */
const handleErrors = () => {
  return onError(({ graphQLErrors, networkError }) => {
    if (graphQLErrors) {
      graphQLErrors.map(({ message, locations, path }) =>
        console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`)
      );
    }

    if (networkError) {
      console.log(`[Network error]: ${networkError}`);
    }
  });
};

/**
 * Creates a Apollo Client
 *
 * @param {string} apiUrl, GraphQL api url
 * @param {string} websocketApiUrl, GraphQL WebSocket api url
 */
export const createApolloClient = (apiUrl, websocketApiUrl) => {
  const cache = new InMemoryCache();

  const errorLink = handleErrors();
  const authLink = createAuthLink();
  const uploadLink = createUploadLink({ uri: apiUrl }); // Upload link also creates an HTTP link

  // Create WebSocket link
  const authToken = localStorage.getItem('token');
  const wsLink = new WebSocketLink({
    uri: websocketApiUrl,
    options: {
      timeout: 60000,
      reconnect: true,
      connectionParams: {
        authorization: authToken,
      },
    },
  });

  // Temporary fix for early websocket closure resulting in websocket connections not being instantiated
  // https://github.com/apollographql/subscriptions-transport-ws/issues/377
  wsLink.subscriptionClient.maxConnectTimeGenerator.duration = () =>
    wsLink.subscriptionClient.maxConnectTimeGenerator.max;

  // Split links, so we can send data to each link
  // depending on what kind of operation is being sent
  const terminatingLink = split(
    ({ query }) => {
      const { kind, operation } = getMainDefinition(query);
      return kind === 'OperationDefinition' && operation ==='subscription';
    },
    wsLink,
    uploadLink
  );

  return new ApolloClient({
    link: ApolloLink.from([errorLink, authLink, terminatingLink]),
    cache,
  });
};
<issue_start><issue_comment>Title: Feature/reduce rest calls
username_0: Introduced new way of resolving referenced objects.
Before every reference was resolved on its own, this behavior is now changed to resolve all references given in the same field of multiple objects within one query instead of one query per reference.

The code quality can likely be improved, but the functionality is there.
<issue_comment>username_1: All tests passed[273 U.S. 236, 237] Mr. Samuel E. Darby, of New York City, for appellant.
The Attorney General and Mr. Assistant Attorney General Galloway, for the United States.
Mr. Chief Justice TAFT delivered the opinion of the Court.
This is an appeal from a judgment of the Court of Claims dismissing the petition of the appellant on the 4th of May, 1925, 60 Ct. Cl. 1034. This was before the effective date of the Act of February 13, 1925, c. 229 ( 43 Stat. 936), by which direct appeals under sections 242 and 243 of the Judicial Code (Comp. St. 1219, 1220) from the Court of Claims were repealed, and the review by certiorari was substituted.
The De Forest Radio Telephone & Telegraph Company filed its petition in the Court of Claims against the United States, seeking to recover for an alleged unlawful use by the government of certain patented vacuum tubes or audions used in radio communication. The suit was brought under the Act of June 25, 1910, c. 423 (36 Stat. 851), as amended by the Act of July 1, 1918, c. 114 (40 Stat. 704, 705), that, whenever an invention described that, whenever an invetion described in and covered by a patent of the United States should thereafter be used by the government without license of the owner or lawful right to use it, the owner could recover reasonable compensation for the use in the Court of Claims, provided that the United States could avail itself of all defenses, general or special, which might be pleaded by any other defendant charged with infringement. The amending act of 1918 enlarged the scope of the act by providing that the recovery by the [273 U.S. 236, 238] owner should include compensation for patented inventions used or made by or for the United States.
The petition showed that the two patents involved in the suit were granted to De Forest, and by him were duly assigned to the appellant, the company bearing him name; that that company executed and delivered to the Western Electric Company a written instrument conveying certain rights in the patents, which were subsequently conveyed to the American Telephone & Telegraph Company. This contract was set out in the petition. In consideration of $1 and other good and valuable considerations it granted a license to make, use, install, operate, and lease, and to sell or otherwise dispose of to others for sale, installation, and operation, apparatus and systems embodying or made or operating in accordance with the invention. It purported to give this license for the full terms of the patents and for all transferable rights of the De Forest Company in the inventions, except such as were expressly reserved by that company. The reservations included nonassignable rights for the purpose of making the articles in question for, and selling them to, the United States government for its use. The instrument further provided that the Western Company and the De Forest Company might respectively institute and conduct suits against others for any of the patents within the fields in which each respectively possessed rights, but that all such suits should be conducted at the expense of the party bringing them, that party to retain any judgment recovered in any such suits.
Paragraph 12 of the instrument provided that the Western Company might transfer to others, in whole or in part, the rights granted by the instrument, and might assign rights thereunder or grant licenses to various persons, firms, or corporations for the several uses to which the inventions were applicable. The petition further [273 U.S. 236, 239] alleges that the United states, being engaged in war, informed the American Telephone & Telegraph Company that it desired to have large numbers of the audions made promptly for it by the General Electric Company and others; that the American Telephone & Telegraph Company replied by writing to the Chief Signal Officer of the Army that it would not do anything to interfere with the immediate manufacture of the audions, provided it were understood and agreed that the Telephone & Telegraph Company 'waived none of its claims under any patents or patent rights owned by it on account of said manufacture, and that all claims under patent rights and all patent questions be reserved and later investigated, adjusted, and settled by the United States.' The plan was accepted by the United States, and the orders for said audions were thereafter given by the United States to said General Electric Company and said Moorhead Laboratories. Inc., who made them and delivered them to the government, which used them.
The petition further alleged that, for the purpose of assisting the United States to obtain said audions promptly pursuant to the orders given, the American Telephone & Telegraph Company furnished information, drawings, and blueprints to the General Electric Company, and permitted representatives and experts of the United States and of said General Electric Company to witness and study the manufacture of said audions by the Telephone & Telegraph Company, all to the end that the audions might be the more promptly made and delivered to the United States for use in the war in which it was then engaged.
After the filing of the petition in the suit, it was amended by an averment that, after the audions were made and used by the United States, negotiations were carried on between it and the American Telephone Company, and that the latter company executed a release to [273 U.S. 236, 240] the United States and all manufacturers acting under its orders of all claims for compensation for the making and use of the audions, and that the release included 'all claims which had arisen or might thereafter arise for royalties, damages, profits, or compensation for infringement of any or all letters patent owned or controlled by the Telephone & Telegraph Company, whether expressly recited therein or not, for the manufacture or use prior thereto, and for use by the United States occurring thereafter.'
The petition was demurred to, the demurrer was sustained, and the petition dismissed. It is conceded by the parties that on the face of the petition, with the contracts which were made exhibits, the De Forest Company and the American Telephone & Telegraph Company had each the right to license to the United States the making and use of these audions, and that, if either did so license them, it would be a complete defense to a claim for damages for the tort of infringement by the other.
The sole question, therefore, which the Court