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.

TypeError when using AuthorizePlugin

See original GitHub issue

image

TS2345: Argument of type '{ type: NexusObjectTypeDef<"GroupCategory">; description: string; args: { name: NexusArgDef<"String">; }; authorize: () => boolean; resolve(parent: any, args: any, { database, tenant }: Context): Promise<...>; }' is not assignable to parameter of type 'NexusOutputFieldConfig<"Mutation", "createGroupCategory">'.   Object literal may only specify known properties, and 'authorize' does not exist in type 'NexusOutputFieldConfig<"Mutation", "createGroupCategory">'.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cvngcommented, Nov 19, 2020

@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

0reactions
toinelincommented, Feb 1, 2021

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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError when using AuthorizePlugin · Issue #511 - GitHub
Given your TS error, it looks like the authorize property is not known at all by TS. Are you sure you've enabled the...
Read more >
Unexpected TypeError when using reduce function
2 Answers 2 ... The list function cannot be used because it corresponds to a type conversion which is not possible as your...
Read more >
Typeerror: str object is not callable – How to Fix in Python
The result was the TypeError: 'str' object is not callable error. This is happening because we are using a variable name that the...
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