Closed raleigh9123 closed 3 years ago
Additionally, these are the relevant gql schemas from the generated schema.graphql.
enum SortOrder {
asc
desc
}
input OrderBy {
createdAt: SortOrder!
updatedAt: SortOrder!
id: SortOrder!
}
type User {
# User id by integer. Auto-generated and auto-incremented
id: Int!
# User id by string. Auto-generated and auto-incremented. Machine-readable only
uuid: String!
# User created at date
createdAt: DateTime!
# User updated at date
updatedAt: DateTime!
# User First Name
firstName: String!
# User Last Name
lastName: String!
# User's full email address
email: String!
# Athlete membership is active or inactive.
status: UserStatus!
# This is a list of clients that this user may belong to. Typically users have one client, but with a few exceptions may belong to more than one.
clients: [Client]!
# User role for application permissions
role: UserRole!
# User profile with additional user information
profile: Profile
}
type Profile {
# Profile id by integer. Integer matches profile creation.
id: Int!
# Profile Prisma-generated UUID. Not intended to be human readable.
uuid: String!
# User address number
address: String
# User city
city: String
# User state
state: String
# User zip code
zip: Int
# User country
country: CountryCode
# User cell phone number
phoneNumber: String
# User WhatsApp number
whatsApp: String
# User birthday
dateOfBirth: DateTime
# User emergency contact first name and last name
emergencyContact: String
# User emergency contact phone number
emergencyPhoneNumber: String
}
enum UserRole {
USER
ADMIN
OWNER
}
enum UserStatus {
ACTIVE
INACTIVE
}
enum CountryCode {
United_States
India
}
type Client {
# Client id by integer. Auto-generated and auto-incremented
id: Int!
# Client id by string. Auto-generated and auto-incremented. Machine-readable only
uuid: String!
# Client created at date
createdAt: DateTime!
# Client updated at date
updatedAt: DateTime!
# This is the name of the client (e.g. Typically a facility/business name).
clientName: String!
# The email account used for the primary business facility. If the owner or admin also has a user account, that user must have a different, unique email address.
email: String!
# All of the client's users. This list is populated with current and inactive users.
users: [User]!
}
type Query {
# Return all users. Allows filtering, pagination, and sorting.
allUsers(
searchString: String
skip: Int
take: Int
orderBy: OrderBy
): [User!]!
}
This is not a problem with nexus, but let me answer so it might help other people.
The problem is that you are not using custom resolvers for the relations in your model.
This means that allUsers
must supply the exact that form that the graphql is expecting, but you are using a join table between your two models (UsersOnClient
). So when you do a findMany you dont have a list of clients (what graphql is expecting), but you have a listof UsersOnClient objects. You need to map them either in the parent resolver or you need to change the source typing so you can map them in the children resolver.
I am trying to build something akin to a CMS. So far, all I am trying to setup are clients and users via an EXPLICIT many-to-many relationship. In my nexus defined schema where I implement resolvers, I run in to errors in my VS Code console.
I am unsure whether these errors are from conflicts via my nexus "objectType()" properties, or whether I am incorrectly writing Query/Mutation resolvers from my defined objectType() definitions.
My prisma.schema is as follows:
My User.ts/Client.ts files are imported to my schema.ts where I then import User.ts and Client.ts as types and run the makeSchema() function.
// User.ts --> I did write an "include: { NESTED READ }" to retrieve the information for the explicit (m-n) relationship, however, I am unsure if this is how to properly select this field from 'USERS' or if I should write an additional interface to reflect the schema.prisma "UsersOnClient" model.
// Client.ts
I get quite a long error message in my console from the query 'allUsers'. I'm not sure where to start since the error message is so long, however I will note that whenever I remove the
.nonNull.SCALAR
from my objectType() declaration, this error does go away completely.TS Error in VS Code
I did remove some objectType definitions to make my problem more straightforward. I've been wracking my head about trying to solve this and am frustrated at how simple Nexus and Prisma seem to be, yet after writing the code end up plagued by typescript errors that don't often have clear solutions.
My problems are as follows: