hasura / hasura/graphql-engine
Data Connectors: change query type to a union of ObjectQuery and ArrayQuery
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Is your proposal related to a problem?
Data connector data types are an important part of the spec and any implementation.
This is a proposal to change the `Query` type to better reflect the realities of how it is used.
The query type may be used to represent either a top-level query, or a subquery corresponding to a relationship.
The proposal is to change this type to a tagged union with two variants, one for objects and one for arrays.
These would be applicable at both the relationship level and the root level.
### Describe the solution you'd like
The new proposed type looks like this:
```ts
type Query = ObjectQuery | ArrayQuery;
type ArrayQuery = {
type: 'array';
aggregates?: Record | null;
fields?: Record | null;
limit?: number | null;
offset?: number | null;
order_by?: OrderBy;
where?: Expression;
};
type ObjectQuery = {
type: 'object';
fields?: Record | null;
where?: Expression;
};
```
Effectively, this brings the type in-line with the reality of how the types are used.
It also eliminates a vector for either undefined behavior or errors once parsed: the current typing suggests that object relationships can have `limit`, `offset`, and `order_by` properties, and the behavior if those are provided is unclear.
This typing update would reject such queries.
Contributor guide
Research direction
No file or test is named in the issue. Start by locating the Data Connectors Query type and its usages, then inspect how root and relationship queries are represented. Done means Query uses the proposed ObjectQuery | ArrayQuery variants and object queries no longer admit array-only properties such as limit, offset, or order_by.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend-api-design
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100