首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用Graphql和Prisma保存和更改大量数据

如何使用Graphql和Prisma保存和更改大量数据
EN

Stack Overflow用户
提问于 2019-06-10 01:48:52
回答 1查看 0关注 0票数 0

我得到了以下架构,并希望将一个数据记录保存TimeUserTimerRecord.timeIdsTime我想要推进的每个后续数据记录UserTimeRecords.timeIds

代码语言:javascript
复制
type UserTimeRecord {
  id: ID! @id
  timeIds: [Time]
  userId: ID! @userId
  createdAt: DateTime @createdAt
}

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

代码语言:javascript
复制
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.

EN

回答 1

Stack Overflow用户

发布于 2019-06-10 11:32:55

您可以添加一堆数据 create

代码语言:javascript
复制
async setTime (_, { type }, context) {
    const userId = getUserId(context)

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

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

    return time
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100006958

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档