Matt Hargett 63038500a2 Flesh out the URL polyfill a bit more (#22901)
Summary:
This expands functionality of URL minimally so Apollo Server can run in React Native contexts. Add explicit-fail getters so undefined values won't get generated from the otherwise missing implemenation.

Use of URL in apollo-server here: 458bc71ead/packages/apollo-datasource-rest/src/RESTDataSource.ts (L79)

Credit to my colleague dysonpro for debugging the issue and providing the initial working stub implementation.

Changelog:
----------

Help reviewers and the release process by writing your own changelog entry. See http://facebook.github.io/react-native/docs/contributing#changelog for an example.

[INTERNAL] [ENHANCEMENT] - Support construction, toString(), and href() of URL objects.
Pull Request resolved: https://github.com/facebook/react-native/pull/22901

Differential Revision: D13690954

Pulled By: cpojer

fbshipit-source-id: 7966bc17be8af9bf656bffea5d530b1e626acfb3
2019-01-16 05:31:55 -08:00

33 lines
1.4 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
'use strict';
const {polyfillGlobal} = require('PolyfillFunctions');
/**
* Set up XMLHttpRequest. The native XMLHttpRequest in Chrome dev tools is CORS
* aware and won't let you fetch anything from the internet.
*
* You can use this module directly, or just require InitializeCore.
*/
polyfillGlobal('XMLHttpRequest', () => require('XMLHttpRequest'));
polyfillGlobal('FormData', () => require('FormData'));
polyfillGlobal('fetch', () => require('fetch').fetch); // flowlint-line untyped-import:off
polyfillGlobal('Headers', () => require('fetch').Headers); // flowlint-line untyped-import:off
polyfillGlobal('Request', () => require('fetch').Request); // flowlint-line untyped-import:off
polyfillGlobal('Response', () => require('fetch').Response); // flowlint-line untyped-import:off
polyfillGlobal('WebSocket', () => require('WebSocket'));
polyfillGlobal('Blob', () => require('Blob'));
polyfillGlobal('File', () => require('File'));
polyfillGlobal('FileReader', () => require('FileReader'));
polyfillGlobal('URL', () => require('URL').URL); // flowlint-line untyped-import:off
polyfillGlobal('URLSearchParams', () => require('URL').URLSearchParams); // flowlint-line untyped-import:off