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

Views with transforms to not correctly handle related records #2999

Open
AndrewSisley opened this issue Sep 13, 2024 · 0 comments
Open

Views with transforms to not correctly handle related records #2999

AndrewSisley opened this issue Sep 13, 2024 · 0 comments
Labels
area/query Related to the query component bug Something isn't working

Comments

@AndrewSisley
Copy link
Contributor

The Lens node does not fully convert the output of a Lens transform to a core.Doc - it only converts the top level document, this means that inner documents cannot properly have post-view stuff done to them (e.g. aggregates, filters, etc).

This has mostly been fixed in #2951 /2951-cached-views (not yet merged), however some problems remain caused by stuff not expecting schema only definitions (e.g. the sum node).

E.g. the below test will fail on the last action (failure depends on branch):

func TestView_OneToManyWithTransformOnOuterAndSum(t *testing.T) {
	test := testUtils.TestCase{
		Actions: []any{
			testUtils.SchemaUpdate{
				Schema: `
					type Author {
						name: String
						books: [Book]
					}
					type Book {
						name: String
						author: Author
						pages: Int
					}
				`,
			},
			testUtils.CreateView{
				Query: `
					Author {
						name
						books {
							name
						}
					}
				`,
				SDL: `
					type AuthorView @materialized(if: false) {
						fullName: String
						books: [BookView]
					}
					interface BookView {
						name: String
						pages: Int
					}
				`,
				Transform: immutable.Some(model.Lens{
					// This transform will copy the value from `name` into the `fullName` field,
					// like an overly-complicated alias
					Lenses: []model.LensModule{
						{
							Path: lenses.CopyModulePath,
							Arguments: map[string]any{
								"src": "name",
								"dst": "fullName",
							},
						},
					},
				}),
			},
			testUtils.CreateDoc{
				CollectionID: 0,
				Doc: `{
					"name":	"Ferdowsi"
				}`,
			},
			testUtils.CreateDoc{
				CollectionID: 1,
				DocMap: map[string]any{
					"name":   "Shahnameh",
					"author": testUtils.NewDocIndex(0, 0),
					"pages":  10,
				},
			},
			testUtils.Request{
				Request: `
					query {
						AuthorView {
							fullName
							_sum(books: {field: pages})
						}
					}
				`,
				Results: map[string]any{
					"AuthorView": []map[string]any{
						{
							"fullName": "Ferdowsi",
							"_sum":     10,
						},
					},
				},
			},
		},
	}

	testUtils.ExecuteTestCase(t, test)
}

Please do not pick this up until after #2951 is merged, as a lot of the problem has been solved and the code rewritten.

@AndrewSisley AndrewSisley added bug Something isn't working area/query Related to the query component labels Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/query Related to the query component bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant