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

Method lazyLoadSchema

graphql/admin/admin.go:1009–1045  ·  view source on GitHub ↗
(namespace uint64)

Source from the content-addressed store, hash-verified

1007}
1008
1009func (as *adminServer) lazyLoadSchema(namespace uint64) error {
1010 // if the schema is already in memory, no need to fetch it from disk
1011 if currentSchema, ok := as.gqlSchemas.GetCurrent(namespace); ok && currentSchema.Loaded {
1012 return nil
1013 }
1014
1015 // otherwise, fetch the schema from disk
1016 sch, err := getCurrentGraphQLSchema(namespace)
1017 if err != nil {
1018 glog.Errorf("namespace: %d. Error reading GraphQL schema: %s.", namespace, err)
1019 return errors.Wrap(err, "failed to lazy-load GraphQL schema")
1020 }
1021
1022 var generatedSchema schema.Schema
1023 if sch.Schema == "" {
1024 // if there was no schema stored in Dgraph, we still need to attach resolvers to the main
1025 // graphql server which should just return errors for any incoming request.
1026 // generatedSchema will be nil in this case
1027 glog.Infof("namespace: %d. No GraphQL schema in Dgraph; serving empty GraphQL API",
1028 namespace)
1029 } else {
1030 generatedSchema, err = generateGQLSchema(sch, namespace)
1031 if err != nil {
1032 glog.Errorf("namespace: %d. Error processing GraphQL schema: %s.", namespace, err)
1033 return errors.Wrap(err, "failed to lazy-load GraphQL schema")
1034 }
1035 }
1036
1037 as.mux.Lock()
1038 defer as.mux.Unlock()
1039 sch.Loaded = true
1040 as.gqlSchemas.Set(namespace, sch)
1041 as.resetSchema(namespace, generatedSchema)
1042
1043 glog.Infof("namespace: %d. Successfully lazy-loaded GraphQL schema.", namespace)
1044 return nil
1045}
1046
1047func LazyLoadSchema(namespace uint64) error {
1048 return adminServerVar.lazyLoadSchema(namespace)

Callers 1

LazyLoadSchemaFunction · 0.80

Calls 9

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

Tested by

no test coverage detected