-
Notifications
You must be signed in to change notification settings - Fork 13
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
Can't wrap the Query calls in another method. #69
Comments
I tried something similar with the QueryInfoProvider. But you have to fetch the CallerArgumentExpression in the wrapper method else it will not work:
Also the queryKey is never set at runtime, it's important at compile time as the SourceGenerator from ZeroQL analyzes to build the query string and the query store. And retrieve the correct query string at runtime. Edit: But it didn't worked out nicely. So i resorted to create an extension method which returned custom client with the IHttpHandler
|
Theoretically, there is a way to make it work. It would require changes in analyzer and it would not look nice. public async Task<GraphQLResult<TQueryResult>> QueryAsync<TQueryResult>(string operationName, [GraphQLLambda]Func<Query, TQueryResult> query, [CallerArgumentExpression(nameof(query))] string queryKey = null!)
{
var gqlClient = // .. make generated client with our IHttpHandler
// do other things we need
var res = await gqlClient.Query(operationName, query, queryKey);
return res;
} and I have a feeling that such implementation would definitely get some sort of unknown WTF. |
It would already help if there is a way that the analyzers capture classes implementing an interface provided by ZeroQL so libraries could implement it and read the query body from the QueryInfoProvider instead of using the generated ZeroQL client. Would have also the nice side effect to get the tooltips with the compiled query. This would also ensure that the necessary functionality is supported like variable capturing etc. |
Hmm.. Potentially the interface can be even a better way to implement it. I will have a look. |
Checkout v7.0.0-.preview.1. Now it is possible to create wrappers around generated ZeroQL client. Here example:
Basically new implementation depends on |
Describe the bug
Can't wrap the Query calls in another method.
How to Reproduce
We're trying to replace an existing implementation and wanted to limit the changes across the code base. So we have the following
The
await gqlClient.Query(operationName, query);
gives the following errorExpected behavior
Clearly a Source Generator issue, but I'm not sure if it is a limitation of Source Generators or if it could be supported. If it is a limitation of Source Generators then you can close this. Otherwise it would be good to support this.
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: