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

F# Support #3670

Closed
wants to merge 7 commits into from
Closed

F# Support #3670

wants to merge 7 commits into from

Conversation

michaelstaib
Copy link
Member

@michaelstaib michaelstaib commented May 6, 2021

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

@wonbyte wonbyte mentioned this pull request May 8, 2021
@wonbyte wonbyte linked an issue May 8, 2021 that may be closed by this pull request
@sep2
Copy link

sep2 commented May 10, 2021

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

sep2 commented May 10, 2021

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

@wonbyte wonbyte mentioned this pull request May 24, 2021
@sonarcloud
Copy link

sonarcloud bot commented Jun 1, 2021

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

@Zaid-Ajaj
Copy link

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

@michaelstaib michaelstaib modified the milestones: HC-2021-06, HC-2021-09 Jun 27, 2021
@geekox86
Copy link

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

@Ciantic
Copy link
Contributor

Ciantic commented Nov 18, 2021

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

@michaelstaib
Copy link
Member Author

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

@michaelstaib
Copy link
Member Author

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

@Ciantic
Copy link
Contributor

Ciantic commented Nov 20, 2021

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

@stale
Copy link

stale bot commented May 4, 2022

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 stale bot added the ⌛ stale Nothing happened with this issue in quite a while label May 4, 2022
@mika76
Copy link

mika76 commented May 4, 2022

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

@stale stale bot removed the ⌛ stale Nothing happened with this issue in quite a while label May 4, 2022
@adelarsq
Copy link
Contributor

adelarsq commented May 4, 2022

I am interested on this too.

@stale
Copy link

stale bot commented Jul 3, 2022

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 stale bot added the ⌛ stale Nothing happened with this issue in quite a while label Jul 3, 2022
@ss-proc
Copy link

ss-proc commented Jul 3, 2022

@michaelstaib Please mark this as not stale

@stale stale bot removed the ⌛ stale Nothing happened with this issue in quite a while label Jul 3, 2022
@CLAassistant
Copy link

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.

✅ michaelstaib
❌ wonbyte
You have signed the CLA already but the status is still pending? Let us recheck it.

@stale
Copy link

stale bot commented Dec 15, 2022

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 stale bot added the ⌛ stale Nothing happened with this issue in quite a while label Dec 15, 2022
@mika76
Copy link

mika76 commented Dec 15, 2022

was this PR forgotten?

@stale stale bot removed the ⌛ stale Nothing happened with this issue in quite a while label Dec 15, 2022
@michaelstaib
Copy link
Member Author

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

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

Successfully merging this pull request may close these issues.

F# Star Wars F# Record and Purecode First schema Generation F# discriminated union support
10 participants