尝试添加按该对象的唯一ID进行过滤的查询。
Query.js
async function getAbility (root, args, context, info) {
return await context.prisma.ability({
where : {id : args.abilityId}
}, info)
}
这也在我的schema.graphql文件中定义。
getAbility(where: AbilityWhereUniqueInput) : Ability
我认识到AbilityWhereUniqueInput来自使用Prisma CLI完成的模式生成,但是我不确定如何为schema.graphql文件引用它。
我试图将其添加到文件顶部:
# import * from './generated/prisma-client/prisma-schema'
但是,每当我尝试运行该应用程序时,就是说它遇到意外的字符'。',指的是我为导入提供的文件路径的第一部分。
其他相关声明:
schema.graphql
type Ability {
id: ID!
name: String!
description: String!
imagePath: String!
}
答案 0 :(得分:2)
prisma.yml
# Specifies the HTTP endpoint of your Prisma API (deployed to a Prisma Demo server).
endpoint: https://eu1.prisma.sh/public-cookiearm-769/exp-graphql-subscription/dev
# Defines your models, each model is mapped to the database as a table.
datamodel: datamodel.prisma
# Specifies the language and directory for the generated Prisma client.
generate:
- generator: javascript-client
output: ../src/generated/prisma-client
- generator: graphql-schema
output: ../src/generated/prisma.graphql
# Seed your service with initial data based on `seed.graphql`.
seed:
import: seed.graphql
# Ensures Prisma client is re-generated after a datamodel change.
hooks:
post-deploy:
- prisma generate
# If specified, the `secret` must be used to generate a JWT which is attached
# to the `Authorization` header of HTTP requests made against the Prisma API.
# Info: https://www.prisma.io/docs/prisma-graphql-api/reference/authentication-ghd4/
# secret: mysecret123
在这里您看到我正在生成两个文件。一个用于棱镜客户端,另一个用于导入schema.graphql
中的类型。
schema.graphql
# import * from './generated/prisma.graphql'
type Query {
feed: [Post!]!
drafts: [Post!]!
post(id: ID!): Post
}
type Mutation {
createDraft(title: String!, content: String): Post
editPost(id: String!, data: PostUpdateInput!): Post
deletePost(id: ID!): Post
publish(id: ID!): Post
}
type Subscription {
post: Post!
}
type Post {
id: ID!
published: Boolean!
title: String!
content: String!
}
查看此行
# import * from './generated/prisma.graphql'
现在我可以在schema.graphql中使用PostUpdateInput
确保您更改了遵循的路径。
答案 1 :(得分:0)
请确保导入的生成方案具有.graphql扩展名,因为您不能在graphql文件中导入非graphql文件。