-1

I am using lighthouse-php with laravel. I need to use type Employee in multiple queries and in different schemas. In some cases Employee can have extra fields.

#employee.graphql

type Employee{
  id: ID
  name: String
}


#company.graphql

extend type Employee{
  loginCount: ID
}

Is this good approach? Please suggest me if there is any better way to do this.

Arun
  • 344
  • 2
  • 11

1 Answers1

4

Yes. This is a perfectly acceptable way of doing it although your example is maybe a bit less perfect. Consider something like this though:

# employee.graphql

type Employee {
  id: ID!
  name: String!
}

# company.graphql

type Company {
  id: ID!
  name: String!
}

extend type Employee {
  company: Company! @belongsTo
}

The loginCount attribute in your example did not seem related to the company.graphl, so for your own sanity try to keep related items grouped.

But having all company related fields and queries in a single file makes a lot of sense especially on bigger schema's.

One sidenote, the added field (loginCount in your example and company in mine) is added to the Employee type wherever you are using it, it's not like that added field is only available within company.graphql. When building the final schema all extend * types are merged together to a single Employee type so the end result of the above results in this schema:

type Employee {
  id: ID!
  name: String!
  company: Company!
}

type Company {
  id: ID!
  name: String!
}

Hope it all makes sense!

Alex
  • 1,425
  • 11
  • 25