setGraphQLSchema updates the graphql schema in the dgraph cluster with the schema present in all the files in the export as passed in args.
(c *LocalCluster, files []string)
| 188 | // setGraphQLSchema updates the graphql schema in the dgraph cluster with |
| 189 | // the schema present in all the files in the export as passed in args. |
| 190 | func setGraphQLSchema(c *LocalCluster, files []string) error { |
| 191 | hc, err := c.HTTPClient() |
| 192 | if err != nil { |
| 193 | return errors.Wrap(err, "error creating HTTP client") |
| 194 | } |
| 195 | |
| 196 | for _, sf := range files { |
| 197 | data, err := readGzFile(sf, c.conf.encryption, c.encKeyPath) |
| 198 | if err != nil { |
| 199 | return err |
| 200 | } |
| 201 | // if there is no GraphQL schema in the cluster, the GQL |
| 202 | // file only has empty []. we can skip these files. |
| 203 | if len(data) < 10 { |
| 204 | continue |
| 205 | } |
| 206 | |
| 207 | var nsToSch []struct { |
| 208 | Namespace uint64 `json:"namespace"` |
| 209 | Schema string `json:"schema"` |
| 210 | } |
| 211 | if err := json.Unmarshal(data, &nsToSch); err != nil { |
| 212 | return errors.Wrapf(err, "error parsing gql schema file content [%v]", string(data)) |
| 213 | } |
| 214 | for _, nss := range nsToSch { |
| 215 | if nss.Schema == "" { |
| 216 | continue |
| 217 | } |
| 218 | |
| 219 | if c.conf.acl { |
| 220 | err := hc.LoginIntoNamespace(dgraphapi.DefaultUser, dgraphapi.DefaultPassword, nss.Namespace) |
| 221 | if err != nil { |
| 222 | return errors.Wrap(err, "error login into default namespace") |
| 223 | } |
| 224 | } |
| 225 | if err := hc.UpdateGQLSchema(nss.Schema); err != nil { |
| 226 | return errors.Wrapf(err, "error updating GQL schema to: [%v]", nss.Schema) |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | return nil |
| 231 | } |
| 232 | |
| 233 | // LiveLoad runs the live loader with provided options |
| 234 | func (c *LocalCluster) LiveLoad(opts LiveOpts) error { |
no test coverage detected