Skip to content

Using instanceof for external libs(graphql) is dangerous  #2477

Open
@justin-equi

Description

@justin-equi

Is your feature request related to a problem? Please describe.

The graphql module is extremely popular and used by many and many third party dependencies. While its possible to pin a version, it still exposes 2 versions of itself, a commonjs version and a module version. This can be an issue for the instanceof compares in the graphql-module code such as

function isScalarResolver(obj: any): obj is GraphQLScalarType {
  return obj instanceof GraphQLScalarType;
}
...
export function isNotSchema<T>(obj: any): obj is T {
  return obj instanceof GraphQLSchema === false;
}

Are the 2 most dangerous usages. When an instanceof these classes resolve to a different file, wether by module type or module version these will fail to work correctly.

Describe the solution you'd like
The graphql library supplies its own isSchema and isScalar utilty functions. Use these instead, under the covers its really doing string manipulation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions