Skip to content

Commit

Permalink
fix(i): Remove default collection fields from gql view types (#2202)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
AndrewSisley authored Jan 12, 2024
1 parent 31a2988 commit bccf4e0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions request/graphql/schema/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/schema/default_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/view/one_to_many/with_introspection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/view/simple/with_introspection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit bccf4e0

Please sign in to comment.