Ctx.db.mutation. "UpdateAccepted" не является функцией .. Мутация не генерируется Prisma - PullRequest
0 голосов
/ 23 мая 2019

Я пытаюсь сделать мутацию graphql для обновления элемента из моей существующей базы данных. Тем не менее, я получаю сообщение об ошибке при попытке выполнить эту мутацию.

Я добавил «принято» к пункту:

Я пытался развернуть мою схему, но ничего не произвело ..

type Item {
  id: ID! @id
  title: String!
  image: String
  largeImage: String
  price: Int!
  user: User!
  accepted: String!
}

После этого я сделал мутацию:

type Mutation {
  updateAccepted(id: ID!): Item!
}

Тогда я написал резольвер:

async updateAccepted(parent, args, ctx, info) {
    // 1. Check if the person is logged in
    const { userId } = ctx.request;
    if (!userId) {
      throw new Error('You must be signed in');
    }
    // 2. find the item
    const item = await ctx.db.mutation.updateAccepted(
      {
        where: { id: args.id },
        data: {
          accepted: 1
        }
      },
      info
    );

    // 3. Return the item
    return item;
  },

Когда я выполняю эту функцию на детской площадке, я получаю эту ошибку

{
  "data": null,
  "errors": [
    {
      "message": "ctx.db.mutation.updateAccepted is not a function",
      "locations": [
        {
          "line": 10,
          "column": 3
        }
      ],
      "path": [
        "updateAccepted"
      ]
    }
  ]
}

Добрый невежественный атм, пожалуйста, помогите dev в нужде:)

1 Ответ

0 голосов
/ 24 мая 2019

Проблема решена.Проблема заключалась в том, что мне пришлось звонить updateItem вместо updateAccepted.Мутация по типу Item ... не accepted ..

async updateAccepted(parent, args, ctx, info) {
    const { id, accepted } = args;
    // 1. Check if the person is logged in
    const { userId } = ctx.request;
    if (!userId) {
      throw new Error('You must be signed in');
    }
    // 2. find the item
    return ctx.db.mutation.updateItem(
      {
        data: { accepted },
        where: { id: args.id }
      },
      info
    );
  },

Счастливые дни

...