How can I modify the top code to get both user and...
# orm-help
s
How can I modify the top code to get both user and posts? The bottom one doesn't feel very intuitive.
m
Use the .$fragment() method to pass the fields you want. Here's a snippet from my codebase that demonstrates this
Copy code
const brokerageWithOwnerAndPositions = gql`
  fragment BrokerageAccountOwnedPositions on BrokerageAccount {
    id
    accountId
    provider
    owner {
      id
      username
    }
    positions {
      id
      symbol
      symbolClass
      holdingType
      quantity
      costbasis
    }
    orders {
      id
    }
  }
`

export const brokerageAccountsWithOwnerAndPositions = async (
  args?: PrismaQueryArgs<
    BrokerageAccountWhereInput,
    BrokerageAccountOrderByInput
  >
): Promise<AHBrokerageAccount[]> =>
  prisma
    .brokerageAccounts(args)
    .$fragment<AHBrokerageAccount[]>(brokerageWithOwnerAndPositions)