MCPcopy
hub / github.com/dgraph-io/dgraph / initServer

Method initServer

graphql/admin/admin.go:816–866  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

814}
815
816func (as *adminServer) initServer() {
817 // Nothing else should be able to lock before here. The admin resolvers aren't yet
818 // set up (they all just error), so we will obtain the lock here without contention.
819 // We then setup the admin resolvers and they must wait until we are done before the
820 // first admin calls will go through.
821 as.mux.Lock()
822 defer as.mux.Unlock()
823
824 // It takes a few seconds for the Dgraph cluster to be up and running.
825 // Before that, trying to read the GraphQL schema will result in error:
826 // "Please retry again, server is not ready to accept requests."
827 // 5 seconds is a pretty reliable wait for a fresh instance to read the
828 // schema on a first try.
829 waitFor := 5 * time.Second
830
831 for {
832 <-time.After(waitFor)
833
834 sch, err := getCurrentGraphQLSchema(x.RootNamespace)
835 if err != nil {
836 glog.Errorf("namespace: %d. Error reading GraphQL schema: %s.", x.RootNamespace, err)
837 continue
838 }
839 sch.Loaded = true
840 as.gqlSchemas.Set(x.RootNamespace, sch)
841 // adding the actual resolvers for updateGQLSchema and getGQLSchema only after server has
842 // current GraphQL schema, if there was any.
843 as.addConnectedAdminResolvers()
844 mainHealthStore.up()
845
846 if sch.Schema == "" {
847 glog.Infof("namespace: %d. No GraphQL schema in Dgraph; serving empty GraphQL API",
848 x.RootNamespace)
849 break
850 }
851
852 generatedSchema, err := generateGQLSchema(sch, x.RootNamespace)
853 if err != nil {
854 glog.Errorf("namespace: %d. Error processing GraphQL schema: %s.",
855 x.RootNamespace, err)
856 break
857 }
858 as.incrementSchemaUpdateCounter(x.RootNamespace)
859 as.resetSchema(x.RootNamespace, generatedSchema)
860
861 glog.Infof("namespace: %d. Successfully loaded GraphQL schema. Serving GraphQL API.",
862 x.RootNamespace)
863
864 break
865 }
866}
867
868// addConnectedAdminResolvers sets up the real resolvers
869func (as *adminServer) addConnectedAdminResolvers() {

Callers 1

newAdminResolverFunction · 0.95

Calls 11

resetSchemaMethod · 0.95
getCurrentGraphQLSchemaFunction · 0.85
generateGQLSchemaFunction · 0.85
upMethod · 0.80
InfofMethod · 0.80
SetMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected