Skip to content
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

How to do a mutation? #2

Open
lmiller1990 opened this issue Jul 13, 2021 · 2 comments
Open

How to do a mutation? #2

lmiller1990 opened this issue Jul 13, 2021 · 2 comments

Comments

@lmiller1990
Copy link

lmiller1990 commented Jul 13, 2021

I looked at the docs for nexus and the source code here, but no luck. I also I tried to do something like this, but no dice:

@nxs.objectType({
  description: 'Namespace for information related to the app',
})
export class App {
  constructor (private ctx: ExecContext) {}

  @nxs.queryField(() => {
    return { type: App }
  })
  static app (_, ctx) {
    return new App(ctx)
  }

  @nxs.mutationField(() => {
    return {
      name: 'initProject',
      type: class {
        constructor(someValue: string) {}
      }
    }
  })
  public async initProject () {
    return { msg: 'ok!' }
  }
}
@tgriesser
Copy link
Member

I believe it should work if you make the method static:

@nxs.objectType({
  description: 'Namespace for information related to the app',
})
export class App {
  constructor (private ctx: ExecContext) {}

  @nxs.queryField(() => {
    return { type: App }
  })
  static app (_, ctx) {
    return new App(ctx)
  }

  @nxs.mutationField(() => {
    return {
      type: 'Boolean'
    }
  })
  static async initProject () {
    return true
  }
}

Will add to the docs

@lmiller1990
Copy link
Author

I swear I tried this, maybe was doing it wrong. I will try again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants