From bccf4e019babcb85be059813f0ca9eb66884ab55 Mon Sep 17 00:00:00 2001 From: AndrewSisley Date: Fri, 12 Jan 2024 12:57:06 -0500 Subject: [PATCH] fix(i): Remove default collection fields from gql view types (#2202) ## Relevant issue(s) Resolves #2199 ## Description Removes default collection fields from gql view types. Views should not automatically have these fields. It will also be impossible to guarantee that they exist once we allow Views to have Lens transforms. --- request/graphql/schema/generate.go | 5 +++-- tests/integration/schema/default_fields.go | 6 +++--- .../integration/view/one_to_many/with_introspection_test.go | 4 ++-- tests/integration/view/simple/with_introspection_test.go | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/request/graphql/schema/generate.go b/request/graphql/schema/generate.go index 87efcbd56e..1083772d58 100644 --- a/request/graphql/schema/generate.go +++ b/request/graphql/schema/generate.go @@ -417,6 +417,7 @@ func (g *Generator) buildTypes( collection := c fieldDescriptions := collection.Schema.Fields isEmbeddedObject := collection.Description.Name == "" + isViewObject := isEmbeddedObject || collection.Description.BaseQuery != nil var objectName string if isEmbeddedObject { @@ -441,7 +442,7 @@ func (g *Generator) buildTypes( fieldsThunk := (gql.FieldsThunk)(func() (gql.Fields, error) { fields := gql.Fields{} - if !isEmbeddedObject { + if !isViewObject { // automatically add the _docID: ID field to the type fields[request.DocIDFieldName] = &gql.Field{ Description: docIDFieldDescription, @@ -495,7 +496,7 @@ func (g *Generator) buildTypes( Type: gql.NewList(gqlType), } - if !isEmbeddedObject { + if !isViewObject { // add _version field fields[request.VersionFieldName] = &gql.Field{ Description: versionFieldDescription, diff --git a/tests/integration/schema/default_fields.go b/tests/integration/schema/default_fields.go index 97671738fb..23f1697938 100644 --- a/tests/integration/schema/default_fields.go +++ b/tests/integration/schema/default_fields.go @@ -70,9 +70,9 @@ var DefaultFields = concat( aggregateFields, ) -// DefaultEmbeddedObjFields contains the list of fields every -// defra embedded-object should have. -var DefaultEmbeddedObjFields = concat( +// DefaultViewObjFields contains the list of fields every +// defra view-object should have. +var DefaultViewObjFields = concat( fields{ groupField, }, diff --git a/tests/integration/view/one_to_many/with_introspection_test.go b/tests/integration/view/one_to_many/with_introspection_test.go index 895ed03fcb..8a8eeeb12d 100644 --- a/tests/integration/view/one_to_many/with_introspection_test.go +++ b/tests/integration/view/one_to_many/with_introspection_test.go @@ -70,7 +70,7 @@ func TestView_OneToMany_GQLIntrospectionTest(t *testing.T) { ExpectedData: map[string]any{ "__type": map[string]any{ "name": "AuthorView", - "fields": schema.DefaultFields.Append( + "fields": schema.DefaultViewObjFields.Append( schema.Field{ "name": "name", "type": map[string]any{ @@ -112,7 +112,7 @@ func TestView_OneToMany_GQLIntrospectionTest(t *testing.T) { // although aggregates and `_group` should be. // There should also be no `Author` field - the relationship field // should only exist on the parent. - "fields": schema.DefaultEmbeddedObjFields.Append( + "fields": schema.DefaultViewObjFields.Append( schema.Field{ "name": "name", "type": map[string]any{ diff --git a/tests/integration/view/simple/with_introspection_test.go b/tests/integration/view/simple/with_introspection_test.go index ada7d2cfcd..c8c45b9e8a 100644 --- a/tests/integration/view/simple/with_introspection_test.go +++ b/tests/integration/view/simple/with_introspection_test.go @@ -58,7 +58,7 @@ func TestView_Simple_GQLIntrospectionTest(t *testing.T) { ExpectedData: map[string]any{ "__type": map[string]any{ "name": "UserView", - "fields": schema.DefaultFields.Append( + "fields": schema.DefaultViewObjFields.Append( schema.Field{ "name": "name", "type": map[string]any{