Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Does not generate resolvers for relation fields #466

Open
Elijen opened this issue Mar 12, 2019 · 0 comments
Open

Does not generate resolvers for relation fields #466

Elijen opened this issue Mar 12, 2019 · 0 comments

Comments

@Elijen
Copy link

Elijen commented Mar 12, 2019

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

  • graphqlgen: 0.6.0-rc9
  • OS name and version: macOS 10.14.2
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant