Skip to content

Return errors from railway programming model #274

@xperiandri

Description

@xperiandri

Description

We use Chessie and resolver function returns a result. Then I want to unwrap that result and return value or errors as GraphQL response like this:

/// If Ok, returns value and sets messages as GraphQL operation errors
/// If Bad, returns value and sets errors as GraphQL operation errors
let handleMessages<'TSuccess,'TMessage> (ctx : ResolveFieldContext) (result : Result<'TSuccess,'TMessage>) : 'TSuccess =
    let setErrors messages =
        let ex = GraphQLException (ctx.ExecutionInfo.Identifier)
        messages |> Seq.iteri (fun m i -> ex.Data.Add (i, m))
        ctx.AddError ex
    match result with
    | Ok (value, messages) -> setErrors (messages); value
    | Bad messages -> setErrors (messages); Unchecked.defaultof<'TSuccess>

However as long as type is not nullable, returning null produces error.

Repro steps

  1. Create resolver that returns Result type of Chassie library
  2. Use my function to unwrap a result

Expected behavior

Ability to handle Result type and pass errors without raising an exception.

Actual behavior

nullResolverError is called and GraphQLException is returned

Known workarounds

Raise exception after resolver execution

Related information

  • FSharp.Data.GraphQL.Server 1.0.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions