Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Graphql 普里斯玛:场。。。未在…中定义。。。输入类型或类型。。。应为,但已提交非对象_Graphql_Graphql Js_Prisma_Prisma Graphql - Fatal编程技术网

Graphql 普里斯玛:场。。。未在…中定义。。。输入类型或类型。。。应为,但已提交非对象

Graphql 普里斯玛:场。。。未在…中定义。。。输入类型或类型。。。应为,但已提交非对象,graphql,graphql-js,prisma,prisma-graphql,Graphql,Graphql Js,Prisma,Prisma Graphql,我用的是Prisma 1.34。fro API开发。通过localhost操场测试它。 抱歉提前发了这么长的短信,我不明白我哪里出错了 我有以下表示层次结构的方案脚本模板由卡片模板组成,卡片包括任务模板: type ScriptTemplate { id: ID! name: String! cards: [CardTemplate!] input: String! output: String! } type CardTemplate { id: ID! tit

我用的是Prisma 1.34。fro API开发。通过localhost操场测试它。 抱歉提前发了这么长的短信,我不明白我哪里出错了

我有以下表示层次结构的方案脚本模板由卡片模板组成,卡片包括任务模板:

type ScriptTemplate {
  id: ID! 
  name: String!
  cards: [CardTemplate!]
  input: String!
  output: String!
}

type CardTemplate {
  id: ID!
  title: String!
  description: String
  tasks: [TaskTemplate!]
}

input ExistingCardTemplateInput {
  id: ID!
}

input NewCardTemplateInput {
  title: String!
  description: String!
  tasks: [NewTaskTemplateInput!]
}

type TaskTemplate {
  id: ID!
  label: String!
  description: String!
  cards: [CardTemplate!]
}

input ExistingTaskTemplateInput {
  id: ID!
}

input NewTaskTemplateInput {
  label: String!
  description: String!
}

相应的突变是:

type Mutation {
  createScriptTemplate(name: String!, input: String!, output: String!, cards: [ExistingCardTemplateInput!], new_cards: [NewCardTemplateInput!]): ScriptTemplate
  createCardTemplate(title: String!, description: String! tasks:[ExistingTaskTemplateInput!], new_tasks:[NewTaskTemplateInput!]): CardTemplate
  createTaskTemplate(label: String!, description: String! cards:[ExistingCardTemplateInput!]): TaskTemplate

}
所以基本上,如果我尝试使用
createTaskTemplate
mutation或
createCardTemplate
mutation,一切都正常。我可以创建这些实体,包括创建包含新任务的新卡或绑定现有任务。或将现有卡添加到新创建的任务。这就是明确定义输入类型的原因:
ExistingTaskTemplateInput
NewTaskTemplateInput
NewCardTemplateInput
。 当我尝试创建一个包含新卡的新脚本或将其连接到现有卡时,一切都按预期进行。 然而,若我试图创建脚本、卡片并在其中包含新任务,我会在上面看到错误消息

  • 在尝试以下变异时:
  • 我有个错误:

    {
      "data": {
        "createScriptTemplate": null
      },
      "errors": [
        {
          "message": "Variable '$data' expected value of type 'ScriptTemplateCreateInput!' but got: 
    {\"name\":\"First Script through API_H2\",\"input\":\"Something describing initial state\",\"output\":\"Something describing requred state at the end\",\"cards\":{\"connect\":[{\"id\":\"cjycl2nup00ta0703sd0kd8oa\"},{\"id\":\"cjye3ryee01ey070383sxaoxz\"}],\"create\":[{\"title\":\"New card via scriptis2\",\"description\":\"desc\",\"tasks\":[{\"label\":\"test label\",\"description\":\"test dewscription\"}]},{\"title\":\"New card through scriptos2\",\"description\":\"desc\"}]}}. 
    Reason: 'cards.create[0].tasks' 
    Expected 'TaskTemplateCreateManyWithoutCardsInput', found not an object. (line 1, column 11):\nmutation ($data: ScriptTemplateCreateInput!) {\n          ^",
          "locations": [
            {
              "line": 2,
              "column": 3
            }
          ],
          "path": [
            "createScriptTemplate"
          ]
        }
      ]
    }
    
    实际请求如下所示(通过console.log):

    看起来我缺少
    任务
    字段的{connect或create}位。 但是,当我将其更改为:

    tasks: {create: [ 
              {
                description: "test dewscription"
                label: "test label"
              }
            ]
           }
    
    我得到的错误是,
    字段\“create\”不是由类型NewTaskTemplateInput定义的
    字段NewTaskTemplateInput.label和所需类型字符串的描述!未提供

  • 但是,这可以很好地工作(没有任务的相同请求):
  • 检查生成的方案,无法发现任何问题

    input TaskTemplateCreateManyWithoutCardsInput {
      create: [TaskTemplateCreateWithoutCardsInput!]
      connect: [TaskTemplateWhereUniqueInput!]
    }
    
    input TaskTemplateCreateWithoutCardsInput {
      id: ID
      label: String!
      description: String!
    }
    
    看起来我混淆了我在gql文件中定义的方案和我再次执行请求的方案,但不知道该往哪个方向走。

    Description 首先概述请求的整个过程

    上图取自Prisma官方文档中的Prisma Basic

    如图所示,
    localhost playway
    是图中的
    客户端
    。由
    localhost playway
    访问的
    服务器
    是图中的
    API服务器
    ,即
    Prisma客户端
    。这是第一个连接,图中的绿色箭头。
    Prisma客户端
    通过访问
    Prisma服务器
    从数据库获取数据。这是第二个连接,图中的黄色箭头

    数据流处理,从
    localhost
    发送到
    API服务器
    完成第一次连接传输,然后由
    resolve
    处理,使用
    Prisma客户端
    发送到
    Prisma服务器
    完成第二次连接传输
    Prisma服务器
    根据请求的数据从
    数据库
    检索数据,并将其返回到
    API服务器
    ,完成第二次连接验收<代码>API服务器将数据返回到
    本地主机
    ,完成对第一个连接的接受。一个完整的过程完成了

    在使用
    Prisma
    的过程中,我们定义了两个模式,一个用于定义
    Prisma服务器
    ,名称通常是
    datamodel.Prisma
    。另一个用于定义
    Prisma客户端
    ,如果它是在文件中定义的,通常命名为
    schema.graphql
    ,也可以通过模板字符串在JS文件中定义,还有其他方式,这里不作深入讨论。您显示的内容属于
    客户机架构

    成功完成此过程需要每个部件发送的数据正确无误。 发送第二个连接时发生第一个错误。从
    API服务器
    发送的数据与
    Prisma服务器
    中的架构定义不匹配。 第二个错误是,当发送第一个连接时,从
    localhost
    发送的数据与
    API服务器中的架构定义不匹配

    例子 假设以下架构

    # datamodel.prisma
    type User {
      id: @id!
      name: String!
      post: [Post!]!
    }
    type Post {
      id: @id!
      title: String!
    }
    
    使用以下命令创建用户

    mutation {
      createUser(name: "prisma", posts: [{ title: "test" }]) {
        id
        name
      }
    }
    
    localhost
    发送到
    API服务器
    时,数据如下

    {
      "name": "prisma",
      "posts": [{ "title": "test" }]
    }
    
    如果将此数据直接发送到
    Prisma服务器
    ,则不符合
    Prisma服务器
    的定义。您需要将数据转换为符合
    Prisma服务器
    模式的定义

    {
      "name": "prisma",
      "posts": { "create": [{ "title": "test" }] }
    }
    
    然后通过
    Prisma客户端将其发送到
    Prisma服务器

    const resolve={
    突变:{
    createUser:async(\uz,args)=>{
    常量userCreateInput={
    名称:args.name,
    职位:{
    创建:args.posts,
    },
    }
    返回wait prisma.createUser(userCreateInput)
    },
    },
    }
    
    这样,最终数据通过
    Prisma服务器
    到达数据库

    解决问题 查看
    API Server
    createScriptTemplate
    的定义。应该是它没有将接收到的数据转换为由
    API Server
    所需格式引起的错误



    我认为您必须在
    任务
    中使用
    创建
    ,使用标签和说明,或者使用
    连接
    仅使用
    id
    。这里,您使用带有标签和说明且没有id的
    connect
    。@Errorname对不起,我的错误示例。“create”的结果是否相同并不重要。我无法理解的是,我将
    任务的输入类型显式定义为
    [NewTaskTemplateInput!]
    。为什么Prisma会在某一时刻根据此类型检查它,但同时根据
    TaskTemplateCreateWithout CardsInput
    检查它?
    # schema.graphql
    input CreatePost {
      title: String!
    }
    type Mutation {
      createUser(name: String!,posts:[CreatePost])
    }
    
    mutation {
      createUser(name: "prisma", posts: [{ title: "test" }]) {
        id
        name
      }
    }
    
    {
      "name": "prisma",
      "posts": [{ "title": "test" }]
    }
    
    {
      "name": "prisma",
      "posts": { "create": [{ "title": "test" }] }
    }