Open chareice opened 4 years ago
Hey @chareice,
Given your TS error, it looks like the authorize
property is not known at all by TS. Are you sure you've enabled the authorize plugin?
import { makeSchema, fieldAuthorizePlugin } from '@nexus/schema'
export const schema = makeSchema({
plugins: [fieldAuthorizePlugin()],
})
@Weakky Yes, It's enabled.
Well, I'm sorry but I cannot reproduce your error. Would you mind providing a small reproduction? 🙏
@chareice A quick fix I have found is to copy-paste this snippet into your project:
// Taken from https://github.com/graphql-nexus/schema/blob/4f4f9f49e8afa235da1f1cfe73e685fbf8835714/examples/ghost/src/generated/ghost-nexus.ts#L217
declare global {
interface NexusGenPluginTypeConfig<TypeName extends string> {}
interface NexusGenPluginFieldConfig<TypeName extends string, FieldName extends string> {
/**
* Authorization for an individual field. Returning "true"
* or "Promise<true>" means the field can be accessed.
* Returning "false" or "Promise<false>" will respond
* with a "Not Authorized" error for the field.
* Returning or throwing an error will also prevent the
* resolver from executing.
*/
authorize?: FieldAuthorizeResolver<TypeName, FieldName>
}
interface NexusGenPluginSchemaConfig {}
}
You could also try to use Nexus built-in typegen
and the error should vanish:
https://nexusjs.org/docs/api/make-schema#shouldgenerateartifacts-outputs-typegenautoconfig
Hello 🖖
Encountered the same issue now and with the disparition of typegenAutoConfig
I wondered if is there any different solution instead of creating definition file ourselves (which imo should not be an ideal fix) ?
Encountered the same issue now and with the disparition of typegenAutoConfig I wondered if is there any different solution instead of creating definition file ourselves (which imo should not be an ideal fix) ?
typegenAutoConfig
hasn't gone anywhere, it was just renamed to sourceTypes
Indeed, my bad I wrote my comment before making further investigations about this 🤡
I found a solution in case of someone looking for a fix. I added this to tsconfig.json
"ts-node": {
"files": true
},
"files": [
"./@types/nexus-typegen.d.ts",
],
And now it works for me :)