MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / processGqlSchema

Method processGqlSchema

dgraph/cmd/bulk/loader.go:490–552  ·  view source on GitHub ↗
(loadType chunker.InputFormat)

Source from the content-addressed store, hash-verified

488}
489
490func (ld *loader) processGqlSchema(loadType chunker.InputFormat) {
491 if ld.opt.GqlSchemaFile == "" {
492 return
493 }
494
495 rdfSchema := `_:gqlschema <dgraph.type> "dgraph.graphql" <%#x> .
496 _:gqlschema <dgraph.graphql.xid> "dgraph.graphql.schema" <%#x> .
497 _:gqlschema <dgraph.graphql.schema> %s <%#x> .
498 `
499
500 jsonSchema := `{
501 "namespace": "%#x",
502 "dgraph.type": "dgraph.graphql",
503 "dgraph.graphql.xid": "dgraph.graphql.schema",
504 "dgraph.graphql.schema": %s
505 }`
506
507 process := func(ns uint64, schema string) {
508 // Ignore the schema if the namespace is not already seen.
509 if _, ok := ld.schema.namespaces.Load(ns); !ok {
510 fmt.Printf("No data exist for namespace: %d. Cannot load the graphql schema.", ns)
511 return
512 }
513 gqlBuf := &bytes.Buffer{}
514 schema = strconv.Quote(schema)
515 switch loadType {
516 case chunker.RdfFormat:
517 _, err := fmt.Fprintf(gqlBuf, rdfSchema, ns, ns, schema, ns)
518 x.Check(err)
519 case chunker.JsonFormat:
520 _, err := fmt.Fprintf(gqlBuf, jsonSchema, ns, schema)
521 x.Check(err)
522 }
523 ld.readerChunkCh <- &chunkWithMeta{buf: gqlBuf, filename: "<gql_schema>"}
524 }
525
526 buf := readGqlSchema(ld.opt)
527 schemas := parseGqlSchema(string(buf))
528 if ld.opt.Namespace == math.MaxUint64 {
529 // Preserve the namespace.
530 for ns, schema := range schemas {
531 process(ns, schema)
532 }
533 return
534 }
535
536 switch len(schemas) {
537 case 1:
538 // User might have exported from a different namespace. So, schema.Namespace will not be
539 // having the correct value.
540 for _, schema := range schemas {
541 process(ld.opt.Namespace, schema)
542 }
543 default:
544 if _, ok := schemas[ld.opt.Namespace]; !ok {
545 // We expect only a single GraphQL schema when loading into specific namespace.
546 fmt.Printf("Didn't find GraphQL schema for namespace %d. Not loading GraphQL schema.",
547 ld.opt.Namespace)

Callers 1

mapStageMethod · 0.95

Calls 4

CheckFunction · 0.92
readGqlSchemaFunction · 0.85
parseGqlSchemaFunction · 0.85
processFunction · 0.85

Tested by

no test coverage detected