Automatically encode and decode input arguments?

Open
#236 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
fsharp, graphql
Domain
api, backend

Research direction

Review the current Define.Input and ResolveFieldContext.TryArg usage shown in the issue before assessing a typed argument approach. The work would need a defined way to encode and decode a record such as CreateUserArgs, with completion demonstrated by accessing fname and lname through the proposed mechanism.

Written by the indexing model from the issue text.

Description

Looking quickly at how to accept incoming params, is there a current way that allows defining something more global. Currently that's how it's done:

let createUserArgs: InputFieldDef list = 
    [ Define.Input("fname", String); Define.Input("lname", String); ]

let createUser(ctx: ResolveFieldContext) =
        let name = ctx.TryArg("fname")
        match name with
                | Some n ->
                    // ok...
                | None ->
                    // failhere...

Now I was wondering if there is another way say we could have something like this which could potentially automatically encode the input params and decode them as well ? Something like this perhaps:

type CreateUserArgs = {
    fname: string
    lname: string
}


let createUser(ctx: ResolveFieldContext) =
        let allArgsInput = ctx.getAllArgs<CreateUserArgs >()
        // At this point the system would know about allArgsInput.fname and allArgsInput.lname      
Dominant language
F#
Stars
406
Forks
74
Avg merge
1d 8h
Merged PRs (30d)
14

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fsprojects/FSharp.Data.GraphQL

All issues in fsprojects/FSharp.Data.GraphQL

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.