https://www.prisma.io/ logo
Join SlackCommunities
Powered by
# orm-help
  • a

    ahebwa49

    04/11/2019, 6:53 AM
    here is the resolver for it
    Copy code
    async order(root, args, context, info) {
        //1. make sure they are logged in.
        if (!context.request.userId) {
          throw new Error("You must be logged in.");
        }
        //2. query the current order.
        const order = await context.prisma.order({
          id: args.id
        }).$fragment(`{
          user{
            id
          }
        }`);
        //3. check if they ahve the permissions to see this order
        const ownsOrder = order.user.id === context.request.userId;
        const hasPermissionToSeeOrder = context.request.user.permissions.includes(
          "ADMIN"
        );
        if (!ownsOrder || !hasPermissionToSeeOrder) {
          throw new Error("You don't have permissions to see this.");
        }
        //4. return the order.
        return order;
      }
    n
    j
    • 3
    • 8
  • a

    ahebwa49

    04/11/2019, 6:55 AM
    here is the query in the frontend with apollo client
    Copy code
    const SINGLE_ORDER_QUERY = gql`
      query SINGLE_ORDER_QUERY($id: ID!) {
        order(id: $id) {
          id
          charge
          total
          createdAt
          user {
            id
          }
          items {
            id
            title
            description
            price
            image
            quantity
          }
        }
      }
    `;
  • a

    ahebwa49

    04/11/2019, 6:56 AM
    here is how i modified my index.js to allow for custom resolvers
    Copy code
    const resolvers = {
      Query,
      Mutation,
      ItemConnection: {
        aggregate: (parent, args, context, info) => {
          return context.prisma.itemsConnection(args).aggregate();
        }
      },
      User: {
        cart(parent, args, context, info) {
          return context.prisma.user({ id: context.request.userId }).cart();
        }
      },
      CartItem: {
        item(parent, args, context, info) {
          return context.prisma.cartItem({ id: parent.id }).item();
        }
      },
      Order: {
        user(parent, args, context, info) {
          return context.prisma.order({ id: parent.id }).user();
        }
      },
      Order: {
        items(parent, args, context, info) {
          return context.prisma.order({ id: parent.id }).items();
        }
      }
    };
    n
    • 2
    • 10
  • a

    ahebwa49

    04/11/2019, 6:57 AM
    here is the order type in the datamodel
    Copy code
    type Order {
      id: ID! @unique
      items: [OrderItem!]!
      total: Int!
      user: User!
      charge: String!
      createdAt: DateTime!
      updatedAt: DateTime!
    }
  • a

    ahebwa49

    04/11/2019, 7:04 AM
    @Harshit
  • b

    boennemann

    04/11/2019, 10:05 AM
    Hey all, is there some sort of api reference documentation for
    .$subscribe
    ? This one here is a bit to basic for me: https://www.prisma.io/docs/prisma-client/features/realtime-JAVASCRIPT-rsc8/ It doesn't paint a really good picture of all the possible options, and I can't find them documented anywhere. I'm trying to do subscriptions and get information on which fields changed. Right now I'm just getting the full object, with no indication of what actually changed … and that's a bit useless. Thanks for any pointers šŸ™
    • 1
    • 3
  • n

    Nelson Pecora

    04/11/2019, 2:27 PM
    Hi all. I'm poking at the prisma admin view and I'm seeing a weird issue: It thinks a string I'm saving is null http://up.keats.me/916cda6cab9a
  • n

    Nelson Pecora

    04/11/2019, 2:27 PM
    here's the SDL for that:
    Copy code
    type Action {
      id: ID! @unique
      event: EventType! @default(value: "CREATED")
      userID: String! # TODO: Pull user data from other db.
      timestamp: DateTime!
      state: Json!
    }
    j
    h
    • 3
    • 7
  • a

    ahebwa49

    04/11/2019, 2:57 PM
    Hi all, I'm trying to query for a list of orders from my prisma backend and I'm being hunted by the error that
    [GraphQL error]: Message: Could not find argument user for type Order, Location: [object Object],
  • a

    ahebwa49

    04/11/2019, 2:57 PM
    as shown in the screenshot below.
  • a

    ahebwa49

    04/11/2019, 2:58 PM
  • a

    ahebwa49

    04/11/2019, 3:00 PM
    Here is the resolver for the orders query where i connect the user from the request on context
    Copy code
    orders(root, args, context, info) {
        const { userId } = context.request;
    
        if (!userId) {
          throw new Error("You must be logged in to do this");
        }
        
        return context.prisma.orders({
          user: { id: context.request.userId }
        });
      }
    n
    • 2
    • 3
  • a

    ahebwa49

    04/11/2019, 3:01 PM
    here is the query in my frontend app with apollo client
    Copy code
    const USER_ORDERS_QUERY = gql`
      query USER_ORDERS_QUERY {
        orders(orderBy: createdAt_DESC) {
          id
          total
          createdAt
          items {
            id
            title
            description
            price
            quantity
            image
          }
        }
      }
    `;
  • a

    ahebwa49

    04/11/2019, 3:03 PM
    here is the
    orders
    field in the schema on the query root type
    Copy code
    type Query {
      users: [User]!
      items(
        where: ItemWhereInput
        orderBy: ItemOrderByInput
        skip: Int
        first: Int
      ): [Item!]!
      item(id: ID!): Item
      profile: User
      itemsConnection(where: ItemWhereInput): ItemConnection!
      cart(where: CartItemWhereUniqueInput!): CartItem!
      order(id: ID!): Order
      orders(orderBy: OrderOrderByInput): [Order]!
    }
  • a

    ahebwa49

    04/11/2019, 3:03 PM
    here is my order type in the datamodel
    Copy code
    type Order {
      id: ID! @unique
      items: [OrderItem!]!
      total: Int!
      user: User!
      charge: String!
      createdAt: DateTime!
      updatedAt: DateTime!
    }
  • a

    ahebwa49

    04/11/2019, 3:04 PM
    Somebody bail me out please.
  • a

    Alex

    04/11/2019, 3:37 PM
    Is there a recommended way to generate an introspection.json file without a running server?
    h
    • 2
    • 4
  • s

    schickling

    04/11/2019, 4:59 PM
    Looking forward to seeing many of you here! šŸ™Œ germany parrot https://www.prisma.io/blog/announcing-prisma-day-50cg22nn40qk
    fast parrot 8
    šŸš€ 7
    šŸ™Œ 7
  • t

    thecrazyhoodie

    04/11/2019, 5:02 PM
    I forgot that I had slack installed lol
  • d

    dnbkr

    04/11/2019, 5:15 PM
    @schickling will there be any video recording or livestream?
    s
    • 2
    • 1
  • s

    Saidy Barry

    04/11/2019, 5:29 PM
    can anyone direct me to a article that can help connect my frontend to the graphql server
    a
    • 2
    • 1
  • n

    Nelson Pecora

    04/11/2019, 5:59 PM
    does anyone have any best practices when writing resolvers? I feel like mine are.....verbose, to say the least.
  • n

    Nelson Pecora

    04/11/2019, 5:59 PM
    this has been helpful https://www.prisma.io/tutorials/a-guide-to-common-resolver-patterns-ct08/#scenario:-implementing-relations-with-prisma-client
  • n

    Nelson Pecora

    04/11/2019, 6:01 PM
    er, specifically when writing mutations. Queries are really straightforward with prisma-client
  • n

    Nelson Pecora

    04/11/2019, 6:03 PM
    e.g. http://up.keats.me/ffceae68c1a0
    • 1
    • 3
  • a

    Andy Dietler

    04/11/2019, 6:38 PM
    docker-compose.yml
    j
    • 2
    • 9
  • r

    rwatts3

    04/11/2019, 7:09 PM
    is there a status update on the MS SQL connector ?
  • j

    James

    04/12/2019, 6:25 AM
    Is minifying by removing newlines and multiple spaces in my queries safe? I have been running
    query.replace(/\s+/g, ' ')
    in my javascript client and haven't had any problems, but I don't perfectly understand the requirements on the server and wonder if I will run into unexpected bugs later.
  • s

    sid bhatta

    04/12/2019, 7:00 AM
    does anyone know how to represent multiple level nesting in form of prisma datamodel. for example -> categories has multiple questions and questions has multiple answers for eg: categories { question answer questions answer }
  • j

    James

    04/12/2019, 7:05 AM
    Your data model would define a categories type with a question field. That question field would correspond to a seperate Question type which would have an answer field relating it to a third type called answer, or just an array of strings
1...250251252...637Latest