'starting with graphql-problems with queries

Hi I have just started with graphql so bear with me and be very explicit. I have a database in MySQL with a list of departments with the attributes of id, name and array of users. I have explicited that in the schema in this way

type Department {
  id: ID!
  name: String!
  user: [User]
}

then I have created a couple of queries, ie. allDepartments and getDepartment in this way

type Query {
  departments: [Department!]!
  getDept(id: ID!): Department!
}

the resolver functions are those ones

Query: {
    departments: async (parent, args, context) => {
      return context.prisma.department.findMany();
    },
    getDept: async (parent, args, context) => {
      return context.prisma.department.findUnique({
        where: { id: args.id },
      });
    },
  },

however when I query the alldepartments, I get the list but the user array is empty (whereas there is at least one person each) with getDept I manage to get the department only if I hardcode the id in the where obj. how can I implement a query where I can pass the id as argument and have the findunique to catch that particular one? can I use the name of the department instead of the id?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source