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

    夏の雪Official

    10/26/2022, 6:58 PM
    Hi, can I turn off autocreate db schema in my database? Because as I understand Prisma create table, but I don’t want this (I’ll create tables in my db).
  • m

    Marcus

    10/26/2022, 7:16 PM
    I’m following https://www.prisma.io/docs/guides/testing/unit-testing and struggling to get a successful test. Are there better tutorials?
    • 1
    • 1
  • j

    John Bradens

    10/27/2022, 1:08 AM
    Hi, I hope this is in the right place. I'm very new to all this. I want to show the name of the logged in user. I have this: `const ME_QUERY = gql``
    {
    me {
    id
    name
    }
    }
    ;
    and when I do
    const { data } = useQuery(ME_QUERY);
    console.log(data);
    I get undefined. Please let me know if you'd like me to share any more info
  • j

    John Bradens

    10/27/2022, 1:09 AM
    I'm trying to follow along with the prisma/apollo graphql tutorial, and trying to add thigns on my own to solidify the concepts in my brain
  • j

    John Bradens

    10/27/2022, 1:10 AM
    I also have this in query.js:
    function me(parent, args, context) {
    const id = getUserId(context);
    return context.prisma.user({ id });
    }
  • j

    John Bradens

    10/27/2022, 1:16 AM
    I guess a more simple question is how to even get the ME_QUERY working in the playground? If I log in with a user, and then in the playground I do
    query {
    me {
    id
    name
    }
    }
    , I get errors. How do I get it to show me the username that is logged in?
  • j

    John Bradens

    10/27/2022, 2:58 AM
    Can anyone please help me understand the difference between these two functions? Why does one take context and one takes request? (Sorry if this isn't a prisma specific question - if I need to ask for help in a more appropriate place, please let me know & my apologies in advance):
    j
    • 2
    • 5
  • j

    John Bradens

    10/27/2022, 2:59 AM
    Copy code
    function getUserId(context) {
      const Authorization = context.request.get("Authorization");
      console.log("hello");
      console.log(context.request);
      if (Authorization) {
        const token = Authorization.replace("Bearer ", "");
        const { userId } = jwt.verify(token, process.env.APP_SECRET);
        return userId;
      }
    
      throw new AuthError();
    }
    
    class AuthError extends Error {
      constructor() {
        super("Not authorized");
      }
    }
    
    // function getUserId(req, authToken) {
    //   if (req) {
    //     const authHeader = req.headers.authorization;
    //     if (authHeader) {
    //       const token = authHeader.replace("Bearer ", "");
    //       if (!token) {
    //         throw new Error("No token found");
    //       }
    //       const { userId } = getTokenPayload(token);
    //       return userId;
    //     }
    //   } else if (authToken) {
    //     const { userId } = getTokenPayload(authToken);
    //     return userId;
    //   }
    
    //   throw new Error("Not authenticated");
    // }
  • c

    Cường Vũ

    10/27/2022, 3:29 AM
    Can anyone please help me, Is there a way to use
    db push
    without losing data ?
    👀 3
    j
    r
    • 3
    • 4
  • n

    Nik

    10/27/2022, 4:13 AM
    anyone know if this is valid prisma code? trying to filter based off two fields
  • n

    Nik

    10/27/2022, 4:45 AM
    I'm trying to find movies released between two dates, with the parameter being optional (that is return all movies if no dates are provided). Any clue what the error is from?
    j
    • 2
    • 1
  • d

    Divya Jain

    10/27/2022, 7:17 AM
    @here Anyone who has faced the issue using Prisma transactions?
    Copy code
    originalError": {
                "is_panic": false,
                "message": "Transaction API error: Transaction already closed: Transaction is no longer valid. Last state: 'Expired'.",
                "meta": {
                    "error": "Transaction already closed: Transaction is no longer valid. Last state: 'Expired'."
                },
                "error_code": "P2028",
                "clientVersion": "3.15.2"
    },
    I have been facing this issue when there are multiple queries in a transaction. I tried to increased the timeout for some its working but for some its not I referred to this thread https://github.com/prisma/prisma/issues/13713. Then I even updated the Prisma version to 4.1.1 that also not helping that also referred from another thread If anyone has any insights on how to resolve it. Please do share.
  • m

    Mark

    10/27/2022, 7:41 AM
    Hi everybody, I’m wondering if anybody of you is strong enough with typescript to help me with a “dynamic service”. (Without typecasting to any). Basically what I want to get is to get the
    findMany
    with a
    Prisma.ModelName.
    But I get the following error:
    Each member of the union type has signatures
    Copy code
    const modelName = 'todoItem';
    
    return client[modelName].findMany(undefined);
    I have a playground here
1...633634635636637Latest