天道酬勤,学无止境

prisma

如何修复由数据类型关系引起的“变量“$_v0_data”得到无效值 - Mutation Resolver(How to fix 'Variable "$_v0_data" got invalid value' caused from data types relation - Mutation Resolver)

问题 我正在尝试设置类型之间的关系并编写了一个解析器来运行一个创建列表值的突变,但得到以下错误 这是我的突变文件 async createList(parent, args, ctx, info) { const list = await ctx.db.mutation.createList( { data: { project: { connect: { id: args.projectId } }, ...args } }, info ); return list; } 这是我的数据模型 type Board { id: ID! @id title: String! createdAt: DateTime! @createdAt updatedAt: DateTime! @updatedAt lists: [List]! } type List { id: ID! @id title: String! createdAt: DateTime! @createdAt updatedAt: DateTime! @updatedAt project: Board! } 我的架构是 type Mutation { createList(title: String!, projectId: ID!): List! } 和生成的棱镜文件 type Mutation { createList

2021-10-25 02:49:49    分类:技术分享    javascript   graphql   prisma   prisma-graphql

Prisma graphql 计算域(Prisma graphql computed fields)

问题 我有这个数据模型: type Item { id: ID! @unique title: String! description: String! user: User! pictures: [Picture] basePrice: Int! addons: [Addon] } 我正在编写一个名为 parsedItem 的查询,它从参数中获取 id 并查找 Item(使用 Prisma 生成的 Item 的默认查询),如下所示: const where = { id: args.id }; const item = await ctx.db.query.item({ where }, `{ id title ... 我需要在前端显示一个计算值:“dynamicPrice”,它取决于项目拥有的插件的数量。 例如:Item #1 有 3 个插件,每个插件的价值为 5 美元。 这个计算值应该是 dynamicPrice = basePrice + 3 * 5 Addon 关系可能会改变,所以我需要在前端发出的每个请求中计算它。 我非常想做这样的事情: item.dynamicPrice = item.basePrice + (item.addons.length * 5) 并在解析器中返回此项目,但这不起作用。 那抛出一个错误: "message": "无法在类型 \"Item\"

2021-10-24 12:59:34    分类:技术分享    graphql   apollo   apollo-client   prisma   prisma-graphql

过滤掉打字稿中接口不需要的对象属性(filter out unneeded object properties for interface in typescript)

问题 作为背景,我使用 Prisma (graphql)、mysql2 (nodejs) 和 typescript。 我正在使用交互式命令行脚本连接到 mysql2。 这是我看到的警告: 忽略传递给 Connection: 类型的无效配置选项。 这是当前的警告,但在 MySQL2 的未来版本中,如果将无效的配置选项传递给 Connection,则会引发错误 这就是我在 MysqlConnector 类中实例化 mysql2 的方式: this.connectionPromise = await this.mysql.createConnection(this.connectionOptions) “connectionOptions”在类构造函数中设置: constructor(connectionDetails: MysqlConnectionDetails) { 这是我的类型定义: export interface MysqlConnectionDetails { host: string port: number user: string password: string database?: string } 这是我传递给 MysqlConnector 类的对象的类型定义: export interface DatabaseCredentials { type

2021-10-23 17:35:59    分类:技术分享    javascript   typescript   prisma

How to fix 'Variable "$_v0_data" got invalid value' caused from data types relation - Mutation Resolver

I am trying to setup relations between types and wrote a resolver to run a mutation that create the list values but getting the below error here is my mutation file async createList(parent, args, ctx, info) { const list = await ctx.db.mutation.createList( { data: { project: { connect: { id: args.projectId } }, ...args } }, info ); return list; } and here is my datamodel type Board { id: ID! @id title: String! createdAt: DateTime! @createdAt updatedAt: DateTime! @updatedAt lists: [List]! } type List { id: ID! @id title: String! createdAt: DateTime! @createdAt updatedAt: DateTime! @updatedAt

2021-10-23 11:18:51    分类:问答    javascript   graphql   prisma   prisma-graphql

使用 Docker Compose 在端口 3307 上运行 MySQL(Run MySQL on Port 3307 Using Docker Compose)

问题 我正在尝试在一台机器上创建多个 Prisma 数据库服务。 我一直无法使用 Docker Compose 在 3306 以外的端口上创建 MySQL 数据库。 docker-compose.yml version: '3' services: hackernews: image: prismagraphql/prisma:1.8 restart: always ports: - "${CLIENT_PORT}:${INTERNAL_PORT}" environment: PRISMA_CONFIG: | port: $INTERNAL_PORT managementApiSecret: $PRISMA_MANAGEMENT_API_SECRET databases: default: connector: mysql host: mysql port: $SQL_INTERNAL_PORT user: root password: $SQL_PASSWORD migrations: true mysql: image: mysql:5.7 restart: always environment: MYSQL_ROOT_PASSWORD: $SQL_PASSWORD volumes: - ./custom/:/etc/mysql/conf.d/my.cnf - mysql

2021-10-23 05:34:13    分类:技术分享    mysql   docker   docker-compose   prisma

Prisma graphql computed fields

I have this datamodel: type Item { id: ID! @unique title: String! description: String! user: User! pictures: [Picture] basePrice: Int! addons: [Addon] } I'm writing a query called parsedItem that takes the id from arguments and looks for the Item (using the default query for Item generated by Prisma), something like this: const where = { id: args.id }; const item = await ctx.db.query.item({ where }, `{ id title ... I need to show on the frontend a computed value: "dynamicPrice" it depends on the quantity of the Addons that the Item has. e.g: Item #1 has 3 addons, each addons has a value of $5

2021-09-01 06:29:31    分类:问答    graphql   apollo   apollo-client   prisma   prisma-graphql

filter out unneeded object properties for interface in typescript

As background, I'm using Prisma (graphql), mysql2 (nodejs) and typescript. I'm using an interactive command line script to connect to mysql2. This is the warning I am seeing: Ignoring invalid configuration option passed to Connection: type. This is currently a warning, but in future versions of MySQL2, an error will be thrown if you pass an invalid configuration options to a Connection This is how I instantiate mysql2, in my MysqlConnector class: this.connectionPromise = await this.mysql.createConnection(this.connectionOptions) "connectionOptions" is set in the class constructor: constructor

2021-08-30 18:37:32    分类:问答    javascript   typescript   prisma

Row level security using prisma and postgres

I am using prisma and yoga graphql servers with a postgres DB. I want to implement authorization for my graphql queries. I saw solutions like graphql-shield that solve column level security nicely - meaning I can define a permission and according to it block or allow a specific table or column of data (on in graphql terms, block a whole entity or a specific field). The part I am stuck on is row level security - filtering rows by the data they contain - say I want to allow a logged in user to view only the data that is related to him, so depending on the value in a user_id column I would allow

2021-08-01 23:14:42    分类:问答    postgresql   graphql   prisma   row-level-security   prisma-graphql

Apollo GraphQL subscriptions is not working in Vuejs

I am using GraphQL Subscription with Prisma and vuejs + apollo client In local system, I am running vuejs at http://localhost:8080 and server at http://localhost:4000. I want to display recently added and updated records in dashboard. I have implemented subscription in my local system and it's working proper. I push all server side and client side code to server but subscription is not working there. I am using AWS server. Everything is working proper except subscription. I set up websockets and it's also working proper. Sometime I am getting below error: WebSocket connection to 'wss://URL

2021-07-29 00:37:09    分类:问答    vue.js   graphql   apollo-client   apollo-server   prisma

Prisma 2 query to return records only that are associated with ALL of the provided tag IDs

I have tables Principles and Tags. And there is a many-to-many relation between them (joined implicitly). Without using prisma.raw, how can I run the following query? SELECT p.id, p.title, p.description, p.createdAt, p.modifiedAt FROM principle p WHERE EXISTS (SELECT NULL FROM _PrincipleToTag pt WHERE pt.B IN (${tagIds.join(',')}) AND pt.A = p.id GROUP BY pt.A HAVING COUNT(DISTINCT pt.B) = ${tagIds.length}) How can I update this Prisma 2 query such that the principles returned are only principles that are associated with ALL of the provided tagIds? export const principles = ({ tagIds }) => {

2021-06-25 03:06:08    分类:问答    react-apollo   apollo-server   prisma   prisma-graphql   redwoodjs