微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决无法在类型 \"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 举报,一经查实,本站将立刻删除。