我应该在 graphql 模式文件中将每个对象写两次作为“输入"和“类型"吗 [英] Should I write two times each objects as 'input' and 'type' in a graphql schema file

查看:19
本文介绍了我应该在 graphql 模式文件中将每个对象写两次作为“输入"和“类型"吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在 GraphQL 中使用 Java 对象作为响应和请求.

I have to use a Java object in GraphQL in response as well as in request.

我是否应该在 GraphQL 模式文件中将每个对象写两次作为输入"和类型"?用于在请求和响应中获取该对象.

Should I have to write two times each objects as 'input' and 'type' in a GraphQL schema file? For getting that object in request as well as in response.

我应该用 input 和 type 定义同一个对象两次吗?

Should I define the same object two times with input and type?

文件:test.graphqls

input Employee {
  id: Integer
  name: String
  dept: String
  active: String
}

type Employee {
  id: Integer
  name: String
  dept: String
  active: String
}

推荐答案

是的,因为输入和输出类型的类型系统规则非常不同.输入类型不能是联合,不能实现接口等,所以你不能简单地为这两个目的使用相同的定义.

Yes, because the type system rules are very different for input and output types. Input types can not be unions, can not implement interfaces etc, so you can not simply use the same definition for both purposes.

此外,您必须为每种类型指定一个唯一名称.所以它应该是 EmployeeEmployeeInput 例如.

Moreover, you must give each type a unique name. So it should be Employee and EmployeeInput for example.

这篇关于我应该在 graphql 模式文件中将每个对象写两次作为“输入"和“类型"吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆