Skip to content

Commit

Permalink
Implement Named for TypeSystemDefinition
Browse files Browse the repository at this point in the history
Reviewed By: ginfung

Differential Revision: D58083352

fbshipit-source-id: 1e67706d8bcb2eec52075b9ea5f2dddaef3bd205
  • Loading branch information
cuhtis authored and facebook-github-bot committed Jun 3, 2024
1 parent d803920 commit f0b17b0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions compiler/crates/graphql-syntax/src/node/type_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f0b17b0

Please sign in to comment.