无法在类型 \"WorkOrderType\" 上查询字段 \"serviceTechnician\"

问题描述

查询所有 workorders 时,我无法访问分配给工作订单的 service_technician。

{
  "errors": [
    {
      "message": "Cannot query field \"serviceTechnician\" on type \"WorkOrderType\".","locations": [
        {
          "line": 21,"column": 5
        }
      ]
    }
  ]
}

如果您删除 serviceTechnician,此查询有效:

query workOrders {
  workorders {
    id,sameAsCustomerAddress,relatedCustomer {id,customerName,customerCity {id,locationCity},customerZip},serviceZip
    serviceCity {id,locationCity}
    serviceTechnician
  }
}

用户类型和工作订单类型:

class UserType(UserNode):
    class Meta:
        model = get_user_model()
        filter_fields = app_settings.USER_NODE_FILTER_FIELDS
        exclude = app_settings.USER_NODE_EXCLUDE_FIELDS
        interfaces = (graphene.relay.Node,)
        skip_registry = True

    pk = graphene.Int()
    archived = graphene.Boolean()
    verified = graphene.Boolean()
    secondary_email = graphene.String()

class WorkOrderType(DjangoObjectType):
    class Meta:
        model = WorkOrder
        fields = ('id','same_as_customer_address','service_address','service_city','service_state','service_zip','service_unit_number','service_technician','status','description','computer_brand_type','computer_password','related_customer')

工单输入

class WorkOrderInput(graphene.InputObjectType):
    id = graphene.ID()
    same_as_customer_address = graphene.Boolean()
    service_address = graphene.String()
    service_city = Locationinput()
    service_state = graphene.String()
    service_zip = graphene.String()
    service_unit_number = graphene.String()
    service_technician = graphene.InputField(UserInput)
    status = graphene.String()
    description = graphene.String()
    computer_brand_type = graphene.String()
    computer_password = graphene.String()
    related_customer = Customerinput()

查询resolve_workorder:

    def resolve_workorder(self,info,**kwargs):
        id = kwargs.get('id')

        if id is not None:
            return WorkOrder.objects.get(pk=id)
        
        return None

我真的不知道为什么我无法查询这个字段,我已经在我的 ObjectType、InputObjectType 中定义了它,并且能够创建工单(并分配技术人员),但无法查询它们。

使用Django==3.1.5、django-graphql-auth==0.3.15、django-graphql-jwt==0.3.0、graphene==2.1.8、graphene-django==2.15.0>

架构

input WorkOrderInput {
  id: ID
  sameAsCustomerAddress: Boolean
  serviceAddress: String
  serviceCity: LocationInput
  serviceState: String
  serviceZip: String
  serviceUnitNumber: String
  serviceTechnician: UserInput
  status: String
  description: String
  computerBrandType: String
  computerPassword: String
  relatedCustomer: CustomerInput
}

input UserInput {
  id: ID
  username: String
  email: String
  password: String
}

type UserNode implements Node {
  id: ID!
  lastLogin: DateTime
  username: String!
  firstName: String!
  lastName: String!
  email: String!
  isstaff: Boolean!
  isActive: Boolean!
  dateJoined: DateTime!
  serviceTechnician: [WorkOrderType!]!
  pk: Int
  archived: Boolean
  verified: Boolean
  secondaryEmail: String
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)