php - 解析查询时是否可以在内部查询架构?
问题描述
我正在用 laravel 和 laravel-lighthouse 构建一个 api。我编写了一个类型系统,您可以在其中注册“人员”或“组织”等类型并将字段附加到它们。这些类型存在于我的数据库中,由我的 lighthouse graphql 实现创建和读取。然后,这些“虚拟”类型会按照lighthouse 文档中的描述注册到模式中。我有查询和突变
- 读取和操作类型(或类,如果你想这样称呼它们)
- 读取和操作实例(在抽象级别上)
type Query {
objectTypes(
orderBy: [ObjectTypesOrderByOrderByClause!]
first: Int = 10
page: Int
): ObjectTypePaginator
attributeTypes(
orderBy: [attributeTypesOrderByOrderByClause!]
first: Int = 10
page: Int
): AttributeTypePaginator
objects(
orderBy: [ObjectsOrderByOrderByClause!]
first: Int = 10
page: Int
): ObjectPaginator
attributes(
orderBy: [AttributesOrderByOrderByClause!]
first: Int = 10
page: Int
): AttributePaginator
}
type Mutation {
createObjectType(input: CreateObjectTypeInput!): ObjectType!
createAttributeType(input: CreateAttributeTypeInput!): AttributeType!
updateObjectType(input: UpdateObjectTypeInput!): ObjectType!
updateAttributeType(input: UpdateAttributeTypeInput!): AttributeType!
deleteObjectType(input: DeleteObjectTypeInput!): ObjectType!
deleteAttributeType(input: DeleteAttributeTypeInput!): AttributeType!
createObject(input: CreateObjectInput!): Object!
createAttribute(input: CreateAttributeInput!): Attribute!
updateObject(input: UpdateObjectInput!): Object!
updateAttribute(input: UpdateAttributeInput!): Attribute!
deleteObject(input: DeleteObjectInput!): Object!
deleteAttribute(input: DeleteAttributeInput!): Attribute!
}
在下一步中,我想注册查询和突变以直接管理这些类型的实例(例如createPerson(input: CreatePersonInput!): Person!
)。我认为合适的是为每个处理所有对象类型的 CRUD 方法创建一个解析器,但不是重新实现我为操作抽象对象实例而编写的所有检查和验证,而是我想查询现有的查询和突变和将结果呈现为适当的对象。
TL;博士
我可以通过查询架构来解决查询和突变而不发出额外的 http 请求(分别在内部)
解决方案
推荐阅读
- javascript - html 标记字面上显示在浏览器中
- python - 在 matplotlib 中绘制多个图时出现索引错误
- php - 如何制作通用函数以将嵌套对象减少为 CSV 样式数组?
- c++ - 在类设计中查找外部命名空间中的重载运算符
- javascript - 编写 1 个 JavaScript 语句,该语句将从文本框中获取文本,并在单击按钮时使用它来设置段落的边框
- multiple-monitors - 我想在 2 台显示器上播放视频 uipath
- .net - ASP.NET MVC 5 与 ASP.NET Core
- javascript - 我有两个相同的 html 输入文本 id 但不同的 div 如何在 jquery 中获取两个 id 值
- windows - 如何解决函数 GsDriverEntry 中引用的 LNK2019 未解析的外部符号 DriverEntry?
- javascript - How do I print a reversed times table in Javascript