predicates.mjs 1.8 KB

12345678910111213141516171819202122232425262728
  1. import { Kind } from "./kinds.mjs";
  2. export function isDefinitionNode(node) {
  3. return isExecutableDefinitionNode(node) || isTypeSystemDefinitionNode(node) || isTypeSystemExtensionNode(node);
  4. }
  5. export function isExecutableDefinitionNode(node) {
  6. return node.kind === Kind.OPERATION_DEFINITION || node.kind === Kind.FRAGMENT_DEFINITION;
  7. }
  8. export function isSelectionNode(node) {
  9. return node.kind === Kind.FIELD || node.kind === Kind.FRAGMENT_SPREAD || node.kind === Kind.INLINE_FRAGMENT;
  10. }
  11. export function isValueNode(node) {
  12. return node.kind === Kind.VARIABLE || node.kind === Kind.INT || node.kind === Kind.FLOAT || node.kind === Kind.STRING || node.kind === Kind.BOOLEAN || node.kind === Kind.NULL || node.kind === Kind.ENUM || node.kind === Kind.LIST || node.kind === Kind.OBJECT;
  13. }
  14. export function isTypeNode(node) {
  15. return node.kind === Kind.NAMED_TYPE || node.kind === Kind.LIST_TYPE || node.kind === Kind.NON_NULL_TYPE;
  16. }
  17. export function isTypeSystemDefinitionNode(node) {
  18. return node.kind === Kind.SCHEMA_DEFINITION || isTypeDefinitionNode(node) || node.kind === Kind.DIRECTIVE_DEFINITION;
  19. }
  20. export function isTypeDefinitionNode(node) {
  21. return node.kind === Kind.SCALAR_TYPE_DEFINITION || node.kind === Kind.OBJECT_TYPE_DEFINITION || node.kind === Kind.INTERFACE_TYPE_DEFINITION || node.kind === Kind.UNION_TYPE_DEFINITION || node.kind === Kind.ENUM_TYPE_DEFINITION || node.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION;
  22. }
  23. export function isTypeSystemExtensionNode(node) {
  24. return node.kind === Kind.SCHEMA_EXTENSION || isTypeExtensionNode(node);
  25. }
  26. export function isTypeExtensionNode(node) {
  27. return node.kind === Kind.SCALAR_TYPE_EXTENSION || node.kind === Kind.OBJECT_TYPE_EXTENSION || node.kind === Kind.INTERFACE_TYPE_EXTENSION || node.kind === Kind.UNION_TYPE_EXTENSION || node.kind === Kind.ENUM_TYPE_EXTENSION || node.kind === Kind.INPUT_OBJECT_TYPE_EXTENSION;
  28. }