Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Issue] SDL Generators Not Mapping relationship #647

Closed
BurnedChris opened this issue Jun 3, 2020 · 3 comments
Closed

[Issue] SDL Generators Not Mapping relationship #647

BurnedChris opened this issue Jun 3, 2020 · 3 comments

Comments

@BurnedChris
Copy link
Contributor

BurnedChris commented Jun 3, 2020

Good Afternoon,

After a debugging session with @RobertBroersma (thank you!)
We have found out that when using the command rw g XXX --crud

if you have relationships it is possible for them not to be mapped properly resulting in the field returning as null.

example sdl

export const schema = gql`
  type User {
    id: Int!
    email: String!
    publicAddress: String!
    issuer: String!
    firstName: String
    secondName: String
    avatarPublicId: String
    onboarding: UserOnboarding
    onboardingId: Int
    createdAt: DateTime!
    updatedAt: DateTime!
  }

  type UserOnboarding {
    id: Int!
    hasAvatar: Boolean!
    hasName: Boolean!
    hasTeam: Boolean!
    user: User
  }

  type Query {
    users: [User!]!
    user(id: Int!): User!
  }

  input CreateUserInput {
    email: String!
    publicAddress: String!
    issuer: String!
    firstName: String
    secondName: String
    avatarPublicId: String
    onboardingId: Int
    updatedAt: DateTime!
  }

  input UpdateUserInput {
    email: String
    publicAddress: String
    issuer: String
    firstName: String
    secondName: String
    avatarPublicId: String
    onboardingId: Int
    updatedAt: DateTime
  }

  type Mutation {
    createUser(input: CreateUserInput!): User!
    updateUser(id: Int!, input: UpdateUserInput!): User!
    deleteUser(id: Int!): User!
  }
`

Function that returns null

import { db } from 'src/lib/db'

export const users = () => {
  return db.user.findMany()
}

export const user = ({ id }) => {
  return db.user.findOne({
    where: { id },
  })
}

// export const createUser = ({ input }) => {}
// export const updateUser = ({ id, input }) => {}
// export const deleteUser = ({ id }) => {}

export const User = {
  userOnboarding: (_obj, { root }) => db.user.findOne({ where: { id: root.id } }).userOnboarding(),
}

Function Fixed that returns data from relationship

import { db } from 'src/lib/db'

export const users = () => {
  return db.user.findMany()
}

export const user = ({ id }) => {
  return db.user.findOne({
    where: { id },
  })
}

// export const createUser = ({ input }) => {}
// export const updateUser = ({ id, input }) => {}
// export const deleteUser = ({ id }) => {}

export const User = {
  onboarding: (_obj, { root }) =>
    db.user.findOne({ where: { id: root.id } }).onboarding(),
}

Notice that Inside the User table the crud commands generate userOnboarding but it needs to be replaced with onboarding to work

@BurnedChris BurnedChris changed the title [Issue] Generators Not Mapping relationship [Issue] SDL Generators Not Mapping relationship Jun 3, 2020
@cannikin
Copy link
Member

cannikin commented Jun 3, 2020

Hmmm...looks like the generator might be using the name of the foreign table itself UserOnboarding rather than the of the name of the relationship onboarding. That's not correct! Marking as a bug.

@cannikin
Copy link
Member

cannikin commented Jun 3, 2020

@cannikin cannikin added bug/confirmed We have confirmed this is a bug good first issue labels Jun 3, 2020
@jtoar jtoar removed this from v1.0 in Generators & Scaffolds May 19, 2021
@jtoar jtoar removed the help wanted label Jun 9, 2021
@jtoar jtoar added this to New issues in Current-Release-Sprint via automation Jun 9, 2021
@jtoar jtoar moved this from New issues to On deck (future-release; help-wanted) in Current-Release-Sprint Jun 9, 2021
@jtoar jtoar removed this from On deck (future-release; help-wanted) in Current-Release-Sprint Jun 10, 2021
@jtoar jtoar added this to Needs confirmation in Triage Jun 10, 2021
@jtoar
Copy link
Contributor

jtoar commented Jun 10, 2021

Fixed in #813 I believe!

@jtoar jtoar closed this as completed Jun 10, 2021
@jtoar jtoar removed this from Needs confirmation in Triage Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants