Graphql 无法返回null或不可为null的字段用户。角色无法从prisma中检索关系数据

Graphql 无法返回null或不可为null的字段用户。角色无法从prisma中检索关系数据,graphql,apollo-server,prisma,prisma-graphql,prisma-binding,Graphql,Apollo Server,Prisma,Prisma Graphql,Prisma Binding,我试着用arroud APOLO服务器、GRAPHQL PRISMA和struct来做最基本的事情。。我无法从简单查询返回关系数据 当我尝试添加用户和角色id时。。我无法获取角色信息 我在用什么 "dependencies": { "apollo-server": "^2.9.3", "bcryptjs": "^2.4.3", "graphql": "^14.5.5", "graphql-import": "^0.7.1", "jsonwebtoken":

我试着用arroud APOLO服务器、GRAPHQL PRISMA和struct来做最基本的事情。。我无法从简单查询返回关系数据

当我尝试添加用户和角色id时。。我无法获取角色信息

我在用什么

"dependencies": {
    "apollo-server": "^2.9.3",
    "bcryptjs": "^2.4.3",
    "graphql": "^14.5.5",
    "graphql-import": "^0.7.1",
    "jsonwebtoken": "^8.5.1",
    "prisma-client-lib": "^1.34.8"
  }
对于我的简单查询

mutation{

  createUser(name:"tst",
  roleId:"ck0lx425n00z50782jgcl4qg8")
  {
    name
    role{
code}
Graphql返回错误说明

{
  "errors": [
    {
      "message": "Cannot return null for non-nullable field User.role.",
      "locations": [
        {
          "line": 4,
          "column": 5
        }
      ],
      "path": [
        "createUser",
        "role"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "Error: Cannot return null for non-nullable field User.role.",
GAPHQL SHCHEMA

scalar DateTime

type User {
  id: ID! 
  name: String! 
  role:Role!
  createdAt:DateTime 

}

 type Role{
   id:ID!,
   code:String!
   users:[User!]!
 }
type Query {
  users:[User!]!
  user:User!
  roles:[Role!]!
  role:Role!
}

type Mutation {
  createRole(code:String!):Role!
  createUser(name:String!,roleId:String!):User! 

 }
质疑

function users(parent, args, context) {
    return context.prisma.uses()

}
function roles(parent,args,context){
    return context.prisma.roles()
}
mutaion

function  createRole(parent,args,context,info){
     return context.prisma.createRole({
         code:args.code
     });

function  createUser(parent,args,context,info){
    return context.prisma.createUser({
        name:args.name,
        role:{
            connect:{id:args.roleId}
        }
    },info);


}
PRISMA数据模型

type User {
  id: ID! @id 
  name:String! 
  createdAt:DateTime @createdAt
  role:Role! @relation(Name:"Role Assinged To User")

}

type Role{
  id:ID! @id
  code:String! 
  users:[User!]! @relation(Name:"Role Assinged To User")

}

有人能帮我吗,这是怎么解决的。。我知道这将是我错过的最基本的一个。。我在努力理解?我是否缺少一些非常基本的东西?

当您创建角色时,您还需要指定一个用户,因为您将其作为一个可能导致错误的要求