Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(i): Remove default collection fields from gql view types #2202

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading