-
Notifications
You must be signed in to change notification settings - Fork 0
/
federation.go
61 lines (49 loc) · 1.36 KB
/
federation.go
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
59
60
61
// Code generated by github.com/eduardohumberto/test-gql, DO NOT EDIT.
package generated
import (
"context"
"errors"
"fmt"
"strings"
"github.com/eduardohumberto/test-gql/plugin/federation/fedruntime"
)
func (ec *executionContext) __resolve__service(ctx context.Context) (fedruntime.Service, error) {
if ec.DisableIntrospection {
return fedruntime.Service{}, errors.New("federated introspection disabled")
}
var sdl []string
for _, src := range sources {
if src.BuiltIn {
continue
}
sdl = append(sdl, src.Input)
}
return fedruntime.Service{
SDL: strings.Join(sdl, "\n"),
}, nil
}
func (ec *executionContext) __resolve_entities(ctx context.Context, representations []map[string]interface{}) ([]fedruntime.Entity, error) {
list := []fedruntime.Entity{}
for _, rep := range representations {
typeName, ok := rep["__typename"].(string)
if !ok {
return nil, errors.New("__typename must be an existing string")
}
switch typeName {
case "Product":
id0, err := ec.unmarshalNString2string(ctx, rep["upc"])
if err != nil {
return nil, errors.New(fmt.Sprintf("Field %s undefined in schema.", "upc"))
}
entity, err := ec.resolvers.Entity().FindProductByUpc(ctx,
id0)
if err != nil {
return nil, err
}
list = append(list, entity)
default:
return nil, errors.New("unknown type: " + typeName)
}
}
return list, nil
}