Description
When used with the react-query client, I would like an option in the orval configuration file to configure explicitly what prefix to use for factories.
Current behavior
If I use orval with react-query client, it internally determines whether to use a use or get prefix based on the presence of a custom query options factory:
const queryOptionsFnName = camel(
queryKeyMutator || queryOptionsMutator || mutator?.isHook
? `use-${name}-queryOptions`
: `get-${name}-queryOptions`,
);
However, the use prefix is sometimes undesirable for query options, since the function may have to be used outside react (router loaders for example, with ensureQueryData or prefetchQuery). You can use it anyway of course but:
- It would be confusing in any react codebase
- If you have certain eslint rules configured, you may have to disable the rule about React functions
Proposed behavior
Orval should let the user decide what prefix to use (if any) for query options factories, and possibly for query keys factories as well.
Proposed solution
The default automatic prefix could detect whether the mutators are hooks or not:
const queryOptionsFnName = camel(
queryKeyMutator?.isHook || queryOptionsMutator?.isHook || mutator?.isHook
? `use-${name}-queryOptions`
: `get-${name}-queryOptions`,
);
Moreover, we could introduce two new settings (queryKeyFactoryPrefix and queryOptionsFactoryPrefix, for example) that would live inside query. An empty prefix is sometimes desirable: my OpenAPI yaml files already prefix get operations with get, so with the default get prefix (assuming no mutators) it would result in a silly getGetActivitiesQueryOptions.
I am willing to put the work myself if you like the idea.
Description
When used with the
react-queryclient, I would like an option in the orval configuration file to configure explicitly what prefix to use for factories.Current behavior
If I use orval with
react-queryclient, it internally determines whether to use auseorgetprefix based on the presence of a custom query options factory:However, the
useprefix is sometimes undesirable for query options, since the function may have to be used outside react (router loaders for example, withensureQueryDataorprefetchQuery). You can use it anyway of course but:Proposed behavior
Orval should let the user decide what prefix to use (if any) for query options factories, and possibly for query keys factories as well.
Proposed solution
The default automatic prefix could detect whether the mutators are hooks or not:
Moreover, we could introduce two new settings (
queryKeyFactoryPrefixandqueryOptionsFactoryPrefix, for example) that would live insidequery. An empty prefix is sometimes desirable: my OpenAPI yaml files already prefix get operations withget, so with the defaultgetprefix (assuming no mutators) it would result in a sillygetGetActivitiesQueryOptions.I am willing to put the work myself if you like the idea.