MCPcopy
hub / github.com/daptin/daptin / MakeGraphqlSchema

Function MakeGraphqlSchema

server/graphql.go:31–1072  ·  view source on GitHub ↗
(cmsConfig *resource.CmsConfig, resources map[string]*resource.DbResource)

Source from the content-addressed store, hash-verified

29var Schema graphql.Schema
30
31func MakeGraphqlSchema(cmsConfig *resource.CmsConfig, resources map[string]*resource.DbResource) *graphql.Schema {
32
33 //mutations := make(graphql.InputObjectConfigFieldMap)
34 //query := make(graphql.InputObjectConfigFieldMap)
35 //done := make(map[string]bool)
36
37 inputTypesMap := make(map[string]*graphql.Object)
38 //outputTypesMap := make(map[string]graphql.Output)
39 //connectionMap := make(map[string]*relay.GraphQLConnectionDefinitions)
40
41 nodeDefinitions = relay.NewNodeDefinitions(relay.NodeDefinitionsConfig{
42 IDFetcher: func(id string, info graphql.ResolveInfo, ctx context.Context) (interface{}, error) {
43 resolvedID := relay.FromGlobalID(id)
44
45 ur, _ := url.Parse("/api/" + resolvedID.Type)
46 pr := &http.Request{
47 Method: "GET",
48 URL: ur,
49 }
50 pr = pr.WithContext(ctx)
51 req := api2go.Request{
52 PlainRequest: pr,
53 }
54 responder, err := resources[strings.ToLower(resolvedID.Type)].FindOne(resolvedID.ID, req)
55 if responder != nil && responder.Result() != nil {
56 return responder.Result().(api2go.Api2GoModel).GetAttributes(), err
57 }
58 return nil, err
59 },
60 TypeResolve: func(p graphql.ResolveTypeParams) *graphql.Object {
61 log.Printf("Type resolve query: %v", p)
62 //return inputTypesMap[p.Value]
63 return nil
64 },
65 })
66
67 rootFields := make(graphql.Fields)
68 mutationFields := make(graphql.Fields)
69
70 actionResponseType := graphql.NewObject(graphql.ObjectConfig{
71 Name: "ActionResponse",
72 Description: "Action response",
73 Fields: graphql.Fields{
74 "ResponseType": &graphql.Field{
75 Type: graphql.String,
76 },
77 "Attributes": &graphql.Field{
78 Type: graphql.NewObject(graphql.ObjectConfig{
79 Name: "Attributes",
80 Fields: graphql.Fields{
81 "type": &graphql.Field{
82 Name: "type",
83 Type: graphql.String,
84 },
85 "message": &graphql.Field{
86 Name: "message",
87 Type: graphql.String,
88 },

Callers 1

Calls 15

CheckErrFunction · 0.92
IsStandardColumnFunction · 0.92
makeFunction · 0.85
ParseMethod · 0.80
GetGraphqlTypeMethod · 0.80
CanExecuteMethod · 0.80
DataStatsMethod · 0.80
CreateWithTransactionMethod · 0.80

Tested by

no test coverage detected