From f0b17b0c1b4d1de611938e0c889e8a438ab5156b Mon Sep 17 00:00:00 2001 From: Curtis Li Date: Mon, 3 Jun 2024 09:51:47 -0700 Subject: [PATCH] Implement Named for TypeSystemDefinition Reviewed By: ginfung Differential Revision: D58083352 fbshipit-source-id: 1e67706d8bcb2eec52075b9ea5f2dddaef3bd205 --- .../graphql-syntax/src/node/type_system.rs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/compiler/crates/graphql-syntax/src/node/type_system.rs b/compiler/crates/graphql-syntax/src/node/type_system.rs index 37b0eb78061c6..194c12c72aa3e 100644 --- a/compiler/crates/graphql-syntax/src/node/type_system.rs +++ b/compiler/crates/graphql-syntax/src/node/type_system.rs @@ -7,7 +7,9 @@ use std::fmt; +use common::Named; use common::Span; +use intern::string_key::Intern; use intern::string_key::StringKey; use super::constant_directive::ConstantDirective; @@ -171,6 +173,29 @@ impl fmt::Display for TypeSystemDefinition { } } +impl Named for TypeSystemDefinition { + type Name = StringKey; + fn name(&self) -> StringKey { + match self { + TypeSystemDefinition::SchemaDefinition(_definition) => "".intern(), // Not implemented + TypeSystemDefinition::SchemaExtension(_extension) => "".intern(), // Not implemented + TypeSystemDefinition::ObjectTypeDefinition(definition) => definition.name.value, + TypeSystemDefinition::ObjectTypeExtension(extension) => extension.name.value, + TypeSystemDefinition::InterfaceTypeDefinition(definition) => definition.name.value, + TypeSystemDefinition::InterfaceTypeExtension(extension) => extension.name.value, + TypeSystemDefinition::UnionTypeDefinition(definition) => definition.name.value, + TypeSystemDefinition::UnionTypeExtension(extension) => extension.name.value, + TypeSystemDefinition::DirectiveDefinition(definition) => definition.name.value, + TypeSystemDefinition::InputObjectTypeDefinition(definition) => definition.name.value, + TypeSystemDefinition::InputObjectTypeExtension(extension) => extension.name.value, + TypeSystemDefinition::EnumTypeDefinition(definition) => definition.name.value, + TypeSystemDefinition::EnumTypeExtension(extension) => extension.name.value, + TypeSystemDefinition::ScalarTypeDefinition(definition) => definition.name.value, + TypeSystemDefinition::ScalarTypeExtension(extension) => extension.name.value, + } + } +} + /// This trait provides a *single* known into method, so we don't need /// to type method usages that utilize this trait and call into_definition(). /// It may be useful in the future to define a DefinitionIntoExtension trait