Skip to content

Polyfill for URL is incomplete and causes crash with apollo-server #22594

Closed
@matthargett

Description

@matthargett

Environment

  React Native Environment Info:
    System:
      OS: Linux 4.4 Ubuntu 18.04.1 LTS (Bionic Beaver)
      CPU: x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
      Memory: 6.07 GB / 15.93 GB
      Shell: 4.4.19 - /bin/bash
    Binaries:
      Node: 10.12.0 - ~/.nvs/node/10.12.0/x64/bin/node
      Yarn: 1.10.1 - ~/.nvs/node/10.12.0/x64/bin/yarn
      npm: 6.4.1 - ~/.nvs/node/10.12.0/x64/bin/npm
    npmPackages:
      react: 16.5.0 => 16.5.0
      react-native: 0.57.1 => 0.57.1
    npmGlobalPackages:
      react-native-cli: 2.0.1

Description

To add non-URL (local) Blob support, a simple polyfill for one static method on the URL object was added here:


(note that the ctor throws)

This triggers an exception Apollo Server tries to do a new URL() here:
https://github.com/apollographql/apollo-server/blob/458bc71eadde52483ccaef209df3eb1f1bcb4424/packages/apollo-datasource-rest/src/RESTDataSource.ts#L79

It then uses the SearchParams collection on the URL to add parameters:
https://github.com/apollographql/apollo-server/blob/458bc71eadde52483ccaef209df3eb1f1bcb4424/packages/apollo-datasource-rest/src/RESTDataSource.ts#L218

And then constructs a string, implicitly calling the url.toString() method:
https://github.com/apollographql/apollo-server/blob/458bc71eadde52483ccaef209df3eb1f1bcb4424/packages/apollo-datasource-rest/src/RESTDataSource.ts#L233

Reproducible Demo


import { RESTDataSource } from 'apollo-datasource-rest';

export default class SearchDataSource extends RESTDataSource {
  constructor() {
    super();
    this.baseURL = `https://foo.com/`;
  }

  async search(searchString, options) {
    return this.get('universalSearch', {
      searchTerm: this.searchString,
    });
  }
}

const sds = new SearchDataSource();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions