Skip to content

Commit

Permalink
Add support for Symbol.toStringTag
Browse files Browse the repository at this point in the history
**Changes**
 * Add static and instance property getters for Symbol.toStringTag for
 each exported class.

**Purpose**
Being able to compare class and class instances via internal class type
as per the definition and usage of Symbol.toStringTag allows other
libraries to validate types during runtime in this manner. It also
prevents them from having to patch the live values in their own
codebases.

**Contrived Example**
With no modules and vanilla JavaScript we should be able to do something
like the following.

```javascript
let type = new GraphQLObjectType({name: 'Sample'});

if (({}).toString.call(type) === '[object GraphQLObjectType]') {
  // we have the right type of class
}
```

However, with libraries such as `type-detect` or `ne-types` the code can
look far cleaner.

```javascript
// type-detect
let type = require('type-detect')
let obj = new GraphQLObjectType({name:'Example'})
assert(type(obj) === GraphQLObjectType.name)

// ne-types
let { typeOf } = require('ne-types')
let obj = new GraphQLObjectType({name:'Example'})
assert(typeOf(obj) === GraphQLObjectType.name)
```

There are a lot of libraries out there, despite doing nearly the same
thing in all cases, that support the usage of `Symbol.toStringTag` and
by adding support for that in the base GraphQL classes, all of these
libraries can be used with GraphQL.
  • Loading branch information
nyteshade authored and Brielle Harrison committed May 29, 2018
1 parent 0a30b62 commit 71a6669
Show file tree
Hide file tree
Showing 7 changed files with 8,547 additions and 0 deletions.
Loading

0 comments on commit 71a6669

Please sign in to comment.