-
Notifications
You must be signed in to change notification settings - Fork 274
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
NexusGenFieldTypes with resolved fields #36
Comments
Yeah, so the thought here is that nexus can't know whether fields with resolvers have that actual field on the "root type" or not, for instance you could have this: const User = objectType({
name: 'User',
definition: t => {
t.string('firstName');
t.string('lastName');
t.string('fullName', (root) => `${root.firstName} ${root.lastName}`)
},
}); What should the typing of {
firstName: string
lastName: string
} rather than: {
firstName: string
lastName: string
fullName: string
} because I have a separate ticket open to make something which would allow you to define the root types in runtime code rather than mapping them. Still need to think more about this - interested to hear feedback. It's a good question though, and something that needs to be much better documented since the type auto generation/inference is probably 90% of what makes Nexus really powerful. I think maybe if Let me know if this makes sense or if I could clarify further. |
Thank you @tgriesser. I agree that It's possible I don't understand the role of |
// type error on fullName because NexusGenFieldTypes['user']['fullName'] = 'string'
const User = objectType({
name: 'User',
definition: t => {
t.string('firstName');
t.string('lastName');
t.string('fullName', (root) => 1)
},
}); |
Ah, that 100% clears up what The answer may very well be that it is out of scope for this project, but what would you think of adding another |
@ecwyne I don't think that's even enough. After tinkering with the code, I was able to make it generate an exported interface called But that's not enough. Even with that, it is still necessary for me to declare the mapping of response type explicitly, and that's not much better than simply semi-duplicating the schema myself in the frontend. // Semi-duplicated schema.
user: NexusGenFieldTypes['User']
users: Array<NexusGenFieldTypes['User']>
// This is not really that much better.
user: NexusGenResponseTypes['user']
users: NexusGenResponseTypes['users'] We want the code above to be generated for us. For that, Nexus.js would have to parse the client query, which means expanding the scope of the Nexus.js project into the front-end. @tgriesser Would you reconsider expanding the scope of Nexus.js to the front-end as well? Or perhaps it could be developed as part of a plugin system. For now, the proper solution is using one of these tools: |
@tgriesser in my plugin library I'm adding a few fields based on some definition provided by the library user: https://github.com/JCMais/nexus-plugins/blob/6150e9793a48d93ec6a2e8501019cf1306b99266/plugins/relay-global-id/src/index.ts#L115-L132 @passionkind noticed (in this PR) that those fields are not added to the root type. Is there any way for me, as a plugin author, to add some fields to the root type? In my example above, I need the source object to have an |
I am not sure how best to ask this question, so I hope this simplest reproduction makes sense.
This code
produces these ts type definitions
In my client I am trying to give types to the following query
the closest I can get is
NexusGenFieldTypes['Query']['user']
but that returnsNexusGenRootTypes['User']
which does not have abody
. Is there a reason thatNexusGenFieldTypes
is not the following? (linking to field types instead of root types)The text was updated successfully, but these errors were encountered: