Issue
No typing for gqlFields
export const USER = 'user';
export interface UserEntity {
id: string;
firstName: string;
lastName: string;
}
export interface State extends EntityState<UserEntity> {
selectedId?: string;
loaded?: boolean;
error?: string;
}
export interface PartialState {
readonly [USER]: State;
}
export const getFeature = createFeatureSelector<PartialState, State>(USER);
export const selectRootUser = rootEntitySelector(getFeature);
export const getUser = selectRootUser({ gqlFields: [''] }); // !Missing suggestions for gqlFields!
Possible sulotion
Provide an ENTITY
declare global {
export interface SELECTOR_META<ENTITY = any> {
flatKey?: string;
gqlFields?: Array<keyof ENTITY>;
}
}
adjust rootEntitySelector.ts
by providing the ENTITY
to SELECTOR_META
=> SELECTOR_META<ENTITY>
.
This is how it might look after compilation:
import { FEATURE_SELECTOR, HANDLER_RELATED_ENTITY, HANDLER_ROOT_ENTITY, ID_TYPES, TRANSFORMER } from './types';
export declare function rootEntitySelector<STORE, ENTITY, TRANSFORMED>(featureSelector: FEATURE_SELECTOR<STORE, ENTITY>, transformer: TRANSFORMER<ENTITY, TRANSFORMED>, meta: SELECTOR_META<ENTITY>): (metaOrRelationship?: SELECTOR_META<ENTITY> | HANDLER_RELATED_ENTITY<STORE, ENTITY>, ...relationships: Array<HANDLER_RELATED_ENTITY<STORE, ENTITY>>) => HANDLER_ROOT_ENTITY<STORE, ENTITY, TRANSFORMED, ID_TYPES>;
export declare function rootEntitySelector<STORE, ENTITY, TRANSFORMED>(featureSelector: FEATURE_SELECTOR<STORE, ENTITY>, transformer: TRANSFORMER<ENTITY, TRANSFORMED>): (metaOrRelationship?: SELECTOR_META<ENTITY> | HANDLER_RELATED_ENTITY<STORE, ENTITY>, ...relationships: Array<HANDLER_RELATED_ENTITY<STORE, ENTITY>>) => HANDLER_ROOT_ENTITY<STORE, ENTITY, TRANSFORMED, ID_TYPES>;
export declare function rootEntitySelector<STORE, ENTITY>(featureSelector: FEATURE_SELECTOR<STORE, ENTITY>, meta: SELECTOR_META<ENTITY>): (metaOrRelationship?: SELECTOR_META<ENTITY> | HANDLER_RELATED_ENTITY<STORE, ENTITY>, ...relationships: Array<HANDLER_RELATED_ENTITY<STORE, ENTITY>>) => HANDLER_ROOT_ENTITY<STORE, ENTITY, ENTITY, ID_TYPES>;
export declare function rootEntitySelector<STORE, ENTITY>(featureSelector: FEATURE_SELECTOR<STORE, ENTITY>): (metaOrRelationship?: SELECTOR_META<ENTITY> | HANDLER_RELATED_ENTITY<STORE, ENTITY>, ...relationships: Array<HANDLER_RELATED_ENTITY<STORE, ENTITY>>) => HANDLER_ROOT_ENTITY<STORE, ENTITY, ENTITY, ID_TYPES>;
Profit and a happy developer:
![image](https://user-images.githubusercontent.com/16114644/116866461-bbc80e00-ac0b-11eb-86bf-e03492613da7.png)
We don't need to guess the entity props any more.
Use all entity props without providing'em all in gqlFields: ['id', '...']
Is it possible to make the gqlFields
little more dynamic? For example explicit with gqlFields: 'all'
or implicit if gqlFields
is not provided, all the entity props are used to generate a graphql query/mutation/subscription.
The only question is, how to handle nested props like:
interface User {
id: string;
firstName: string;
profile: Settings;
}
interface Settings {
theme: 'light' | 'dark';
permissions: Permission[];
// ...
}
interface Permission {
id: string;
name: string;
value: boolean;
Maybe it'd be even cooler with this approach like in prisma
export const getUser = selectRootUser({
gqlFields: { id: true, firstName: true, profile: { permissions: { value: true } },
});
would generate following graphql query
{
user {
id
firstName
profile {
permissions {
value
}
}
}
}