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 create mutation with foreign key? #54

Open
xp13910818313 opened this issue Oct 20, 2020 · 0 comments
Open

how to create mutation with foreign key? #54

xp13910818313 opened this issue Oct 20, 2020 · 0 comments

Comments

@xp13910818313
Copy link

xp13910818313 commented Oct 20, 2020

I want to create mutation with domain class talk ,how to write the document?

@GrailsCompileStatic
class Speaker {
    String firstName
    String lastName
    String name
    String email
    String bio
    static hasMany = [talks: Talk]
    static graphql = true 
    static constraints = {
        email nullable: true, email: true
        bio nullable: true
    }
    static mapping = {
        bio type: 'text'
        name formula: 'concat(FIRST_NAME,\' \',LAST_NAME)'
        talks sort: 'id'
    }
}

@GrailsCompileStatic
class Talk {
    Speaker speaker
    String title
    int duration
    static graphql = true 
    static belongsTo = [speaker: Speaker]
}

if i use the code like this:

mutation {
  talkCreate(talk: {
    title: "about K8S"
    duration: 120
    speaker: {
        id: 1
    }
  }) {
    id
    title
    duration
    speaker {
        id
    }
    errors {
      field
      message
    }
  }
}

the speaker_id always set null, why?

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

1 participant