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

    LQ

    08/15/2019, 8:39 PM
    becauser
    User
    isn’t an embedded type, you need to specify the relationship between
    User
    and
    Company
  • n

    Neal

    08/15/2019, 8:41 PM
    So how do I specify it to the
    id
    of the user?
  • l

    LQ

    08/15/2019, 8:42 PM
    Copy code
    type User {
        id: ID! @id
    }
    
    type Company {
        id: ID! @id
        createdBy: User
        members: [User!]! @relation(link: INLINE)
    }
  • l

    LQ

    08/15/2019, 8:43 PM
    now you should be able to add
    Users
    to your
    Company
  • n

    Neal

    08/15/2019, 8:43 PM
    Thanks already for the help 👍 . Can you explain what an "embedded" type is?
  • n

    Neal

    08/15/2019, 8:44 PM
    Because don't see a difference between the relation of createdBy or members in the example
  • l

    LQ

    08/15/2019, 8:45 PM
    basically an
    @embedded
    type is something that exists only inside a certain collection/table
  • l

    LQ

    08/15/2019, 8:47 PM
    here’s an example:
    Copy code
    type User {
        id: ID! @id
        profile: UserProfile
    }
    
    type UserProfile @embedded {
       name: String
    }
    
    type Company {
        id: ID! @id
        createdBy: User
        members: [User!]! @relation(link: INLINE)
    }
  • l

    LQ

    08/15/2019, 8:47 PM
    in this example,
    UserProfile
    doesn’t have its own collection/table like
    User
    and
    Company
    does
  • l

    LQ

    08/15/2019, 8:48 PM
    it only exists as the definition of the profile object for a
    User
  • l

    LQ

    08/15/2019, 8:48 PM
    therefore, it’s an embedded type
  • n

    Neal

    08/15/2019, 8:48 PM
    Didn't know that was possible 🙂
  • n

    Neal

    08/15/2019, 8:49 PM
    But in the example I have we don't specify
    @relation
    for
    createdBy
    but we need to for
    members
    , what is the difference then? Because the
    User
    type is not an embedded type
  • l

    LQ

    08/15/2019, 8:50 PM
    good point
  • l

    LQ

    08/15/2019, 8:51 PM
    i have a hard time understanding why it wouldn’t show you an error since you would technically need the
    @relation
    as well
  • l

    LQ

    08/15/2019, 8:51 PM
    but maybe it’s not showing you an error because it’s not specified as required
  • l

    LQ

    08/15/2019, 8:51 PM
    unlike
    members
  • l

    LQ

    08/15/2019, 8:51 PM
    that’s my guess
  • n

    Neal

    08/15/2019, 8:51 PM
    Doesn't
    [User!]!
    mean that it can be empty as well?
  • l

    LQ

    08/15/2019, 8:53 PM
    yes
  • n

    Neal

    08/15/2019, 8:54 PM
    So members is not required then right?
  • l

    LQ

    08/15/2019, 8:54 PM
    an array is required, but the array can be empty
  • n

    Neal

    08/15/2019, 8:55 PM
    So how do I specify the
    @relation
    to the
    id
    of the
    User
    type?
  • n

    Neal

    08/15/2019, 8:56 PM
    This is btw the exact error I receive, it basically says I can only use a relation with a name, so no
    INLINE
    Copy code
    × The relation field `createdBy` must specify a `@relation` directive: `@relation(name: "MyRelation")`
    × The relation field `members` must specify a `@relation` directive: `@relation(name: "MyRelation")`
    l
    j
    • 3
    • 64
  • s

    soren

    08/15/2019, 10:37 PM
    Getting this error when I try to run npm run get-schema
    Your token is invalid.
    Here is my package.json scripts:
    Copy code
    "scripts": {
        "start": "nodemon src/index.js --ext js,graphql --exec babel-node",
        "get-schema": "graphql get-schema -p prisma"
      },
    Here is my .graphqlconfig
    Copy code
    {
      "projects": {
        "prisma": {
          "schemaPath": "src/generated/prisma.graphql",
          "extensions": {
            "prisma": "prisma/prisma.yml",
            "endpoints": {
              "default": {
                "url": "<http://192.168.99.100:4466>",
                "headers": {
                  "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7InNlcnZpY2UiOiJkZWZhdWx0QGRlZmF1bHQiLCJyb2xlcyI6WyJhZG1pbiJdfSwiaWF0IjoxNTY1OTA4MTQ1LCJleHAiOjE1NjY1MTI5NDV9.UWO9S9avS-VzY_g9X3Uqo66qVvQtQsVUZkeT5dngaoA"
                }
              }
            }
          }
        }
      }
    }
    And here is my project architecture:

    https://i.gyazo.com/75f023922fef9a91d8e8f368c69c441f.png▾

  • a

    Andrés Villalobos

    08/16/2019, 1:32 AM
    What would be the best way to do this query on Prisma 1: Delete all users with less than 3 written posts? type User { id: ID! writtenPosts: [Post!]! @relation(name: "WrittenPosts") } type Post { id: ID! author: User @relation(name: "WrittenPosts") content: String! }
    ❓ 1
  • r

    rein

    08/16/2019, 8:46 AM
    is there a way in Nexus to use context to resolve an interface type?
  • a

    Andrei Bacescu

    08/16/2019, 10:00 AM
    aws fargate prisma Hello everybody. In AWS Fargate I run two services, a prisma server and a graphql server (using apollo-server-express, graphql-middleware and cors). I don't understand why I got this error in chrome (v76) everytime I made a request from client side (first image). This is my configuration from server (second image). Thanks in advance for any hint.
    a
    j
    • 3
    • 4
  • a

    Alexander

    08/16/2019, 1:08 PM
    Hello. Unfortunately I am struggling a bit to get calculated fields resolved when using prisma bindings or prisma clients and fragments (works with info object). Imagine I want to calculate a hmac from the email of a User type. I add a custom resolver called hmac in the User resolver and add hmac to the User type in the schema.graphql. Now I can query the hmac from the frontend using the info object and it will be returned without a problem. If however I am trying to resolve / receive this calculated value from a fragment I will receive an error like "Cannot query field 'hmac' on type 'User'." Code: const user: any = await prisma .user({ id: ctx.req.userId, }) .$fragment(
    Copy code
    fragment UserWithPosts on User {
              id
              email
              hmac
            }
    ); What am I doing wrong? How to receive custom resolver values using fragments / the prisma client or binding?
  • c

    Corey Snyder

    08/16/2019, 1:29 PM
    Anyone have any experience trying to export the data from the prisma.io DBs? HOw would one go about doing this if they wanted to migrate from one infrastructure to another?
    a
    • 2
    • 1
1...301302303...637Latest