Urigo / graphql-modules

Enterprise Grade Tooling For Your GraphQL Server

Home Page:https://graphql-modules.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using instanceof for external libs(graphql) is dangerous

justin-equi opened this issue · comments

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.