(gqlHealthStore *admin.GraphQLHealthStore, globalEpoch map[uint64]*uint64)
| 700 | } |
| 701 | |
| 702 | func graphqlProbeHandler(gqlHealthStore *admin.GraphQLHealthStore, globalEpoch map[uint64]*uint64) http.Handler { |
| 703 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 704 | x.AddCorsHeaders(w) |
| 705 | w.Header().Set("Content-Type", "application/json") |
| 706 | // lazy load the schema so that just by making a probe request, |
| 707 | // one can boot up GraphQL for their namespace |
| 708 | namespace := x.ExtractNamespaceHTTP(r) |
| 709 | if err := admin.LazyLoadSchema(namespace); err != nil { |
| 710 | w.WriteHeader(http.StatusInternalServerError) |
| 711 | x.Check2(w.Write([]byte(fmt.Sprintf(`{"error":"%s"}`, err)))) |
| 712 | return |
| 713 | } |
| 714 | |
| 715 | healthStatus := gqlHealthStore.GetHealth() |
| 716 | httpStatusCode := http.StatusOK |
| 717 | if !healthStatus.Healthy { |
| 718 | httpStatusCode = http.StatusServiceUnavailable |
| 719 | } |
| 720 | w.WriteHeader(httpStatusCode) |
| 721 | e := globalEpoch[namespace] |
| 722 | var counter uint64 |
| 723 | if e != nil { |
| 724 | counter = atomic.LoadUint64(e) |
| 725 | } |
| 726 | x.Check2(w.Write([]byte(fmt.Sprintf(`{"status":"%s","schemaUpdateCounter":%d}`, |
| 727 | healthStatus.StatusMsg, counter)))) |
| 728 | }) |
| 729 | } |
| 730 | |
| 731 | func resolveWithAdminServer(gqlReq *schema.Request, r *http.Request, |
| 732 | adminServer admin.IServeGraphQL) *schema.Response { |
no test coverage detected
searching dependent graphs…