Muwnaguzi Joshua
Muwnaguzi Joshua

Reputation: 21

Error Cannot return null for non-nullable type: 'String' within parent MyModelType' (/createMyModelType/id)

I am trying to trigger a mutation in the aws console. I have linked my resolver function to a None type data source. However, when I define my mutation with an input type as a parameter, the error " Error Cannot return null for non-nullable type: 'String' within parent MyModelType' (/createMyModelType/id)." occurs. Everything is fine though if I replace the input type with key word arguments. I am certain it has to do with my resolver mapping template. Just if you're wondering why I am using a None type, I want to be able to trigger a subscription without making real database changes or mutations. I am not sure how to make it work with input types. Here is my code for the template:

{
    "version": "2017-02-28",
    "payload": $util.toJson($context.args)
}

My Schema:

input CreateMyModelType5Input {
    title: String
}


type Mutation {
    createMyModelType5(input: CreateMyModelType5Input!): MyModelType5
}

type MyModelType5 {
    id: ID!
    title: String
}


type Subscription {
    onCreateMyModelType5(id: ID, title: String): MyModelType5
        @aws_subscribe(mutations: ["createMyModelType5"])
}

Query I am trying to run:

mutation createMyModelType($createmymodeltypeinput: CreateMyModelTypeInput!) {
  createMyModelType(input: $createmymodeltypeinput) {
    id
    title
  }
}

Query Variables for the mutation query

{
  "createmymodeltype5input": {
    "title": "Hello, world!"
  }
}

Upvotes: 1

Views: 1235

Answers (1)

Muwnaguzi Joshua
Muwnaguzi Joshua

Reputation: 21

So I have been working on passing my arguments in the graphql mutation and using the input type seemed the only straight forward way around. However, I have been able to do it with this way:

    mutation = """mutation CreateMyModelType($id: String!, $title: String!){
        createMyModelType(id: $id, title: $title){
            id
            title
        }
    }
    """
    
    input_params = {
        "id": "34",
        "title": "2009-04-12"
    }

    response = app_sync.createMyModelType(mutation, input_params)

this can be a good guide

Upvotes: 1

Related Questions