Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

go schemabuilder: apply object options even if object is already regi… #545

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions graphql/schemabuilder/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,21 @@ func NewSchemaWithName(name string) *Schema {
// the corresponding map of the enums.
//
// For example a enum could be declared as follows:
// type enumType int32
// const (
// one enumType = 1
// two enumType = 2
// three enumType = 3
// )
//
// type enumType int32
// const (
// one enumType = 1
// two enumType = 2
// three enumType = 3
// )
//
// Then the Enum can be registered as:
// s.Enum(enumType(1), map[string]interface{}{
// "one": enumType(1),
// "two": enumType(2),
// "three": enumType(3),
// })
//
// s.Enum(enumType(1), map[string]interface{}{
// "one": enumType(1),
// "two": enumType(2),
// "three": enumType(3),
// })
func (s *Schema) Enum(val interface{}, enumMap interface{}) {
typ := reflect.TypeOf(val)
if s.enumTypes == nil {
Expand Down Expand Up @@ -169,6 +171,10 @@ func (s *Schema) Object(name string, typ interface{}, options ...ObjectOption) *
if reflect.TypeOf(object.Type) != reflect.TypeOf(typ) {
panic("re-registered object with different type")
}
for _, opt := range options {
opt.apply(s, object)
}

return object
}
object := &Object{
Expand Down