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

    wuichen

    02/20/2019, 10:03 AM
    hi im trying to figure out how to update many to many relations. this is my schema
    Copy code
    type Product @model {
      id: ID! @unique
      objectID: String! @unique
      title: String!
      vendor: String
      productType: String
      categories: [String!]!
      hierarchicalCategories: Json
      createdAt: DateTime!
      updatedAt: DateTime!
      productTags: [String!]!
      price: Float
      priceRange: String
      productImage: String
      handle: String
      sites: [Site!]! @relation(name: "SitesProducts")
    }
    
    type Site @model {
      id: ID! @unique
      createdAt: DateTime!
      name: String!
      posts: [Post!]! @relation(name: "SiteOnPost")
      products: [Product!]! @relation(name: "SitesProducts")
      template: String
      user: User! @relation(name: "UserOnSite")
    }
  • w

    wuichen

    02/20/2019, 10:04 AM
    and this is my nodejs code
    Copy code
    async addProduct(parent, args, context) {
        const productExists = await context.prisma.$exists.product({
          id: args.productId
        });
        const siteExists = await context.prisma.$<http://exists.site|exists.site>({
          id: args.siteId
        });
        console.log(productExists, siteExists);
        return context.prisma.updateProduct({
          data: {
            sites: {
              connect: {
                id: args.siteId
              }
            }
          },
          where: {
            id: args.productId
          }
        });
      },
    j
    h
    • 3
    • 9
  • w

    wuichen

    02/20/2019, 10:04 AM
    i dont get why its not working
  • w

    wuichen

    02/20/2019, 10:05 AM
    this is the result from the query
  • w

    wuichen

    02/20/2019, 10:05 AM
    Copy code
    {
      "data": {
        "addProduct": {
          "id": "cjscyznfh00m00855o231856w",
          "sites": null
        }
      }
    }
  • b

    Brian

    02/20/2019, 11:12 AM
    I would like to check for correct auth/permissions before a user can access my Prisma forwardTo(‘db’) API
    Copy code
    posts: forwardTo('db')
    What’s the best approach to handle this?
    j
    h
    • 3
    • 3
  • a

    ahebwa49

    02/20/2019, 12:17 PM
    Hi guys
  • a

    ahebwa49

    02/20/2019, 12:18 PM
    How do you auto-generate the Resolver types in typescript after adding a mutation or query root field in the schema?
    h
    • 2
    • 2
  • l

    lewisedc

    02/20/2019, 1:34 PM
    I have a products type which has a relationship to a designers type and a relationship to a colors type, is it possible make a query to products to get a list/array of all designers on products that are blue?
    h
    • 2
    • 22
  • d

    dan

    02/20/2019, 2:35 PM
    Is anyone using Prisma in Production and dealing with the HUGE required field migrations flaw?
    h
    • 2
    • 1
  • d

    dan

    02/20/2019, 2:36 PM
    Looking for a deployment flow when adding new fields that are required in the datamodel, so far its a 3 step process that would be hard to automate with CircleCI
  • l

    Lars-Jørgen Kristiansen

    02/20/2019, 2:38 PM
    How is the n+1 problem solved with prisma? I tried running a query:
    Copy code
    query {
      workspaces {
        id
        title
        workers {
          id
          name
        }
      }
    }
    Resolvers:
    Copy code
    {
      Query: {
        workspaces: (parent, args, ctx) => {
          return ctx.prisma.workspaces();
        }
      },
      Workspace: {
        workers: (parent, args, ctx) => {
          return ctx.prisma
            .workspace({
              id: parent.id
            })
            .workers();
        }
      }
    }
    But looking at the debug output it does'nt seem to solve the problem at all:
    Copy code
    Query:
    {
      workspaces {
        id
        title
      }
    }
    
    
    Query:
    query ($where: WorkspaceWhereUniqueInput!) {
      workspace(where: $where) {
        workers {
          id
          name
        }
      }
    }
    
    Variables:
    {"where":{"id":"cjsd9u584000b07629ei22dpc"}}
    
    Query:
    query ($where: WorkspaceWhereUniqueInput!) {
      workspace(where: $where) {
        workers {
          id
          name
        }
      }
    }
    
    Variables:
    {"where":{"id":"cjsdab6s8000p0762vxhtca4d"}}
    Am i doing something wrong?
    👍 1
  • l

    Luca

    02/20/2019, 2:49 PM
    Nope, Prisma sadly doesn't optimize this yet (but plans to do so in the future), also see https://github.com/prisma/prisma/issues/4029
  • l

    Lars-Jørgen Kristiansen

    02/20/2019, 2:53 PM
    Really?! What do the mean when they say:
    Prisma client has a built-in dataloader, solving the N+1 problem and ensuring the Prisma API is queried efficiently.
    🤔 1
    d
    t
    • 3
    • 8
  • u

    Uby

    02/20/2019, 3:12 PM
    can you use more than one prisma endpoint with prisma-nexus?
    w
    • 2
    • 4
  • r

    rem

    02/20/2019, 4:01 PM
    Has anyone had issues with subscriptions not firing? I'm using them to trigger welcome emails for users, but inconsistently don't always fire.
    h
    • 2
    • 27
  • d

    dortega3000

    02/20/2019, 4:09 PM
    Hi Prisma team, Is the following repo mantained https://github.com/prisma/serverless-plugin-typescript. I have a pull request sitting there for a while. If you guys dont have time to mantain it I could do it as it needs some fixes 🙂 Thanks -David
    t
    • 2
    • 1
  • a

    ahebwa49

    02/20/2019, 4:57 PM
    Hi guys, i don't know if anyone can help me trace this bug or solve this error I'm getting in the palyground
    h
    • 2
    • 1
  • a

    ahebwa49

    02/20/2019, 4:57 PM
    Copy code
    {
      "data": null,
      "errors": [
        {
          "message": "context.request.get is not a function",
          "locations": [
            {
              "line": 2,
              "column": 3
            }
          ],
          "path": [
            "profile"
          ]
        }
      ]
    }
  • a

    ahebwa49

    02/20/2019, 4:58 PM
    here is my helper function
  • a

    ahebwa49

    02/20/2019, 4:58 PM
    Copy code
    import jwt from "jsonwebtoken";
    
    import { Context } from ".";
    
    export const APP_SECRET = "GraphQL-is-awesome";
    
    export function getUserId(context: Context): string {
      const bearerToken = context.request.get("Authorization");
    
      if (!bearerToken) {
        throw new Error("Not Authenticated");
      }
    
      const token: string = bearerToken.replace("Bearer", "");
    
      const userId: string = jwt.verify(token, APP_SECRET) as string;
    
      return userId;
    }
    i
    • 2
    • 1
  • a

    ahebwa49

    02/20/2019, 4:59 PM
    @Harshit
  • j

    Jon

    02/20/2019, 5:55 PM
    Hey everyone, I have a bit of an elementary question here. I have an app where you can signup, and then create a property. the /properties page is a list of all the properties you have created. My issue is now is all of these properties are visible to every user (whether or not they created the property or not). How do I only display properties that were created by that user? Is there a common pattern for this anywhere? I created the connection in my resolver, so the database is aware of which properties belong to who. Any tips would be great 🙂
    h
    d
    • 3
    • 12
  • t

    tiagomarques

    02/20/2019, 8:29 PM
    Hello there, So I finished my course of GraphQL + Prisma + Postgres, and I don’t know if I am ready to change NodeJS + Mongoose + MongoDB… to GraphQL + Prisma. Because my job is related to Web API and offline API, and when I use GraphQL I have to write the NodeJS layer yet, so why should I use ? I think the only positive point, it is because I can fetch all data that I need in just one request, is it really an advantage that makes me change how I work ? I am confused ? What do you think about it ?
    h
    • 2
    • 3
  • t

    tiagomarques

    02/20/2019, 8:31 PM
    * So, when I write an API using GraphQL + Prisma, I have to use Apollo client, and a converter of graphql query to a .get or .post request, this is more code in my app.
  • l

    Lars-Jørgen Kristiansen

    02/20/2019, 9:26 PM
    Any one using prisma in a multi-tenant setup?
    l
    j
    +3
    • 6
    • 44
  • m

    Matthew Frey

    02/21/2019, 12:31 AM
    Ding dong can someone please look at this PR? It's probably breaking a lot of packages for a lot of people... https://github.com/prisma/graphql-playground/pull/960
    h
    h
    • 3
    • 3
  • m

    Matthew Frey

    02/21/2019, 12:31 AM
    Zero comments for 12 days now both on the issue and the PR
  • t

    tafelito

    02/21/2019, 4:04 AM
    qq on subscriptions that I didn’t find in the documentation. Are the subscriptions supposed to trigger If I the database is updated outside of prisma? I have 2 servers that are connected to the same DB. I want my prisma client to receive the sub events when anything is updated on the DB. Is this possible to do?
  • m

    Martí Crespí

    02/21/2019, 8:23 AM
    Hi to all! Is possible to overwrite a string property from SDL and expose it as enum with nexus? I have tried this code, hiding the main
    type
    string property, and creating a new one based on an enum. But when I try a query, when it's parsing the response, it throws an error.
    "Expected a value of type \"CostType\" but received: \"MAINTENANCE\"",
    because it's not converting the string to the enum. How can I do it in its resolve function to convert this string to its enum?
    -.cpp
1...214215216...637Latest