首页 > 解决方案 > 解析查询时是否可以在内部查询架构?

问题描述

我正在用 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 请求(分别在内部)

标签: phplaravellaravel-lighthouse

解决方案


推荐阅读