Search code examples
phplaravelgraphqllaravel-lighthouse

In lighthouse-php, How can i define a type for a model with a difftent name?


I am using lighthouse package for graphql in laravel, i need to declare a type for a model lets say "ClassA", but the type name must be TypeA, what is the best practice to do so?


Solution

  • You do not add it on the type itself, you add in in the query. So to follow your example you would do

    type TypeA {
       ...
    }
    
    type Query {
     typeA(id: ID @eq): TypeA @find(model: "TypeA")
     typeAs(): [TypeA] @all(model: "TypeA")
    }
    

    You can find it in the docs also.