prisma-labs / graphqlgen

⚙️ Generate type-safe resolvers based upon your GraphQL Schema
MIT License
818 stars 54 forks source link

Does not generate resolvers for relation fields #466

Open Elijen opened 5 years ago

Elijen commented 5 years ago

Description

Is this expected behavior? The library was recommended by a Prisma team member as a solution to the need of manually defining resolvers for all relation fields (even to-one), but it does seem to generate these.

Steps to reproduce

Model:

type User {
  id: ID! @unique
  name: String!
  assignedTasks: [Task!]! @relation(name: "UserAssignedTasks")
  createdTasks: [Task!]! @relation(name: "UserCreatedTasks")
}

type Task {
  id: ID! @unique
  title: String!
  assignedTo: User! @relation(name: "UserAssignedTasks")
  createdBy: User! @relation(name: "UserCreatedTasks")
}

Query:

query MyTasks {
   myTasks {
      id
      title
      assignedTo {
         id
         name
      }
   }
}

Query.myTasks resolver:

myTasks(parent, args, ctx: Context) {
  const id = getUserId(ctx);
  return ctx.prisma.tasks({ where: { assignedTo: { id } } });
}

Resolvers:

import { Query } from "./Query";
import { TaskResolvers, UserResolvers } from "../generated/graphqlgen";

export default {
  Query,
  User: UserResolvers.defaultResolvers,
  Task: TaskResolvers.defaultResolvers
};

Expected results

Query returns data successfully and includes the assignedTo field

Actual results

Error is thrown:

Error: Cannot return null for non-nullable field Task.assignedTo.

Versions