如何使用Graphql和Prisma保存和更改一堆数据

时间:2019-06-09 18:25:53

标签: javascript graphql graphql-js prisma prisma-graphql

我遵循以下架构,并希望将一个数据记录Time保存到UserTimerRecord.timeIds中。我想将以下每个数据记录Time推入UserTimeRecords.timeIds

type UserTimeRecord {
  id: ID! @id
  timeIds: [Time]
  userId: ID! @userId
  createdAt: DateTime @createdAt
}

type Time {
  id: ID! @id
  type: String!
  time: DateTime! @createdAt
}

async setTime (_, { type }, context) {
    const userId = getUserId(context)

    const time = await prisma.createTime({ type })

    if (type === 'start') {
      await prisma.createUserTimeRecord({
        userId,
        timeIds: [time]
      })
    }

    return time
  }
}

我遇到了错误Reason: 'timeIds' Expected 'TimeCreateManyInput', found not an object.

1 个答案:

答案 0 :(得分:0)

您可以使用Environment.TEST

添加一堆数据
create