-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit 0ffc1e1
authored
Remove typescript enums in favor of plain JS/TS solution (#4254)
This gets rid of enums for two reasons
- TypeScript does not really compile them size efficiently, see
[here](https://www.runpkg.com/?graphql@16.8.1/language/kinds.mjs)
- Raw size kinds.js before: 2800bytes
- Raw size kinds.js after: 2200 bytes
- It's not kind to plains strings as seen in
#3356
Resolves #3356
This does not intend to fix the tree-shaking issue as seen in
#4253, for that we'd need to
fully normalize these exports and sacrifice the DX of the namespaces. I
do think that it becomes easier as plain strings will be "easier"
compared to before so if you're not doing comparisons you can opt out of
the `Kind` namespace.
<details>
<summary>See new output</summary>
```js
/**
* The set of allowed kind values for AST nodes.
*/
exports.Kind = {
/** Name */
NAME: 'Name',
/** Document */
DOCUMENT: 'Document',
OPERATION_DEFINITION: 'OperationDefinition',
VARIABLE_DEFINITION: 'VariableDefinition',
SELECTION_SET: 'SelectionSet',
FIELD: 'Field',
ARGUMENT: 'Argument',
FRAGMENT_ARGUMENT: 'FragmentArgument',
/** Fragments */
FRAGMENT_SPREAD: 'FragmentSpread',
INLINE_FRAGMENT: 'InlineFragment',
FRAGMENT_DEFINITION: 'FragmentDefinition',
/** Values */
VARIABLE: 'Variable',
INT: 'IntValue',
FLOAT: 'FloatValue',
STRING: 'StringValue',
BOOLEAN: 'BooleanValue',
NULL: 'NullValue',
ENUM: 'EnumValue',
LIST: 'ListValue',
OBJECT: 'ObjectValue',
OBJECT_FIELD: 'ObjectField',
/** Directives */
DIRECTIVE: 'Directive',
/** Types */
NAMED_TYPE: 'NamedType',
LIST_TYPE: 'ListType',
NON_NULL_TYPE: 'NonNullType',
/** Type System Definitions */
SCHEMA_DEFINITION: 'SchemaDefinition',
OPERATION_TYPE_DEFINITION: 'OperationTypeDefinition',
/** Type Definitions */
SCALAR_TYPE_DEFINITION: 'ScalarTypeDefinition',
OBJECT_TYPE_DEFINITION: 'ObjectTypeDefinition',
FIELD_DEFINITION: 'FieldDefinition',
INPUT_VALUE_DEFINITION: 'InputValueDefinition',
INTERFACE_TYPE_DEFINITION: 'InterfaceTypeDefinition',
UNION_TYPE_DEFINITION: 'UnionTypeDefinition',
ENUM_TYPE_DEFINITION: 'EnumTypeDefinition',
ENUM_VALUE_DEFINITION: 'EnumValueDefinition',
INPUT_OBJECT_TYPE_DEFINITION: 'InputObjectTypeDefinition',
/** Directive Definitions */
DIRECTIVE_DEFINITION: 'DirectiveDefinition',
/** Type System Extensions */
SCHEMA_EXTENSION: 'SchemaExtension',
/** Type Extensions */
SCALAR_TYPE_EXTENSION: 'ScalarTypeExtension',
OBJECT_TYPE_EXTENSION: 'ObjectTypeExtension',
INTERFACE_TYPE_EXTENSION: 'InterfaceTypeExtension',
UNION_TYPE_EXTENSION: 'UnionTypeExtension',
ENUM_TYPE_EXTENSION: 'EnumTypeExtension',
INPUT_OBJECT_TYPE_EXTENSION: 'InputObjectTypeExtension',
};
```
</details>
Currently seeing whether we should disable the redeclare lint-rule and
whether there is a better way to type our `nodeKinds`1 parent d59c725 commit 0ffc1e1Copy full SHA for 0ffc1e1
File tree
Expand file treeCollapse file tree
7 files changed
+227
-216
lines changedFilter options
- src
- language
- type
- utilities
Expand file treeCollapse file tree
7 files changed
+227
-216
lines changed
0 commit comments