Skip to content

Commit

Permalink
Allow for tree-shaking the Kind enum
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Oct 29, 2024
1 parent 9153497 commit 060bd56
Show file tree
Hide file tree
Showing 3 changed files with 244 additions and 147 deletions.
165 changes: 86 additions & 79 deletions src/language/__tests__/predicates-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,54 +26,55 @@ function filterNodes(predicate: (node: ASTNode) => boolean): Array<string> {

describe('AST node predicates', () => {
it('isDefinitionNode', () => {
expect(filterNodes(isDefinitionNode)).to.deep.equal([
'OperationDefinition',
'FragmentDefinition',
'SchemaDefinition',
'ScalarTypeDefinition',
'ObjectTypeDefinition',
'InterfaceTypeDefinition',
'UnionTypeDefinition',
'EnumTypeDefinition',
'InputObjectTypeDefinition',
'DirectiveDefinition',
'SchemaExtension',
'ScalarTypeExtension',
'ObjectTypeExtension',
'InterfaceTypeExtension',
'UnionTypeExtension',
'EnumTypeExtension',
'InputObjectTypeExtension',
]);
expect(filterNodes(isDefinitionNode)).to.deep.equal(
[
'OperationDefinition',
'FragmentDefinition',
'SchemaDefinition',
'ScalarTypeDefinition',
'ObjectTypeDefinition',
'InterfaceTypeDefinition',
'UnionTypeDefinition',
'EnumTypeDefinition',
'InputObjectTypeDefinition',
'DirectiveDefinition',
'SchemaExtension',
'ScalarTypeExtension',
'ObjectTypeExtension',
'InterfaceTypeExtension',
'UnionTypeExtension',
'EnumTypeExtension',
'InputObjectTypeExtension',
].sort(),
);
});

it('isExecutableDefinitionNode', () => {
expect(filterNodes(isExecutableDefinitionNode)).to.deep.equal([
'OperationDefinition',
'FragmentDefinition',
]);
expect(filterNodes(isExecutableDefinitionNode)).to.deep.equal(
['OperationDefinition', 'FragmentDefinition'].sort(),
);
});

it('isSelectionNode', () => {
expect(filterNodes(isSelectionNode)).to.deep.equal([
'Field',
'FragmentSpread',
'InlineFragment',
]);
expect(filterNodes(isSelectionNode)).to.deep.equal(
['Field', 'FragmentSpread', 'InlineFragment'].sort(),
);
});

it('isValueNode', () => {
expect(filterNodes(isValueNode)).to.deep.equal([
'Variable',
'IntValue',
'FloatValue',
'StringValue',
'BooleanValue',
'NullValue',
'EnumValue',
'ListValue',
'ObjectValue',
]);
expect(filterNodes(isValueNode)).to.deep.equal(
[
'Variable',
'IntValue',
'FloatValue',
'StringValue',
'BooleanValue',
'NullValue',
'EnumValue',
'ListValue',
'ObjectValue',
].sort(),
);
});

it('isConstValueNode', () => {
Expand All @@ -88,57 +89,63 @@ describe('AST node predicates', () => {
});

it('isTypeNode', () => {
expect(filterNodes(isTypeNode)).to.deep.equal([
'NamedType',
'ListType',
'NonNullType',
]);
expect(filterNodes(isTypeNode)).to.deep.equal(
['NamedType', 'ListType', 'NonNullType'].sort(),
);
});

it('isTypeSystemDefinitionNode', () => {
expect(filterNodes(isTypeSystemDefinitionNode)).to.deep.equal([
'SchemaDefinition',
'ScalarTypeDefinition',
'ObjectTypeDefinition',
'InterfaceTypeDefinition',
'UnionTypeDefinition',
'EnumTypeDefinition',
'InputObjectTypeDefinition',
'DirectiveDefinition',
]);
expect(filterNodes(isTypeSystemDefinitionNode)).to.deep.equal(
[
'SchemaDefinition',
'ScalarTypeDefinition',
'ObjectTypeDefinition',
'InterfaceTypeDefinition',
'UnionTypeDefinition',
'EnumTypeDefinition',
'InputObjectTypeDefinition',
'DirectiveDefinition',
].sort(),
);
});

it('isTypeDefinitionNode', () => {
expect(filterNodes(isTypeDefinitionNode)).to.deep.equal([
'ScalarTypeDefinition',
'ObjectTypeDefinition',
'InterfaceTypeDefinition',
'UnionTypeDefinition',
'EnumTypeDefinition',
'InputObjectTypeDefinition',
]);
expect(filterNodes(isTypeDefinitionNode)).to.deep.equal(
[
'ScalarTypeDefinition',
'ObjectTypeDefinition',
'InterfaceTypeDefinition',
'UnionTypeDefinition',
'EnumTypeDefinition',
'InputObjectTypeDefinition',
].sort(),
);
});

it('isTypeSystemExtensionNode', () => {
expect(filterNodes(isTypeSystemExtensionNode)).to.deep.equal([
'SchemaExtension',
'ScalarTypeExtension',
'ObjectTypeExtension',
'InterfaceTypeExtension',
'UnionTypeExtension',
'EnumTypeExtension',
'InputObjectTypeExtension',
]);
expect(filterNodes(isTypeSystemExtensionNode)).to.deep.equal(
[
'SchemaExtension',
'ScalarTypeExtension',
'ObjectTypeExtension',
'InterfaceTypeExtension',
'UnionTypeExtension',
'EnumTypeExtension',
'InputObjectTypeExtension',
].sort(),
);
});

it('isTypeExtensionNode', () => {
expect(filterNodes(isTypeExtensionNode)).to.deep.equal([
'ScalarTypeExtension',
'ObjectTypeExtension',
'InterfaceTypeExtension',
'UnionTypeExtension',
'EnumTypeExtension',
'InputObjectTypeExtension',
]);
expect(filterNodes(isTypeExtensionNode)).to.deep.equal(
[
'ScalarTypeExtension',
'ObjectTypeExtension',
'InterfaceTypeExtension',
'UnionTypeExtension',
'EnumTypeExtension',
'InputObjectTypeExtension',
].sort(),
);
});
});
65 changes: 65 additions & 0 deletions src/language/_kinds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/** Name */
export const NAME = 'Name' as const;

Check failure on line 2 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 2 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

/** Document */
export const DOCUMENT = 'Document' as const;

Check failure on line 5 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 5 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression
export const OPERATION_DEFINITION = 'OperationDefinition' as const;

Check failure on line 6 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 6 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression
export const VARIABLE_DEFINITION = 'VariableDefinition' as const;

Check failure on line 7 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 7 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression
export const SELECTION_SET = 'SelectionSet' as const;

Check failure on line 8 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 8 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression
export const FIELD = 'Field' as const;

Check failure on line 9 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 9 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression
export const ARGUMENT = 'Argument' as const;

Check failure on line 10 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 10 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression
export const FRAGMENT_ARGUMENT = 'FragmentArgument' as const;

Check failure on line 11 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 11 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

/** Fragments */
export const FRAGMENT_SPREAD = 'FragmentSpread' as const;

Check failure on line 14 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 14 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression
export const INLINE_FRAGMENT = 'InlineFragment' as const;
export const FRAGMENT_DEFINITION = 'FragmentDefinition' as const;

/** Values */
export const VARIABLE = 'Variable' as const;
export const INT = 'IntValue' as const;
export const FLOAT = 'FloatValue' as const;
export const STRING = 'StringValue' as const;
export const BOOLEAN = 'BooleanValue' as const;
export const NULL = 'NullValue' as const;
export const ENUM = 'EnumValue' as const;
export const LIST = 'ListValue' as const;
export const OBJECT = 'ObjectValue' as const;
export const OBJECT_FIELD = 'ObjectField' as const;

/** Directives */
export const DIRECTIVE = 'Directive' as const;

/** Types */
export const NAMED_TYPE = 'NamedType' as const;
export const LIST_TYPE = 'ListType' as const;
export const NON_NULL_TYPE = 'NonNullType' as const;

/** Type System Definitions */
export const SCHEMA_DEFINITION = 'SchemaDefinition' as const;
export const OPERATION_TYPE_DEFINITION = 'OperationTypeDefinition' as const;

/** Type Definitions */
export const SCALAR_TYPE_DEFINITION = 'ScalarTypeDefinition' as const;
export const OBJECT_TYPE_DEFINITION = 'ObjectTypeDefinition' as const;
export const FIELD_DEFINITION = 'FieldDefinition' as const;
export const INPUT_VALUE_DEFINITION = 'InputValueDefinition' as const;
export const INTERFACE_TYPE_DEFINITION = 'InterfaceTypeDefinition' as const;
export const UNION_TYPE_DEFINITION = 'UnionTypeDefinition' as const;
export const ENUM_TYPE_DEFINITION = 'EnumTypeDefinition' as const;
export const ENUM_VALUE_DEFINITION = 'EnumValueDefinition' as const;
export const INPUT_OBJECT_TYPE_DEFINITION = 'InputObjectTypeDefinition' as const;

/** Directive Definitions */
export const DIRECTIVE_DEFINITION = 'DirectiveDefinition' as const;

/** Type System Extensions */
export const SCHEMA_EXTENSION = 'SchemaExtension' as const;

/** Type Extensions */
export const SCALAR_TYPE_EXTENSION = 'ScalarTypeExtension' as const;
export const OBJECT_TYPE_EXTENSION = 'ObjectTypeExtension' as const;
export const INTERFACE_TYPE_EXTENSION = 'InterfaceTypeExtension' as const;
export const UNION_TYPE_EXTENSION = 'UnionTypeExtension' as const;
export const ENUM_TYPE_EXTENSION = 'EnumTypeExtension' as const;
export const INPUT_OBJECT_TYPE_EXTENSION = 'InputObjectTypeExtension' as const;
Loading

0 comments on commit 060bd56

Please sign in to comment.