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

Schema View: using view created earlier in a new view SDL doesn't work #2219

Closed
islamaliev opened this issue Jan 15, 2024 · 2 comments
Closed
Labels
area/query Related to the query component area/schema Related to the schema system bug Something isn't working

Comments

@islamaliev
Copy link
Contributor

func TestView_UseViewInAnotherViewQuery(t *testing.T) {
	test := testUtils.TestCase{
		Description: "One to many view with alias on inner object",
		Actions: []any{
			testUtils.SchemaUpdate{
				Schema: `
					type Book {
						name: String
						rating: Float
						author: Author
					}
					type Author {
						name: String
						age: Int
						verified: Boolean
						wrote: [Book]
					}
				`,
			},
			testUtils.CreateDoc{
				CollectionID: 1,
				Doc: `{
					"name":	"Andy"
				}`,
			},
			testUtils.CreateDoc{
				CollectionID: 0,
				Doc: `{
					"name":	"Andy's book",
					"author_id": "bae-2159860f-3cd1-59de-9440-71331e77cbb8"
				}`,
			},
			testUtils.CreateView{
				Query: `
					Book {
						name
						author {
							name
							wrote {
								name
							}
						}
					}
				`,
				SDL: `
					type BookView {
						name: String
						author: AuthorView
					}
					interface AuthorView {
						name: String
						wrote: [BookView]
					}
				`,
			},
			testUtils.CreateView{
				Query: `
					Author {
						name
						wrote {
							name
						}
					}
				`,
				SDL: `
					type AuthorView2 {
						name: String
						wrote: [BookView]
					}
				`,
			},
			testUtils.Request{
				Request: `
					query {
						AuthorView2 {
							name
							wrote {
								name
							}
						}
					}
				`,
				Results: []map[string]any{
					{
						"name": "Andy",
						"wrote": map[string]any{
							"name": "Andy's book",
						},
					},
				},
			},
		},
	}

	testUtils.ExecuteTestCase(t, test)
}

This produces error relation must be defined on both schemas. Field: wrote, Type: BookView.
It seems like it doesn't see the view created on the first action.
But if we change the SDL of the second CreateView action to this:

				SDL: `
					type AuthorView {
						name: String
						wrote: [BookView2]
					}
					type BookView2 {
						name: String
						author: AuthorView
					}
				`,

it produces error schema type already exists. Name: AuthorView. which means it sees it after all.

I think the interfaces should be

  • either local to the view so that other views can create types or interfaces with the same name
  • or should be visible to all views, hence reusable by other views
@islamaliev islamaliev added bug Something isn't working area/query Related to the query component area/schema Related to the schema system labels Jan 15, 2024
@AndrewSisley
Copy link
Contributor

This produces error relation must be defined on both schemas. Field: wrote, Type: BookView.

This is correct behaviour. And is the same as you'd get in normal collections when only defining half a relation.

@AndrewSisley
Copy link
Contributor

it produces error schema type already exists. Name: AuthorView. which means it sees it after all.

This is because AuthorView was already created in the first SDL, and you are trying to re-define it. This also is the same behaviour as in normal collections.

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 area/schema Related to the schema system bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants