Skip to content
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

Merged
merged 1 commit into from
Sep 30, 2021

Conversation

anthony-mi
Copy link
Contributor

No description provided.

src/CodeGen.fs Outdated
Comment on lines 1187 to 1189
let options =
let options' = JsonSerializerOptions()
options'.Converters.Add(JsonFSharpConverter())
options'
{clientName}(url, new HttpClient(), options)
Copy link
Owner

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)

Copy link
Contributor Author

@anthony-mi anthony-mi Jun 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Zaid-Ajaj updated

@anthony-mi anthony-mi force-pushed the FSharp_SystemTextJson branch from 0ddabea to dfe260b Compare June 17, 2021 20:05
type {clientName} =
class
/// <summary>Creates {clientName}</summary>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// <summary>Creates {clientName}</summary>
/// <summary>Creates {clientName} specifying <see href="T:HttpClient">HttpClient</see> instance</summary>

src/CodeGen.fs Outdated
Comment on lines 1232 to 1263
/// <see href="T:Fable.Remoting.Json.FableJsonConverter">FableJsonConverter</see>
/// from <a href="https://github.com/Zaid-Ajaj/Fable.SimpleJson">Fable.SimpleJson</a> NuGet package
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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

Copy link
Owner

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// <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
Comment on lines 1184 to 1189
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Comment on lines 1253 to 1305
/// <see href="T:System.Text.Json.Serialization.JsonFSharpConverter">JsonFSharpConverter</see>
/// from <a href="https://github.com/Tarmil/FSharp.SystemTextJson">FSharp.SystemTextJson</a> NuGet package
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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
Comment on lines 1270 to 1347
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Analogical to previous

@anthony-mi anthony-mi force-pushed the FSharp_SystemTextJson branch from dfe260b to f23c7a9 Compare June 17, 2021 23:05
src/Program.fs Outdated
colorprintfn "✏️ Generating GraphQL client $green[%s]" graphqlClientPath
generatedFiles.Add(graphqlClientPath)
generatedFiles.AddRange([| graphqlClientPath; graphqlClientFsiPath|])
Copy link
Owner

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
Comment on lines 613 to 630
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")
}
Copy link
Owner

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 =
Copy link
Owner

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Zaid-Ajaj updated

@anthony-mi anthony-mi force-pushed the FSharp_SystemTextJson branch 3 times, most recently from 8fc4e93 to aeb9b29 Compare June 18, 2021 20:05
@anthony-mi anthony-mi force-pushed the FSharp_SystemTextJson branch from aeb9b29 to fd8d5a8 Compare June 19, 2021 00:35
@xperiandri
Copy link
Contributor

@Zaid-Ajaj can I use FusionTasks NuGet to simplify code?

task computation expression does not require Async.AwaitTask, async computation expression requires it.
With FusionTasks we can use the same code and simplify generation

@Zaid-Ajaj
Copy link
Owner

@xperiandri task is already included when asyncReturnType: "task" in which case the Ply package is included

@xperiandri
Copy link
Contributor

@Zaid-Ajaj
Copy link
Owner

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?

@xperiandri
Copy link
Contributor

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

@Zaid-Ajaj
Copy link
Owner

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?

@xperiandri
Copy link
Contributor

I don't know why could people not use https://www.nuget.org/packages/FSharp.Control.FusionTasks/2.2.0
It is one of the first NuGet packages I install to any F# project. Adding Async.AwaitTask to every async .NET BCL call is crazy...

@xperiandri
Copy link
Contributor

The same as manually calling OnPropertyChanged instead of installing PropertyChanged.Fody and make it done automatically

@Zaid-Ajaj
Copy link
Owner

I don't know why could people not use https://www.nuget.org/packages/FSharp.Control.FusionTasks/2.2.0
It is one of the first NuGet packages I install to any F# project. Adding Async.AwaitTask to every async .NET BCL call is crazy...

Users of Snowflaqe don't have to call Async.AwaitTask, it is just the generated code. You can always install FusionTasks into your own projects whenever you need it.

Sticking with Ply for now as a dependency of the generated projects because it gives a nice task CE to work with when tasks are preferred.

@Numpsy
Copy link
Contributor

Numpsy commented Jun 21, 2021

Sticking with Ply for now as a dependency of the generated projects because it gives a nice task CE to work with when tasks are preferred.

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 task { } is going to end up part of FSharp Core at some point, at which point the issue and the requirement for 3rd party libs might just go away? (or maybe i'm being hopeful looking at how long that question has been running for!))

@Zaid-Ajaj
Copy link
Owner

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

@xperiandri
Copy link
Contributor

@Zaid-Ajaj Anthony decided to exit from the project. The other developer will pick up the work in several weeks.

@Zaid-Ajaj
Copy link
Owner

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?

@xperiandri
Copy link
Contributor

Keep it open for now. I will let you know

@Zaid-Ajaj Zaid-Ajaj merged commit fd8d5a8 into Zaid-Ajaj:master Sep 30, 2021
@xperiandri
Copy link
Contributor

@Zaid-Ajaj we have discovered that in order to have FSI we need to declare all public members within it too

@xperiandri
Copy link
Contributor

So that we think of removing FSI and rewriting the client class without the default constructor

@Zaid-Ajaj
Copy link
Owner

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

@xperiandri
Copy link
Contributor

We will have a look closer soon. Removing FSI looks easier to implement an maintain for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants