Search code examples
servergraphqlbackendprisma-graphql

Prisma query fields where value is a string or ID


Sorry, brand new to Prisma queries and trying to figure out the query language syntax.

Given the following call made from my GraphQL / Prisma backend, I'm looking to query {parent: String}. Anything non-null will work here, String isn't accepted, complains about wanting an object. So, it's not types. I also tried { parent_not: null } with no luck. Sorry for the beginner question, can't find this in the docs.

Bonus points, I'll take any help I can get, but would like to know how to query by ID type values.

    const children = await ctx.db.query.comments(
      {
        where: { AND: [{ isPublic: true }, { parent: String }] },
        orderBy: 'createdAt_DESC'
      },
      info
    )

Solution

  • have a look at the schema prisma builds for you graphql get-schema -p prisma, this will give you clues into what's possible. In there, you'll find things like id_in, id_not_in, id_contains etc. You'll also find something like parent_* which will give you and idea what you can query by.

    In this case, what you probably want to do is { parent_not_in: "" }, but { parent_not: "" } would probably work too.