question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Execution fails with NRE when using generic field definition

See original GitHub issue

Description

I’m defining model with a similar field in several types. E.g.

let WidgetsField name (getUser: ResolveFieldContext -> 'a -> User) =
    let resolve ctx xx =
        let user = getUser ctx xx 
        let widgets = user.Widgets |> List.toArray
        Connection.ofArray widgets

    Define.Field(name, ConnectionOf Widget, "A person's collection of widgets", Connection.allArgs, resolve)

which is instantiated as

fields = [
        Define.GlobalIdField(fun _ w -> w.Id)
        Define.Field("name", String, fun _ w -> w.Name)
        WidgetsField "widgets" (fun _ user -> user)
    ]

The issue is that only the first “widgets” field is functioning. All other instances causes exception in runtime.

Repro steps

Attaching modifed server.fsx for relay-starter-kit sample project.

  • Put this server.fsx to the sample’s folder.
    • Start the server by fsi server.fsx.
    • Run the query (in Postman)
{"query": "{
    viewer {name}, widgets { edges }
}"}

Notice the first declared “widgets” field is fully functional.

Actual behavior

NRE exception is raised.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
johnberzy-bazingacommented, Sep 23, 2016

@OlegZee @Horusiath

Until we investigate further, below is a workaround for that issue.

and WidgetConnection = ConnectionOf Widget
and WidgetsField name (getUser: ResolveFieldContext -> 'a -> User) =
    let resolve ctx xx =
        let user = getUser ctx xx 
        let widgets = user.Widgets |> List.toArray
        Connection.ofArray widgets

    Define.Field(name, WidgetConnection, "A person's collection of widgets", Connection.allArgs, resolve)
0reactions
johnberzy-bazingacommented, Nov 19, 2018

This is fixed with the change made in #101

Read more comments on GitHub >

github_iconTop Results From Across the Web

No error when using generic class without defining a type
At an assignment to a field: if the type of the left-hand operand is a raw type, then a compile-time unchecked warning occurs...
Read more >
Restrictions on Generics (The Java™ Tutorials ...
To use Java generics effectively, you must consider the following restrictions: Cannot Instantiate Generic Types with Primitive Types; Cannot Create Instances ...
Read more >
Using Generics as Autowiring Qualifiers
Assuming that the preceding beans implement a generic interface, (that is, Store<String> and Store<Integer> ), you can @Autowire the Store ...
Read more >
Static fields should not be used in generic types
A static field in a generic type is not shared among instances of different closed constructed types, thus LengthLimitedSingletonCollection<int>.instances ...
Read more >
Java Programming Tutorial on Generics
JDK 5 introduces generics, which supports abstraction over types (or parameterized types) on classes and methods. The class or method designers can be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found