-
Notifications
You must be signed in to change notification settings - Fork 26
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
Added generation GraphQLClient.fsi #49
Conversation
src/CodeGen.fs
Outdated
let options = | ||
let options' = JsonSerializerOptions() | ||
options'.Converters.Add(JsonFSharpConverter()) | ||
options' | ||
{clientName}(url, new HttpClient(), options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change to the following:
let options = JsonSerializerOptions()
options.Converters.Add(JsonFSharpConverter())
{clientName}(url, new HttpClient(), options)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Zaid-Ajaj updated
0ddabea
to
dfe260b
Compare
type {clientName} = | ||
class | ||
/// <summary>Creates {clientName}</summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// <summary>Creates {clientName}</summary> | |
/// <summary>Creates {clientName} specifying <see href="T:HttpClient">HttpClient</see> instance</summary> |
src/CodeGen.fs
Outdated
/// <see href="T:Fable.Remoting.Json.FableJsonConverter">FableJsonConverter</see> | ||
/// from <a href="https://github.com/Zaid-Ajaj/Fable.SimpleJson">Fable.SimpleJson</a> NuGet package |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// In order to enable all F# types serialization and deserealization you must add | |
/// <see href="T:Fable.Remoting.Json.FableJsonConverter">FableJsonConverter</see> | |
/// from <a href="https://github.com/Zaid-Ajaj/Fable.SimpleJson">Fable.SimpleJson</a> NuGet package | |
/// In order to enable all F# types serialization and deserealization | |
/// <see href="T:Fable.Remoting.Json.FableJsonConverter">FableJsonConverter</see> is added | |
/// from <a href="https://github.com/Zaid-Ajaj/Fable.SimpleJson">Fable.SimpleJson</a> NuGet package |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These remarks are not entirely correct, the type FableJsonConverter
from Fable.Remoting.Json
is not from Fable.SimpleJson
.
- Fable.Remoting.Json is a F# JSON converter running on dotnet
- Fable.SimpleJson is F# JSON converter running with Fable
src/CodeGen.fs
Outdated
/// </remarks> | ||
/// <param name="url">GraphQL endpoint URL</param> | ||
new: url: string * client: HttpClient -> SpotifyGraphqlClient new: string * HttpClient * JsonSerializerOptions -> SpotifyGraphqlClient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new: url: string * client: HttpClient -> SpotifyGraphqlClient new: string * HttpClient * JsonSerializerOptions -> SpotifyGraphqlClient | |
new: url: string * client: HttpClient -> SpotifyGraphqlClient | |
/// <summary>Creates {clientName}</summary> | |
/// <remarks> | |
/// In order to enable all F# types serialization and deserealization | |
/// <see href="T:Fable.Remoting.Json.FableJsonConverter">FableJsonConverter</see> is added | |
/// from <a href="https://github.com/Zaid-Ajaj/Fable.SimpleJson">Fable.SimpleJson</a> NuGet package | |
/// </remarks> | |
new: url: string -> SpotifyGraphqlClient |
src/CodeGen.fs
Outdated
type {clientName} = | ||
class | ||
/// <summary>Creates {clientName}</summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// <summary>Creates {clientName}</summary> | |
/// <summary> | |
/// Creates {clientName} specifying <see href="T:HttpClient">HttpClient</see> instance | |
/// and <see href="T:JsonSerializerOptions">JsonSerializerOptions</see> | |
/// </summary> |
src/CodeGen.fs
Outdated
new(url: string, options: JsonSerializerOptions) = {clientName}(url, new HttpClient(), options) | ||
new(url: string) = {clientName}(url, new HttpClient(), new JsonSerializerOptions()) | ||
new(url: string)= | ||
let options = JsonSerializerOptions() | ||
options.Converters.Add(JsonFSharpConverter()) | ||
{clientName}(url, new HttpClient(), options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new(url: string, options: JsonSerializerOptions) = {clientName}(url, new HttpClient(), options) | |
new(url: string) = {clientName}(url, new HttpClient(), new JsonSerializerOptions()) | |
new(url: string)= | |
let options = JsonSerializerOptions() | |
options.Converters.Add(JsonFSharpConverter()) | |
{clientName}(url, new HttpClient(), options) | |
new(url: string, options: JsonSerializerOptions) = {clientName}(url, new HttpClient(), options) | |
new(url: string, client: HttpClient) = | |
let options = JsonSerializerOptions() | |
options.Converters.Add(JsonFSharpConverter()) | |
{clientName}(url, client, options) | |
new(url: string) = {clientName}(url, new HttpClient()) |
src/CodeGen.fs
Outdated
/// </remarks> | ||
/// <param name="url">GraphQL endpoint URL</param> | ||
new: url: string * client: HttpClient * options: JsonSerializerOptions -> SpotifyGraphqlClient new: string * HttpClient * JsonSerializerOptions -> SpotifyGraphqlClient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new: url: string * client: HttpClient * options: JsonSerializerOptions -> SpotifyGraphqlClient new: string * HttpClient * JsonSerializerOptions -> SpotifyGraphqlClient | |
new: url: string * client: HttpClient * options: JsonSerializerOptions -> SpotifyGraphqlClient | |
/// <summary> | |
/// Creates {clientName} specifying <see href="T:JsonSerializerOptions">JsonSerializerOptions</see> | |
/// </summary> | |
/// <param name="url">GraphQL endpoint URL</param> | |
/// <remarks> | |
/// In order to enable all F# types serialization and deserealization <b>you must</b> add | |
/// <see href="T:System.Text.Json.Serialization.JsonFSharpConverter">JsonFSharpConverter</see> | |
/// from <a href="https://github.com/Tarmil/FSharp.SystemTextJson">FSharp.SystemTextJson</a> NuGet package yourself | |
/// </remarks> | |
new: url: string * options: JsonSerializerOptions -> SpotifyGraphqlClient | |
/// <summary> | |
/// Creates {clientName} specifying <see href="T:HttpClient">HttpClient</see> instance | |
/// </summary> | |
/// <param name="url">GraphQL endpoint URL</param> | |
/// <remarks> | |
/// In order to enable all F# types serialization and deserealization | |
/// <see href="T:System.Text.Json.Serialization.JsonFSharpConverter">JsonFSharpConverter</see> by default is added | |
/// from <a href="https://github.com/Tarmil/FSharp.SystemTextJson">FSharp.SystemTextJson</a> NuGet package | |
/// </remarks> | |
new: url: string * client: HttpClient -> SpotifyGraphqlClient | |
/// <summary>Creates {clientName}</summary> | |
/// <param name="url">GraphQL endpoint URL</param> | |
/// <remarks> | |
/// In order to enable all F# types serialization and deserealization | |
/// <see href="T:System.Text.Json.Serialization.JsonFSharpConverter">JsonFSharpConverter</see> by default is added | |
/// from <a href="https://github.com/Tarmil/FSharp.SystemTextJson">FSharp.SystemTextJson</a> NuGet package | |
/// </remarks> | |
new: url: string -> SpotifyGraphqlClient |
src/CodeGen.fs
Outdated
/// <see href="T:System.Text.Json.Serialization.JsonFSharpConverter">JsonFSharpConverter</see> | ||
/// from <a href="https://github.com/Tarmil/FSharp.SystemTextJson">FSharp.SystemTextJson</a> NuGet package |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// In order to enable all F# types serialization and deserealization you must add | |
/// <see href="T:System.Text.Json.Serialization.JsonFSharpConverter">JsonFSharpConverter</see> | |
/// from <a href="https://github.com/Tarmil/FSharp.SystemTextJson">FSharp.SystemTextJson</a> NuGet package | |
/// In order to enable all F# types serialization and deserealization <b>you must</b> add | |
/// <see href="T:System.Text.Json.Serialization.JsonFSharpConverter">JsonFSharpConverter</see> | |
/// from <a href="https://github.com/Tarmil/FSharp.SystemTextJson">FSharp.SystemTextJson</a> NuGet package yourself |
src/CodeGen.fs
Outdated
class | ||
/// <summary>Creates {clientName}</summary> | ||
/// <remarks> | ||
/// In order to enable all F# types serialization and deserealization you must add | ||
/// <see href="T:Fable.Remoting.Json.FableJsonConverter">FableJsonConverter</see> | ||
/// from <a href="https://github.com/Zaid-Ajaj/Fable.SimpleJson">Fable.SimpleJson</a> NuGet package | ||
/// </remarks> | ||
/// <param name="url">GraphQL endpoint URL</param> | ||
new: url: string * client: HttpClient * options: JsonSerializerOptions -> SpotifyGraphqlClient new: string * HttpClient * JsonSerializerOptions -> SpotifyGraphqlClient | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Analogical to previous
dfe260b
to
f23c7a9
Compare
src/Program.fs
Outdated
colorprintfn "✏️ Generating GraphQL client $green[%s]" graphqlClientPath | ||
generatedFiles.Add(graphqlClientPath) | ||
generatedFiles.AddRange([| graphqlClientPath; graphqlClientFsiPath|]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the fsi file must be compiled before the the actual implementation file:
generatedFiles.AddRange [|
graphqlClientFsiPath
graphqlClientPath
|]
src/Program.fs
Outdated
seq { | ||
MSBuildXElement.Compile($".\{config.project}.GraphqlClient.fs") | ||
MSBuildXElement.Compile($".\{config.project}.GraphqlClient.fsi") | ||
} | ||
else | ||
seq { | ||
MSBuildXElement.Compile($".\{outputDirectoryName}\\dotnet\{config.project}.GraphqlClient.fs") | ||
MSBuildXElement.Compile($".\{outputDirectoryName}\\dotnet\{config.project}.GraphqlClient.fsi") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, the fsi
definition comes before the implementation
| SerializerType.Newtonsoft -> sampleFSharpNewtonsoftGraphqlClient projectName clientName errorType members | ||
|
||
let sampleFableGraphqlClientFsi projectName clientName = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is implemented incorrectly, Fable fsi implementation doesn't use any of Newtonsoft.Json
, Fable.Remoting.Json
, System.Net.Http
and definitely no HttpClient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Zaid-Ajaj updated
8fc4e93
to
aeb9b29
Compare
aeb9b29
to
fd8d5a8
Compare
@Zaid-Ajaj can I use FusionTasks NuGet to simplify code?
|
@xperiandri task is already included when asyncReturnType: "task" in which case the Ply package is included |
You mean you want to use FusionTasks to simplify the async implementation? I don't really think adding a dependency just for Async.AwaitTask is worth it. If you need FusionTasks in your application, why not simply add it in your project that references the generated Snowflaqe client? |
It worse because now we have 2 generator functions everywhere async/task appear which complecates the code a lot and adds more chances for mistake |
I agree it is a bit complicated but it makes the result nicer for users who want Task<'T> as the output of the client function, not just for simplifying the implementation details. I think implementing error handling option from #29 will be the last hurdle and it's still doable IMO Do you have any other features might be impacted because of the task/option? |
I don't know why could people not use https://www.nuget.org/packages/FSharp.Control.FusionTasks/2.2.0 |
The same as manually calling |
Users of Snowflaqe don't have to call Sticking with |
One of the reasons I made the task change was that 'fits' more when the actual 'async' functionality is using tasks anyway (i.e. HttpClient and the Json libs are task based), but then I was also having a go at inserting the generated lib into an existing C# stack and the tasks returned from Ply just work directly there which is nice for interop. (I'm a massive beginner with F# and had never heard of FusionTasks, but it looks to me like |
Hi @anthony-mi what's the status of this PR? Any plans to continue working on? @xperiandri if there are issues or discussions outside of this PR, please consider opening a separate issue to discuss it there |
@Zaid-Ajaj Anthony decided to exit from the project. The other developer will pick up the work in several weeks. |
Thanks for the update @xperiandri does this mean this PR can closed to start all over later on or should I keep it open for now? |
Keep it open for now. I will let you know |
@Zaid-Ajaj we have discovered that in order to have FSI we need to declare all public members within it too |
So that we think of removing FSI and rewriting the client class without the default constructor |
Sounds like a good idea for now. Proper FSI support can be added in another PR |
We will have a look closer soon. Removing FSI looks easier to implement an maintain for now |
No description provided.