graphql_federated_graph/federated_graph/
ids.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use super::*;

macro_rules! id_newtypes {
    ($($storage:ident [ $name:ident ] -> $out:ident,)*) => {
        $(
            #[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
            pub struct $name(usize);

            impl $name {
                pub const fn const_from_usize(i: usize) -> Self {
                    $name(i)
                }
            }

            impl From<$name> for usize {
              fn from(value: $name) -> usize {
                value.0
              }
            }

            impl From<usize> for $name {
              fn from(value: usize) -> $name {
                $name(value)
              }
            }

            impl std::ops::Index<$name> for FederatedGraph {
                type Output = $out;

                fn index(&self, index: $name) -> &$out {
                    &self.$storage[index.0]
                }
            }

            impl std::ops::IndexMut<$name> for FederatedGraph {
                fn index_mut(&mut self, index: $name) -> &mut $out {
                    &mut self.$storage[index.0]
                }
            }
        )*
    }
}

id_newtypes! {
    enum_values[EnumValueId] -> EnumValueRecord,
    enum_definitions[EnumDefinitionId] -> EnumDefinitionRecord,
    directive_definitions[DirectiveDefinitionId] -> DirectiveDefinitionRecord,
    fields[FieldId] -> Field,
    input_objects[InputObjectId] -> InputObject,
    input_value_definitions[InputValueDefinitionId] -> InputValueDefinition,
    interfaces[InterfaceId] -> Interface,
    objects[ObjectId] -> Object,
    strings[StringId] -> String,
    subgraphs[SubgraphId] -> Subgraph,
    extensions[ExtensionId] -> Extension,
    scalar_definitions[ScalarDefinitionId] -> ScalarDefinitionRecord,
    unions[UnionId] -> Union,
}