graphql-hive / graphql-hive/graphql-modules

Using instanceof for external libs(graphql) is dangerous

Open
#2,477 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.3k
Forks
113
Avg merge
3h 36m
Merged PRs (30d)
1

Description

**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(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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.