From 3d866357aaae505b53224faef10de9db2af6d797 Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Tue, 17 Sep 2019 17:48:03 -0700 Subject: [PATCH 1/4] Simplify type definitions. Type definitons are now simpler as the type of the fields is not required anymore. The new format is: ``` type Person { name address ssn } ``` --- dgraph/cmd/alpha/run_test.go | 18 +- dgraph/cmd/live/load-json/family.schema | 14 +- dgraph/cmd/live/load-uids/family.schema | 14 +- query/common_test.go | 34 +-- query/query3_test.go | 10 +- schema/parse.go | 49 ---- schema/parse_test.go | 305 ++---------------------- systest/bulk_live_cases_test.go | 4 +- systest/mutations_test.go | 8 +- 9 files changed, 69 insertions(+), 387 deletions(-) diff --git a/dgraph/cmd/alpha/run_test.go b/dgraph/cmd/alpha/run_test.go index 2b88ee81924..b57c65129c1 100644 --- a/dgraph/cmd/alpha/run_test.go +++ b/dgraph/cmd/alpha/run_test.go @@ -1228,15 +1228,15 @@ func TestListTypeSchemaChange(t *testing.T) { func TestDeleteAllSP2(t *testing.T) { s := ` type Node12345 { - nodeType: string - name: string - date: dateTime - weight: float - weightUnit: string - lifeLoad: int - stressLevel: int - plan: string - postMortem: string + nodeType + name + date + weight + weightUnit + lifeLoad + stressLevel + plan + postMortem } ` require.NoError(t, dropAll()) diff --git a/dgraph/cmd/live/load-json/family.schema b/dgraph/cmd/live/load-json/family.schema index d2f7979bfb2..c33cfb00acb 100644 --- a/dgraph/cmd/live/load-json/family.schema +++ b/dgraph/cmd/live/load-json/family.schema @@ -1,11 +1,11 @@ type FamilyMember { - name: string - age: int - role: string - aka: string - carries: string - parent_to: [FamilyMember] - sibling_of: [FamilyMember] + name + age + role + aka + carries + parent_to + sibling_of } name:string @index(term) . diff --git a/dgraph/cmd/live/load-uids/family.schema b/dgraph/cmd/live/load-uids/family.schema index ea06cf78f8f..46d33d28115 100644 --- a/dgraph/cmd/live/load-uids/family.schema +++ b/dgraph/cmd/live/load-uids/family.schema @@ -1,11 +1,11 @@ type FamilyMember { - name: string - age: int - role: string - aka: string - carries: string - parent_to: [FamilyMember] - sibling_of: [FamilyMember] + name + age + role + aka + carries + parent_to + sibling_of } name:string @index(term) . diff --git a/query/common_test.go b/query/common_test.go index a171d11035c..7c1577a0da8 100644 --- a/query/common_test.go +++ b/query/common_test.go @@ -192,38 +192,38 @@ func addGeoMultiPolygonToCluster(uid uint64, polygons [][][][]float64) { const testSchema = ` type Person { - name: string - pet: Animal + name + pet } type Animal { - name: string + name } type CarModel { - make: string - model: string - year: int - previous_model: CarModel + make + model + year + previous_model } type SchoolInfo { - name: string - abbr: string - school: [uid] - district: [uid] - state: [uid] - county: [uid] + name + abbr + school + district + state + county } type User { - name: string - password: password + name + password } type Node { - node: uid - name: string + node + name } name : string @index(term, exact, trigram) @count @lang . diff --git a/query/query3_test.go b/query/query3_test.go index 617e3b6df15..9a8bdb4713c 100644 --- a/query/query3_test.go +++ b/query/query3_test.go @@ -2150,11 +2150,13 @@ func TestQueryUnknownType(t *testing.T) { require.JSONEq(t, `{"data": {}}`, js) } +// TODO(martinmr): Change type query representation since the type of a field is no longer +// relevant. func TestQuerySingleType(t *testing.T) { query := `schema(type: Person) {}` js := processQueryNoErr(t, query) require.JSONEq(t, `{"data": {"types":[{"name":"Person", - "fields":[{"name":"name", "type":"string"}, {"name":"pet", "type":"Animal"}]}]}}`, + "fields":[{"name":"name", "type":"default"}, {"name":"pet", "type":"default"}]}]}}`, js) } @@ -2162,7 +2164,7 @@ func TestQueryMultipleTypes(t *testing.T) { query := `schema(type: [Person, Animal]) {}` js := processQueryNoErr(t, query) require.JSONEq(t, `{"data": {"types":[{"name":"Animal", - "fields":[{"name":"name", "type":"string"}]}, - {"name":"Person", "fields":[{"name":"name", "type": "string"}, - {"name":"pet", "type":"Animal"}]}]}}`, js) + "fields":[{"name":"name", "type":"default"}]}, + {"name":"Person", "fields":[{"name":"name", "type": "default"}, + {"name":"pet", "type":"default"}]}]}}`, js) } diff --git a/schema/parse.go b/schema/parse.go index 1cc1299e83c..1b217cfd422 100644 --- a/schema/parse.go +++ b/schema/parse.go @@ -351,63 +351,14 @@ func parseTypeDeclaration(it *lex.ItemIterator) (*pb.TypeUpdate, error) { func parseTypeField(it *lex.ItemIterator) (*pb.SchemaUpdate, error) { field := &pb.SchemaUpdate{Predicate: it.Item().Val} - var list bool it.Next() - if it.Item().Typ != itemColon { - return nil, it.Item().Errorf("Missing colon in type declaration. Got %v", it.Item().Val) - } - - it.Next() - if it.Item().Typ == itemLeftSquare { - list = true - it.Next() - } - - if it.Item().Typ != itemText { - return nil, it.Item().Errorf("Missing field type in type declaration. Got %v", - it.Item().Val) - } - field.ValueType = getType(it.Item().Val) - if field.ValueType == pb.Posting_OBJECT { - field.ObjectTypeName = it.Item().Val - } - - it.Next() - if it.Item().Typ == itemExclamationMark { - field.NonNullable = true - it.Next() - } - - if list { - if it.Item().Typ != itemRightSquare { - return nil, it.Item().Errorf("Expected matching square bracket. Got %v", it.Item().Val) - } - field.List = true - it.Next() - - if it.Item().Typ == itemExclamationMark { - field.NonNullableList = true - it.Next() - } - } - if it.Item().Typ != itemNewLine { return nil, it.Item().Errorf("Expected new line after field declaration. Got %v", it.Item().Val) } - return field, nil } -func getType(typeName string) pb.Posting_ValType { - typ, ok := types.TypeForName(strings.ToLower(typeName)) - if ok { - return pb.Posting_ValType(typ) - } - - return pb.Posting_OBJECT -} - // ParsedSchema represents the parsed schema and type updates. type ParsedSchema struct { Preds []*pb.SchemaUpdate diff --git a/schema/parse_test.go b/schema/parse_test.go index ab8ff1eec27..32920f0bb21 100644 --- a/schema/parse_test.go +++ b/schema/parse_test.go @@ -398,7 +398,7 @@ func TestParseSingleType(t *testing.T) { reset() result, err := Parse(` type Person { - Name: string + name } `) require.NoError(t, err) @@ -407,33 +407,7 @@ func TestParseSingleType(t *testing.T) { TypeName: "Person", Fields: []*pb.SchemaUpdate{ { - Predicate: "Name", - ValueType: pb.Posting_STRING, - }, - }, - }, result.Types[0]) -} - -func TestParseBaseTypesCaseInsensitive(t *testing.T) { - reset() - result, err := Parse(` - type Person { - Name: string - LastName: String - } - `) - require.NoError(t, err) - require.Equal(t, 1, len(result.Types)) - require.Equal(t, &pb.TypeUpdate{ - TypeName: "Person", - Fields: []*pb.SchemaUpdate{ - { - Predicate: "Name", - ValueType: pb.Posting_STRING, - }, - { - Predicate: "LastName", - ValueType: pb.Posting_STRING, + Predicate: "name", }, }, }, result.Types[0]) @@ -443,7 +417,7 @@ func TestParseCombinedSchemasAndTypes(t *testing.T) { reset() result, err := Parse(` type Person { - + name } name: string . `) @@ -456,6 +430,11 @@ func TestParseCombinedSchemasAndTypes(t *testing.T) { require.Equal(t, 1, len(result.Types)) require.Equal(t, &pb.TypeUpdate{ TypeName: "Person", + Fields: []*pb.SchemaUpdate{ + { + Predicate: "name", + }, + }, }, result.Types[0]) } @@ -463,10 +442,10 @@ func TestParseMultipleTypes(t *testing.T) { reset() result, err := Parse(` type Person { - Name: string + name } type Animal { - Name: string + name } `) require.NoError(t, err) @@ -475,8 +454,7 @@ func TestParseMultipleTypes(t *testing.T) { TypeName: "Person", Fields: []*pb.SchemaUpdate{ { - Predicate: "Name", - ValueType: pb.Posting_STRING, + Predicate: "name", }, }, }, result.Types[0]) @@ -484,282 +462,33 @@ func TestParseMultipleTypes(t *testing.T) { TypeName: "Animal", Fields: []*pb.SchemaUpdate{ { - Predicate: "Name", - ValueType: pb.Posting_STRING, + Predicate: "name", }, }, }, result.Types[1]) } -func TestParseObjectType(t *testing.T) { - reset() - result, err := Parse(` - type Person { - Father: Person - Mother: Person - Children: [Person] - } - `) - require.NoError(t, err) - require.Equal(t, 1, len(result.Types)) - require.Equal(t, &pb.TypeUpdate{ - TypeName: "Person", - Fields: []*pb.SchemaUpdate{ - { - Predicate: "Father", - ValueType: pb.Posting_OBJECT, - ObjectTypeName: "Person", - }, - { - Predicate: "Mother", - ValueType: pb.Posting_OBJECT, - ObjectTypeName: "Person", - }, - { - Predicate: "Children", - ValueType: pb.Posting_OBJECT, - ObjectTypeName: "Person", - List: true, - }, - }, - }, result.Types[0]) -} - -func TestParseScalarType(t *testing.T) { - reset() - result, err := Parse(` - type Person { - Name: string - Nickname: [String] - Alive: Bool - } - `) - require.NoError(t, err) - require.Equal(t, 1, len(result.Types)) - require.Equal(t, &pb.TypeUpdate{ - TypeName: "Person", - Fields: []*pb.SchemaUpdate{ - { - Predicate: "Name", - ValueType: pb.Posting_STRING, - }, - { - Predicate: "Nickname", - ValueType: pb.Posting_STRING, - List: true, - }, - { - Predicate: "Alive", - ValueType: pb.Posting_BOOL, - }, - }, - }, result.Types[0]) -} - -func TestParseCombinedTypes(t *testing.T) { - reset() - result, err := Parse(` - type Person { - Name: string - Nickname: [string] - Parents: [Person] - } - `) - require.NoError(t, err) - require.Equal(t, 1, len(result.Types)) - require.Equal(t, &pb.TypeUpdate{ - TypeName: "Person", - Fields: []*pb.SchemaUpdate{ - { - Predicate: "Name", - ValueType: pb.Posting_STRING, - }, - { - Predicate: "Nickname", - ValueType: pb.Posting_STRING, - List: true, - }, - { - Predicate: "Parents", - ValueType: pb.Posting_OBJECT, - ObjectTypeName: "Person", - List: true, - }, - }, - }, result.Types[0]) -} - -func TestParseNonNullableScalar(t *testing.T) { - reset() - result, err := Parse(` - type Person { - Name: string! - Nickname: [string] - } - `) - require.NoError(t, err) - require.Equal(t, 1, len(result.Types)) - require.Equal(t, &pb.TypeUpdate{ - TypeName: "Person", - Fields: []*pb.SchemaUpdate{ - { - Predicate: "Name", - ValueType: pb.Posting_STRING, - NonNullable: true, - }, - { - Predicate: "Nickname", - ValueType: pb.Posting_STRING, - List: true, - }, - }, - }, result.Types[0]) -} - -func TestParseNonNullableList(t *testing.T) { - reset() - result, err := Parse(` - type Person { - Name: string - Nickname: [string]! - } - `) - require.NoError(t, err) - require.Equal(t, 1, len(result.Types)) - require.Equal(t, &pb.TypeUpdate{ - TypeName: "Person", - Fields: []*pb.SchemaUpdate{ - { - Predicate: "Name", - ValueType: pb.Posting_STRING, - }, - { - Predicate: "Nickname", - ValueType: pb.Posting_STRING, - List: true, - NonNullableList: true, - }, - }, - }, result.Types[0]) -} - -func TestParseNonNullableScalarAndList(t *testing.T) { - reset() - result, err := Parse(` - type Person { - Name: string! - Nickname: [string!]! - } - `) - require.NoError(t, err) - require.Equal(t, 1, len(result.Types)) - require.Equal(t, &pb.TypeUpdate{ - TypeName: "Person", - Fields: []*pb.SchemaUpdate{ - { - Predicate: "Name", - ValueType: pb.Posting_STRING, - NonNullable: true, - }, - { - Predicate: "Nickname", - ValueType: pb.Posting_STRING, - List: true, - NonNullable: true, - NonNullableList: true, - }, - }, - }, result.Types[0]) -} - func TestParseTypeDuplicateFields(t *testing.T) { reset() _, err := Parse(` type Person { - Name: string! - Name: string + name + name } `) require.Error(t, err) - require.Contains(t, err.Error(), "Duplicate fields with name: Name") + require.Contains(t, err.Error(), "Duplicate fields with name: name") } func TestParseTypeErrMissingNewLine(t *testing.T) { reset() _, err := Parse(` type Person { - }type Animal {} - `) + }type Animal {}`) require.Error(t, err) require.Contains(t, err.Error(), "Expected new line or EOF after type declaration") } -func TestParseTypeErrMissingColon(t *testing.T) { - reset() - _, err := Parse(` - type Person { - Name string - } - `) - require.Error(t, err) - require.Contains(t, err.Error(), "Missing colon in type declaration") -} - -func TestParseTypeErrMultipleTypes(t *testing.T) { - reset() - _, err := Parse(` - type Person { - Name: bool string - } - `) - require.Error(t, err) - require.Contains(t, err.Error(), "Expected new line after field declaration") -} - -func TestParseTypeErrMultipleExclamationMarks(t *testing.T) { - reset() - _, err := Parse(` - type Person { - Name: bool!! - } - `) - require.Error(t, err) - require.Contains(t, err.Error(), "Expected new line after field declaration") -} - -func TestParseTypeErrMissingSquareBracket(t *testing.T) { - reset() - _, err := Parse(` - type Person { - Name: [string - } - `) - require.Error(t, err) - require.Contains(t, err.Error(), "Expected matching square bracket") -} - -func TestParseTypeErrMultipleSquareBrackets(t *testing.T) { - reset() - _, err := Parse(` - type Person { - Name: [[string]] - } - `) - require.Error(t, err) - require.Contains(t, err.Error(), "Missing field type in type declaration") -} - -func TestParseTypeErrMissingType(t *testing.T) { - reset() - _, err := Parse(` - type Person { - Name: - } - `) - require.Error(t, err) - require.Contains(t, err.Error(), "Missing field type in type declaration") -} - func TestParseComments(t *testing.T) { reset() _, err := Parse(` @@ -811,7 +540,7 @@ func TestParseTypeComments(t *testing.T) { # User is a service user type User { # TODO: add more fields - Name: string # e.g., srfrog + name # e.g., srfrog # expanded comment # embedded # comments # here } diff --git a/systest/bulk_live_cases_test.go b/systest/bulk_live_cases_test.go index 94a00819b78..d7ff8fa5b17 100644 --- a/systest/bulk_live_cases_test.go +++ b/systest/bulk_live_cases_test.go @@ -271,7 +271,7 @@ func TestCountIndex(t *testing.T) { func TestLoadTypes(t *testing.T) { s := newSuite(t, ` type Person { - name: string + name } `, ` _:alice "Alice" . @@ -281,7 +281,7 @@ func TestLoadTypes(t *testing.T) { // Ensures that the index keys are written to disk after commit. time.Sleep(time.Second) t.Run("All queries", s.testCase("schema(type: Person) {}", - `{"types":[{"name":"Person", "fields":[{"name":"name", "type":"string"}]}]}`)) + `{"types":[{"name":"Person", "fields":[{"name":"name", "type":"default"}]}]}`)) } // This test is similar to TestCount but the friend predicate is not a list. The bulk loader diff --git a/systest/mutations_test.go b/systest/mutations_test.go index dc174e4d098..89807f6d851 100644 --- a/systest/mutations_test.go +++ b/systest/mutations_test.go @@ -834,8 +834,8 @@ func DeleteWithExpandAll(t *testing.T, c *dgo.Dgraph) { op := &api.Operation{} op.Schema = ` type Node { - to: uid - name: string + to + name } ` @@ -1566,7 +1566,7 @@ func DropType(t *testing.T, c *dgo.Dgraph) { require.NoError(t, c.Alter(ctx, &api.Operation{ Schema: ` type Person { - name: string + name } `, })) @@ -1576,7 +1576,7 @@ func DropType(t *testing.T, c *dgo.Dgraph) { resp, err := c.NewReadOnlyTxn().Query(ctx, query) require.NoError(t, err) testutil.CompareJSON(t, `{"types":[{"name":"Person", - "fields":[{"name":"name", "type":"string"}]}]}`, string(resp.Json)) + "fields":[{"name":"name", "type":"default"}]}]}`, string(resp.Json)) require.NoError(t, c.Alter(ctx, &api.Operation{ DropOp: api.Operation_TYPE, From 184ac2d5e6565f05f692a3b1f12f6299f2601467 Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Wed, 18 Sep 2019 11:37:17 -0700 Subject: [PATCH 2/4] Fix export and test. --- worker/export.go | 25 ------------------------- worker/export_test.go | 15 +++------------ 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/worker/export.go b/worker/export.go index 358291003b4..f01a27fccf6 100644 --- a/worker/export.go +++ b/worker/export.go @@ -333,31 +333,6 @@ func fieldToString(update *pb.SchemaUpdate) string { var builder strings.Builder builder.WriteString("\t") builder.WriteString(update.Predicate) - builder.WriteString(": ") - - if update.List { - builder.WriteString("[") - } - - if update.ValueType == pb.Posting_OBJECT { - builder.WriteString(update.ObjectTypeName) - } else { - tid := types.TypeID(update.ValueType) - builder.WriteString(tid.Name()) - } - - if update.NonNullable { - builder.WriteString("!") - } - - if update.List { - builder.WriteString("]") - } - - if update.NonNullableList { - builder.WriteString("!") - } - builder.WriteString("\n") return builder.String() } diff --git a/worker/export_test.go b/worker/export_test.go index 17bdbc895e7..761b2a516f7 100644 --- a/worker/export_test.go +++ b/worker/export_test.go @@ -52,22 +52,13 @@ var personType = &pb.TypeUpdate{ TypeName: "Person", Fields: []*pb.SchemaUpdate{ { - Predicate: "name", - ValueType: pb.Posting_STRING, - NonNullable: true, + Predicate: "name", }, { - Predicate: "friend", - ValueType: pb.Posting_UID, - List: true, - NonNullable: true, - NonNullableList: true, + Predicate: "friend", }, { - Predicate: "friend_not_served", - ValueType: pb.Posting_OBJECT, - List: true, - ObjectTypeName: "Person", + Predicate: "friend_not_served", }, }, } From 377892eeeeac2966054712149a33ee7ee8af20a3 Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Wed, 18 Sep 2019 16:26:52 -0700 Subject: [PATCH 3/4] Update type definitions in documentation. --- wiki/content/howto/index.md | 4 ++-- wiki/content/query-language/index.md | 26 ++++++++++++-------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/wiki/content/howto/index.md b/wiki/content/howto/index.md index 4d406fc7ae4..bc456c84f75 100644 --- a/wiki/content/howto/index.md +++ b/wiki/content/howto/index.md @@ -776,8 +776,8 @@ To make it work again, add a type definition via the alter endpoint. Let’s ass ```text type Person { - name: string - age: int + name + age } ``` diff --git a/wiki/content/query-language/index.md b/wiki/content/query-language/index.md index 5795866b5bc..062762209ff 100644 --- a/wiki/content/query-language/index.md +++ b/wiki/content/query-language/index.md @@ -1815,14 +1815,14 @@ the following definitions: ``` type Animal { - name: string - species: uid - dob: datetime + name + species + dob } type Pet { - owner: uid - veterinarian: uid + owner + veterinarian } ``` @@ -2375,11 +2375,11 @@ Types are defined using a GraphQL-like syntax. For example: ``` type Student { - name: string - dob: datetime - home_address: string - year: int - friends: [uid] + name + dob + home_address + year + friends } ``` @@ -2407,19 +2407,17 @@ different. ``` type Student { - student_name: string + student_name } type Textbook { - textbook_name: string + textbook_name } student_name: string @index(exact) . textbook_name: string @lang @index(fulltext) . ``` -Types also support lists like `friends: [uid]` or `tags: [string]`. - Altering the schema for a type that already exists, overwrites the existing definition. From 3bd6472e9d7c44a1ee8b40e439fd030e9668a712 Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Tue, 1 Oct 2019 11:16:48 -0700 Subject: [PATCH 4/4] Add backwards compatibility with deprecated type format. --- schema/parse.go | 60 +++++++++++++++++++++++++++++++++++++++++--- schema/parse_test.go | 50 ++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 3 deletions(-) diff --git a/schema/parse.go b/schema/parse.go index 1b217cfd422..61b6e2335a5 100644 --- a/schema/parse.go +++ b/schema/parse.go @@ -24,6 +24,7 @@ import ( "github.com/dgraph-io/dgraph/tok" "github.com/dgraph-io/dgraph/types" "github.com/dgraph-io/dgraph/x" + "github.com/golang/glog" "github.com/pkg/errors" ) @@ -335,7 +336,7 @@ func parseTypeDeclaration(it *lex.ItemIterator) (*pb.TypeUpdate, error) { typeUpdate.Fields = fields return typeUpdate, nil case itemText: - field, err := parseTypeField(it) + field, err := parseTypeField(it, typeUpdate.TypeName) if err != nil { return nil, err } @@ -349,16 +350,69 @@ func parseTypeDeclaration(it *lex.ItemIterator) (*pb.TypeUpdate, error) { return nil, errors.Errorf("Shouldn't reach here.") } -func parseTypeField(it *lex.ItemIterator) (*pb.SchemaUpdate, error) { +func parseTypeField(it *lex.ItemIterator, typeName string) (*pb.SchemaUpdate, error) { field := &pb.SchemaUpdate{Predicate: it.Item().Val} + var list bool + it.Next() + + // Simplified type definitions only require the field name. If a new line is found, + // proceed to the next field in the type. + if it.Item().Typ == itemNewLine { + return field, nil + } + + // For the sake of backwards-compatibility, process type definitions in the old format, + // but ignore the information after the colon. + if it.Item().Typ != itemColon { + return nil, it.Item().Errorf("Missing colon in type declaration. Got %v", it.Item().Val) + } + + it.Next() + if it.Item().Typ == itemLeftSquare { + list = true + it.Next() + } + + if it.Item().Typ != itemText { + return nil, it.Item().Errorf("Missing field type in type declaration. Got %v", + it.Item().Val) + } it.Next() + if it.Item().Typ == itemExclamationMark { + it.Next() + } + + if list { + if it.Item().Typ != itemRightSquare { + return nil, it.Item().Errorf("Expected matching square bracket. Got %v", it.Item().Val) + } + it.Next() + + if it.Item().Typ == itemExclamationMark { + it.Next() + } + } + if it.Item().Typ != itemNewLine { - return nil, it.Item().Errorf("Expected new line after field declaration. Got %v", it.Item().Val) + return nil, it.Item().Errorf("Expected new line after field declaration. Got %v", + it.Item().Val) } + + glog.Warningf("Type declaration for type %s includes deprecated information about field type "+ + "for field %s which will be ignored.", typeName, field.Predicate) return field, nil } +func getType(typeName string) pb.Posting_ValType { + typ, ok := types.TypeForName(strings.ToLower(typeName)) + if ok { + return pb.Posting_ValType(typ) + } + + return pb.Posting_OBJECT +} + // ParsedSchema represents the parsed schema and type updates. type ParsedSchema struct { Preds []*pb.SchemaUpdate diff --git a/schema/parse_test.go b/schema/parse_test.go index 32920f0bb21..dfdc5cffa71 100644 --- a/schema/parse_test.go +++ b/schema/parse_test.go @@ -480,6 +480,56 @@ func TestParseTypeDuplicateFields(t *testing.T) { require.Contains(t, err.Error(), "Duplicate fields with name: name") } +func TestOldTypeFormat(t *testing.T) { + reset() + result, err := Parse(` + type Person { + name: [string!]! + address: string! + children: [Person] + } + `) + require.NoError(t, err) + require.Equal(t, 1, len(result.Types)) + require.Equal(t, &pb.TypeUpdate{ + TypeName: "Person", + Fields: []*pb.SchemaUpdate{ + { + Predicate: "name", + }, + { + Predicate: "address", + }, + { + Predicate: "children", + }, + }, + }, result.Types[0]) +} + +func TestOldAndNewTypeFormat(t *testing.T) { + reset() + result, err := Parse(` + type Person { + name: [string!]! + address + } + `) + require.NoError(t, err) + require.Equal(t, 1, len(result.Types)) + require.Equal(t, &pb.TypeUpdate{ + TypeName: "Person", + Fields: []*pb.SchemaUpdate{ + { + Predicate: "name", + }, + { + Predicate: "address", + }, + }, + }, result.Types[0]) +} + func TestParseTypeErrMissingNewLine(t *testing.T) { reset() _, err := Parse(`