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.

Field level resolver makes the field disappear from TS typegen

See original GitHub issue

Hi. I want to store 1-many relation in an array which contains ids to related objects. orders: [123, 456, 789] And then I want that field level resolver to grab related objects but as soon as i add resolver function the field disappears and TS raises an error saying field does not exist on type. Relevant image: Снимок экрана 2021-10-29 в 11 26 24 For example having only type: type: list("Order") does not remove the field from TS typegen but as soon as resolve func is added, the field is gone.

What’s the problem here? Am i misunderstanding something?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
tgriessercommented, Oct 29, 2021

Yeah, this has been a longstanding source of confusion. The original intention of Nexus is that you’re providing a way to resolve your “source types” globally: https://nexusjs.org/docs/guides/source-types#globally-configure-source-types

I use a fork of schemats for this. If source / parent is an object that’s an ORM class, then you’d want a way to know it’s that object and not a vanilla JS object. I use a codegen of the database with a fork of schemats for this, but for simpler types or if you don’t want/need to do this, it should be possible to manage this on the object’s field definition.

I’m thinking maybe we add a convenience helper for this, sourceType?

sourceType: true - preserve sourceType: 'string | number', etc - specify custom typing

t.list.field('orders', {
  type: 'Order',
  sourceType: true,
  resolve: () => // ...
})

If true it will preserve whatever the typing would otherwise be for the field based on the definition, so in this case:

parent.orders // Order[] | null | undefined

@jasonkuhrt thoughts?

1reaction
VincentGillotcommented, Dec 14, 2022

Is there any news on this? Because if I use: sourceType: { module: __filename, export: 'UserShape' } The type is correctly imported in the generated types file but since I use this file in the front-end I don’t have access to the import.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Return incomplete shapes from resolver with GraphQL Code ...
When I have these sorts of scenarios, I make the extra field nullable (replace extra: UserExtra! with extra: UserExtra ).
Read more >
Upgrading from Prisma 1 with prisma-binding to Nexus
This file will contain the type of your context object that's passed through your GraphQL resolver chain. Create the new context.ts file inside...
Read more >
What is generated? — TypeGen 2.5.2 documentation
Both properties and fields will be generated to TypeScript, unless marked with TsIgnore attribute. Fields are always declared before properties in the ...
Read more >
@slonik/typegen - npm Package Health Analysis | Snyk
We found a way for you to contribute to the project! Looks like @slonik/typegen is missing a security policy. You can connect your...
Read more >
type-graphql/Lobby - Gitter
Does the value used as its TS type or explicit type is decorated with a ... there a way to access arguments given...
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