|
|
@ -61,7 +61,7 @@ type ExtensionFieldInfo struct {
|
|
|
|
type ExtensionInfo struct {
|
|
|
|
type ExtensionInfo struct {
|
|
|
|
ExtType
|
|
|
|
ExtType
|
|
|
|
Type reflect.Type
|
|
|
|
Type reflect.Type
|
|
|
|
Fields map[string]ExtensionFieldInfo
|
|
|
|
Fields map[Tag]ExtensionFieldInfo
|
|
|
|
Data interface{}
|
|
|
|
Data interface{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -328,13 +328,13 @@ func RegisterExtension[E any, T interface { *E; Extension}](ctx *Context, data i
|
|
|
|
return fmt.Errorf("Cannot register extension %+v of type %+v, type already exists in context", reflect_type, ext_type)
|
|
|
|
return fmt.Errorf("Cannot register extension %+v of type %+v, type already exists in context", reflect_type, ext_type)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fields := map[string]ExtensionFieldInfo{}
|
|
|
|
fields := map[Tag]ExtensionFieldInfo{}
|
|
|
|
|
|
|
|
|
|
|
|
for _, field := range(reflect.VisibleFields(reflect_type)) {
|
|
|
|
for _, field := range(reflect.VisibleFields(reflect_type)) {
|
|
|
|
gv_tag, tagged_gv := field.Tag.Lookup("gv")
|
|
|
|
gv_tag, tagged_gv := field.Tag.Lookup("gv")
|
|
|
|
node_tag := field.Tag.Get("node")
|
|
|
|
node_tag := field.Tag.Get("node")
|
|
|
|
if tagged_gv {
|
|
|
|
if tagged_gv {
|
|
|
|
fields[gv_tag] = ExtensionFieldInfo{
|
|
|
|
fields[Tag(gv_tag)] = ExtensionFieldInfo{
|
|
|
|
Index: field.Index,
|
|
|
|
Index: field.Index,
|
|
|
|
Type: field.Type,
|
|
|
|
Type: field.Type,
|
|
|
|
NodeTag: node_tag,
|
|
|
|
NodeTag: node_tag,
|
|
|
@ -354,7 +354,7 @@ func RegisterExtension[E any, T interface { *E; Extension}](ctx *Context, data i
|
|
|
|
|
|
|
|
|
|
|
|
type FieldMapping struct {
|
|
|
|
type FieldMapping struct {
|
|
|
|
Extension ExtType
|
|
|
|
Extension ExtType
|
|
|
|
Tag string
|
|
|
|
Tag Tag
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func RegisterNodeInterface(ctx *Context, name string, fields map[string]graphql.Type) error {
|
|
|
|
func RegisterNodeInterface(ctx *Context, name string, fields map[string]graphql.Type) error {
|
|
|
@ -437,7 +437,6 @@ func RegisterNodeType(ctx *Context, name string, mappings map[string]FieldMappin
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ext_map := map[ExtType]bool{}
|
|
|
|
|
|
|
|
for field_name, mapping := range(mappings) {
|
|
|
|
for field_name, mapping := range(mappings) {
|
|
|
|
_, duplicate := fields[field_name]
|
|
|
|
_, duplicate := fields[field_name]
|
|
|
|
if duplicate {
|
|
|
|
if duplicate {
|
|
|
@ -449,7 +448,12 @@ func RegisterNodeType(ctx *Context, name string, mappings map[string]FieldMappin
|
|
|
|
return fmt.Errorf("Cannot register node type %s, unknown extension %s", name, mapping.Extension)
|
|
|
|
return fmt.Errorf("Cannot register node type %s, unknown extension %s", name, mapping.Extension)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ext_map[mapping.Extension] = true
|
|
|
|
_, exists = reverse_fields[mapping.Extension]
|
|
|
|
|
|
|
|
if exists == false {
|
|
|
|
|
|
|
|
reverse_fields[mapping.Extension] = map[Tag]string{}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
reverse_fields[mapping.Extension][mapping.Tag] = field_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ext_field, exists := ext_info.Fields[mapping.Tag]
|
|
|
|
ext_field, exists := ext_info.Fields[mapping.Tag]
|
|
|
|
if exists == false {
|
|
|
|
if exists == false {
|
|
|
@ -496,7 +500,7 @@ func RegisterNodeType(ctx *Context, name string, mappings map[string]FieldMappin
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
extensions := []ExtType{}
|
|
|
|
extensions := []ExtType{}
|
|
|
|
for ext_type := range(ext_map) {
|
|
|
|
for ext_type := range(reverse_fields) {
|
|
|
|
extensions = append(extensions, ext_type)
|
|
|
|
extensions = append(extensions, ext_type)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|