1

Here is my resolver:

// CreateBook is the resolver for the createBook field.
func (r *mutationResolver) CreateBook(ctx context.Context, input model.NewBook) (*model.Book, error) {
book := &model.Book{
    ID:              input.ID,
    Default_user_id: input.DefaultUserID,
}

n := len(r.Books)
if n == 0 {
    r.Books = make(map[string]*model.Book)
}

r.Books[input.ID] = book
return r.Books[input.ID], nil
//panic(fmt.Errorf("not implemented: Teachers - teachers"))
}

Here's my Books declaration in my Resolver struct:

Books map[string]*model.Book

Here's my response when I call the mutation:

{
  `"errors": [
    {
      "message": "internal system error",
      "path": [
        "createBook",
        "id"
      ]
    }
  ],
  "data": {
    "createBook": null
  }
}

I've attempted the same implementation with an array and was able to successfully query and mutate, but when I use a map to represent the books I receive the above error.

Please help I'm so lost. See above for my code and the mutation I attempted.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.