fsprojects / FSharp.Data.GraphQL

FSharp implementation of Facebook GraphQL query language.
http://fsprojects.github.io/FSharp.Data.GraphQL/
MIT License
399 stars 73 forks source link

Simplify Giraffe boilerplate? #335

Open cmeeren opened 3 years ago

cmeeren commented 3 years ago

Based on the Star Wars sample, it seems that there is quite a lot of boilerplate that would be needed in any GraphQL API. Only Schema.fs contains the "interesting" domain-specific code and schema; the rest of the files seem to be something that could be entirely automated and would be identical for all services.

Is there a way to avoid the boilerplate?

I just came across Graphscriber, but that seems to only use websockets, and I'm not sure I want that since it could be troublesome for (downtime-free) blue-green deployments.

jberzy commented 3 years ago

Hi @cmeeren ,

I've actually been working on that the last few days.

The Program file is pretty reasonable now.

There are a couple things remaining such as WebSocket support, but If you want to give it a go and provide some feedback you can checkout the myget feed below.

https://www.myget.org/feed/fsharp-data-graphql/package/nuget/FSharp.Data.GraphQL.Server.AspNet

Thanks, Johnn

cmeeren commented 3 years ago

Excellent, thanks! I'll check it out.

cmeeren commented 3 years ago

Doesn't work for me. I get this exception from the library.

[08:14:36.104 ERR] Unhandled exception while executing request
System.AggregateException: One or more errors occurred. (The specified type FSharp.Data.GraphQL.Execution+NameValueLookup must derive from the specific value's type Microsoft.FSharp.Collections.FSharpMap`2[System.String,System.Object].)
 ---> System.ArgumentException: The specified type FSharp.Data.GraphQL.Execution+NameValueLookup must derive from the specific value's type Microsoft.FSharp.Collections.FSharpMap`2[System.String,System.Object].
   at void System.Text.Json.ThrowHelper.ThrowArgumentException_DeserializeWrongType(Type type, object value)
   at void System.Text.Json.JsonSerializer.Serialize(Utf8JsonWriter writer, object value, Type inputType, JsonSerializerOptions options)
   at void FSharp.Data.GraphQL.Server.AspNet.Json+GQLResponseConverter.Write(Utf8JsonWriter writer, GQLResponse value, JsonSerializerOptions options)
   at bool System.Text.Json.Serialization.JsonConverter<T>.TryWrite(Utf8JsonWriter writer, in T value, JsonSerializerOptions options, ref WriteStack state)
   at bool System.Text.Json.Serialization.JsonConverter<T>.WriteCore(Utf8JsonWriter writer, in T value, JsonSerializerOptions options, ref WriteStack state)
   at bool System.Text.Json.JsonSerializer.WriteCore<TValue>(JsonConverter jsonConverter, Utf8JsonWriter writer, in TValue value, JsonSerializerOptions options, ref WriteStack state)
   at async Task System.Text.Json.JsonSerializer.WriteAsyncCore<TValue>(Stream utf8Json, TValue value, Type inputType, JsonSerializerOptions options, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at async Task Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)
   at Step<Unit> Giraffe.Middleware+Invoke@63-6.Invoke(Unit unitVar0)
   at Step<a> FSharp.Control.Tasks.TaskBuilder.tryWith<a>(FSharpFunc<Unit, Step<a>> step, FSharpFunc<Exception, Step<a>> catch)
jberzy commented 3 years ago

@cmeeren,

Do you have more info on how I can repro that?

Thanks, John

cmeeren commented 3 years ago

Unfortunately not; this was when experimenting with an existing project with proprietary code. I can't prioritize making a minimal repro right now. Currently testing out various GraphQL frameworks. If I get back to FSharp.Data.GraphQL, I'll revisit this.