-
Notifications
You must be signed in to change notification settings - Fork 275
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
Using resolve to modify field #125
Comments
The problem here is how @tgriesser already explained in the related issue, which comes down to the chicken or the egg problem. You define a field on the type that is computed, but the value you compute from is actually be supposed to be on the root object already. I think the only way(and cleanest way) to do this is to let Nexus know your underlying data models which if you're working with TypeScript are probably already defined with an interface/type/class. You can do this by adding sources to the The star-wars example shows how to do this: export const schema = makeSchema({
types: allTypes,
outputs: {
schema: path.join(__dirname, "../star-wars-schema.graphql"),
typegen: path.join(__dirname, "./star-wars-typegen.ts"),
},
typegenAutoConfig: {
sources: [
{
source: path.join(__dirname, "./types/backingTypes.ts"),
alias: "swapi",
},
],
contextType: "swapi.ContextType",
},
}); The docs (https://nexus.js.org/docs/type-generation) also have a section about this although I think it should be shown more in depth of what the power of this feature is. |
Oh, I guess missed it.
@Nayni thank you for detailed explanation. |
Sorry for bad issue title, not sure how to properly name it.
While rewriting app to nexus I found problem with resolvers that modify. For example:
Both
title
andprice
stored in database, but during request I want to modify them based on request details:JavaScript code works, because these fields exist in
root
, but TypeScript bugs me becauseNexusGenRootTypes[]
does not haveprice
andtitle
fields.I see two ways to resolve this:
transform
, which would work likeauthorize
resolver, but should be called last (authorize
->resolve
->transform
)NexusGenRootTypes
. (e.g:belongsToRoot: true
).Related to #36.
The text was updated successfully, but these errors were encountered: