Is there a way to get the exact object type that is returned from a graphql query instead of the type that is defined in the resolver?

Viewed 129

I have a graphql query that returns an array of users @Query(() => [User]) with missing properties than my schema. Is there a way to get the type of the object in the data that is returned from the query instead of the full reference object in the graphql schema or having to write new type / graphql fragment. In this case it would be the following:

{
    __typename?: "User";
        id: number;
        name: string;
        email: string;
        role: string;
}

instead of this:

export type User = {
  __typename?: "User";
  createdAt: Scalars["String"];
  email: Scalars["String"];
  groups?: Maybe<Array<Group>>;
  id: Scalars["Float"];
  name: Scalars["String"];
  points: Scalars["Int"];
  role: Scalars["String"];
  updatedAt: Scalars["String"];
};

This is my graphql resolver and query:

@Query(() => [User])
      async users(@Ctx() {}: MyContext): Promise<null | User[]> {
        return User.find();
      }

export type UsersQuery = {
  __typename?: "Query";
  users: Array<{
    __typename?: "User";
    id: number;
    name: string;
    email: string;
    role: string;
}};
0 Answers
Related