DEV Community

[Comment from a deleted post]
Collapse
 
dagume profile image
Daniel Guecha

hola Jose, me he encontrdo con un problema de al momento de crear una Interface pero es en la parte de resolver con lightHouse, y que no logro entender, me podrias orientar?, muchas gracias.

I have a problem, I have contacts but it is divided into Person or company, create an interface but at the moment of executing it it generates an error:

#contact types
enum contactType{
    persona @enum(value: 2)
    empresa @enum(value: 3)
}
enum contactIdType{
    cedula @enum(value: 1)
    nit @enum(value: 2)
    pasaporte @enum(value: 3)
    cedula extranjera @enum(value: 4)
}
interface Contact{
    id_contact:ID!
    type:contactType!
    name:String!
    identification_type:contactIdType!
    identification_number:Int!
    email:String!
    phones:String!
    state:Int!
    address:String
    web_site:String
}

type Person implements Contact{
    id_contact:ID!
    id_parent_contact:Int
    id_job:Int
    type:contactType!
    name:String!
    lastname:String
    identification_type:contactIdType!
    identification_number:Int!
    email:String!
    phones:String!
    state:Int!
    address:String
    web_site:String
}

type Company implements Contact{
    id_contact:ID!
    type:contactType!
    name:String!
    identification_type:contactIdType!
    identification_number:Int!
    email:String!
    phones:String!
    state:Int!
    locate:String
    city:String
    address:String
    web_site:String
}

Query:

type Query {    
    #Contacts
    contacts: [Contact!]! @all(model: "App\\Contact")
    contacts_paginator: [Contact]! @paginate(type: "paginator" model: "App\\Contact")
    contact(name: String! @eq): Contact @find(model: "App\\Contact")

}

///////////////////////////////////////////////////////

query{
  contacts{
    name
    type     
  }
}


`
result:

`

{
  "errors": [
    {
      "debugMessage": "Abstract type Contact must resolve to an Object type at runtime for field Query.contacts with value \"{\"id_contact\":4,\"id_parent_contact\":null,\"id_job\":null,\"type\":2,\"name\":\"Laura\",\"lastname\":\"Sanchez\",\"identification_type\":1,\"identification_number\":1049342129,\"email\":\"laura@gmail.com\",\"phones\":\"3203428890\",\"state\":1,\"locate\":null,\"city\":null,\"address\":null,\"web_site\":null}\", received \"Contact\". Either the Contact type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.",
      "message": "Internal server error",
      "extensions": {
        "category": "internal"
      },
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "contacts",
        0
      ]


`

i am working with laravel lighthouse