I've been wrestling (and loosing) with the GraphQL...
# orm-help
p
I've been wrestling (and loosing) with the GraphQL-NextJS example trying to add the "Profile" table and type. Specifically, after I think I've updated all the code correctly, the code in the mutation fails and I get the error:
"Cannot read property 'profile' of undefined",
I notice that the profile adding instructions are the same for all the other examples (or at least for the Profile add). My question is: "Does anyone of completed code that works for adding a Profile, and specifically the first mutation in the example? After debugging some, the code in the mutation that seems to be problematic is here in the line
context.prisma.profile.create
Copy code
t.field("addProfileForUser", {
  type: "Profile",
  args: {
    email: stringArg(),
    bio: stringArg(),
  },
  resolve: async (_, args, context) => {
    return context.prisma.profile.create({
      data: {
        bio: args.bio,
        user: {
          connect: {
            email: args.email || undefined,
          },
        },
      },
    });
  },
Copy code
mutation {
  addProfileForUser(
    userUniqueInput: {
      email: "<mailto:mahmoud@prisma.io|mahmoud@prisma.io>"
    }
    bio: "I like turtles"
  ) {
    id
    bio
    user {
      id
      name
    }
  }
}
r
@Peter Kellner đź‘‹ One issue that I can see here is that you are requesting the
user
as well. Are you returning that someplace else?
p
I did figure it and created a pull request to fix (very aggravating). prisma needs to be global so it should not be
context.prisma.profile.create
but instead just
prisma.profile.create
. I had thought prisma was showing undefined because of a debugger weirdness, but turns out, it really was undefined. As this example also uses getInitialProps inside _app.js,it’s and HOC’s instead of hooks for the apollo client, it really needs an overhaul. I asked about it this morning in the Prisma day / nextjs talk and the response I got was “I don’t really like Apollo, use swr instead”. Arg
r
Why is
prisma
in your context
undefined
? Could you share the code where you have passed the context? Yeah I would suggest looking at my example. You would just need to replace Mercurius with Apollo