GraphQL standard for querying by various IDs
I have the following entities:
company
role
user
A company has many roles, and a role has many users. I’m trying to build a GraphQL query which allows someone to query a company by the role Id. My initial thought is to build a companyByRoleId
query, but wanted to double check that this method is best practice. In the example schema below, is companyByRoleId
the best practice, or is there a better way to allow consumers to query the company that the role belongs to?
type Company {
id: ID!
name: String
roles: Role[]
}
type Role {
id: ID!
name: String
users: User[]
}
type User {
id: ID!
name: String
}
query($roleId: ID!){
companyByRoleId(roleId: $roleId){
id
name
}
}
query($companyId: ID!){
companyById(companyId: $companyId){
id
name
}
}
query($userId: ID!){
companyByUserId(userId: $userId){
id
name
}
}
Read more here: Source link