feat(schema)!: add more range methods, rename EnumDefinition -> EnumType (#21043)

This commit is contained in:
Aaron Craelius
2024-07-24 13:42:47 +00:00
committed by GitHub
parent 1f0ce2f5b5
commit 339e26ea8f
10 changed files with 163 additions and 70 deletions
+24 -2
View File
@@ -31,7 +31,7 @@ func NewModuleSchema(objectTypes []ObjectType) (ModuleSchema, error) {
}
func addEnumType(types map[string]Type, field Field) error {
enumDef := field.EnumDefinition
enumDef := field.EnumType
if enumDef.Name == "" {
return nil
}
@@ -42,7 +42,7 @@ func addEnumType(types map[string]Type, field Field) error {
return nil
}
existingEnum, ok := existing.(EnumDefinition)
existingEnum, ok := existing.(EnumType)
if !ok {
return fmt.Errorf("enum %q already exists as a different non-enum type", enumDef.Name)
}
@@ -119,3 +119,25 @@ func (s ModuleSchema) Types(f func(Type) bool) {
}
}
}
// ObjectTypes iterators over all the object types in the schema in alphabetical order.
func (s ModuleSchema) ObjectTypes(f func(ObjectType) bool) {
s.Types(func(t Type) bool {
objTyp, ok := t.(ObjectType)
if ok {
return f(objTyp)
}
return true
})
}
// EnumTypes iterators over all the enum types in the schema in alphabetical order.
func (s ModuleSchema) EnumTypes(f func(EnumType) bool) {
s.Types(func(t Type) bool {
enumType, ok := t.(EnumType)
if ok {
return f(enumType)
}
return true
})
}