(cmsConfig *resource.CmsConfig, resources map[string]*resource.DbResource)
| 29 | var Schema graphql.Schema |
| 30 | |
| 31 | func 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 | }, |
no test coverage detected