Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
justin-equi opened this issue Dec 2, 2023 · 0 comments
Open

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

justin-equi opened this issue Dec 2, 2023 · 0 comments

Comments

@justin-equi
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant