Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix User redeclaration #274

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lucasavila00
Copy link

When the type is converted by prisma from the datamodel it becomes:

type User implements Node {
  id: ID!
  email: String!
  password: String!
  name: String!
  posts(where: PostWhereInput, orderBy: PostOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Post!]
  role: Role!
}

When redeclaring User to remove the password field, the posts should lose that part from the datamodel.
I caught this using declaration types for the "app" part.
It follows issue #273 but here I'm telling the resolvers what to return, like so

import { Mutation as MutationType } from "../../typings/types";

export const auth = {
  async #(
    parent: never,
    args: #MutationArgs,
    ctx: Context,
    info: never
  ): Promise<MutationType["#"]> {
    const password = await bcrypt.hash(args.password, 10);
    const user = await ctx.db.mutation.createUser({
      data: { ...args, password }
    });

    return {
      token: jwt.sign(
        { userId: user.id },
        invariant<string>("string", process.env.APP_SECRET)
      ),
      user
    };
  },
}

the compiled warned me that createUser returns user[] | undefined but the "app" part was supposed to return user[] as the user data.

When the type is converted by prisma from the datamodel it becomes:
type User implements Node {
  id: ID!
  email: String!
  password: String!
  name: String!
  posts(where: PostWhereInput, orderBy: PostOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Post!]
  role: Role!
}
When redeclaring User to remove the password field, the posts should lose that part from the datamodel.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant