graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

F# Support

Open michaelstaib opened this issue 3 years ago • 14 comments

This PR represents the initial work to determine what we need to make this a great API for F#.

In this initial PR we will re-create the StarWars example with F# and write some F# unit tests to see where the pain points are.

Todo:

  • [ ] F# StarWars
  • [ ] F# Integration Tests
  • [ ] F# Union Support

https://github.com/adelarsq/hotchocolate_fsharp_sample

michaelstaib avatar May 06 '21 18:05 michaelstaib

Is it possible to represent non-nullable GraphQL type by F# record? now I can do nullable type by this method:

[<ReferenceEquality>]
type Author = { Name: string }

[<ReferenceEquality>]
type Book = { Title: string; Author: Author }

type Query() =
    member this.Book() =
        { Title = "F#"
          Author = { Name = "Jon" } }

type Mutation() =
    member this.CreateBook() =
        { Title = "F#"
          Author = { Name = "Jon" } }

sep2 avatar May 10 '21 14:05 sep2

Never mind, I found this [<GraphQLNonNullType>] attribute is exactly what I want.

sep2 avatar May 10 '21 15:05 sep2

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

sonarcloud[bot] avatar Jun 01 '21 04:06 sonarcloud[bot]

Hi @michaelstaib F# support with HotChocolate would be awesome! I will be looking forward to testing it out with Snowflaqe 🙏

Zaid-Ajaj avatar Jun 21 '21 10:06 Zaid-Ajaj

Hello @michaelstaib. Are we expecting this in Sept. milestone? What would it include in terms of F# support?

geekox86 avatar Sep 19 '21 06:09 geekox86

This is a bit cumbersome in F#:

type Query() =
    member this.Book() =
        { Title = "F#"
          Author = { Name = "Jon" } }

type Mutation() =
    member this.CreateBook() =
        { Title = "F#"
          Author = { Name = "Jon" } }

There is no partial classes, it gets awkward. Secondly these classes feel redundant, especially in F#. Mutation functions usually are not dependent on each other by state, so they shouldn't share class anyway.

I'd prefer in F# if we could define mutations and queries like functions. If it's possible, by allowing somehow to annotate functions with "Mutation":

[<Mutation>]
let createBook book (appDbContext: AppDbContext) =
    appDbContext.Books.Add(book) |> ignore
    appDbContext.SaveChanges()
    // ... 

[<Query>]
[<UsePaging>]
[<UseProjection>]
[<UseFiltering>]
[<UseSorting>]
let getBooks ([<Service>] dbContext: AppDbContext) =
    dbContext.Books

Ciantic avatar Nov 18 '21 20:11 Ciantic

@Ciantic are there global functions in F# or are they always members of a class or struct?

michaelstaib avatar Nov 19 '21 22:11 michaelstaib

OK, looked at it ... seems to work ... I can probably put something into one of the next builds ... I think with this kind of function it can also become quite nice to create schema first and define resolvers... have to play a bit with it

michaelstaib avatar Nov 19 '21 22:11 michaelstaib

It's notable that in F# the functions are usually defined in curried form, which also requires support in the HotChocolate to work well. Like input -> AppDbContext -> PersonPayload I also started my simple example repo here:

https://github.com/Ciantic/TestGraphQLWithFsharp/blob/master/Program.fs

Ciantic avatar Nov 20 '21 20:11 Ciantic

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 04 '22 00:05 stale[bot]

I'm sure there's plenty of people who wouldn't want this closed?

mika76 avatar May 04 '22 06:05 mika76

I am interested on this too.

adelarsq avatar May 04 '22 19:05 adelarsq

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 03 '22 21:07 stale[bot]

@michaelstaib Please mark this as not stale

ss-proc avatar Jul 03 '22 21:07 ss-proc

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

:white_check_mark: michaelstaib
:x: wonbyte
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Aug 17 '22 14:08 CLAassistant

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 15 '22 14:12 stale[bot]

was this PR forgotten?

mika76 avatar Dec 15 '22 15:12 mika76

I am closing this PR as we have a newer one #5595.

michaelstaib avatar Dec 19 '22 22:12 michaelstaib