anyone using prisma 1.8.3 with prisma-binding 2.0 ...
# orm-help
p
anyone using prisma 1.8.3 with prisma-binding 2.0 and noticing that
ctx.db.exists.Type
always returns true no matter what args? Am I misunderstanding how it is supposed to work?
Copy code
await <http://ctx.db.exists.Post|ctx.db.exists.Post>({
        title: 'blah',
      })
should return false but instead it looks like it is just querying the server for all posts and returning true.
m
Hi, I'm using the same stack and can get exists to return false as expected. Would you mind sharing a bit more of your implementation?
p
sure thing heres my prisma yml
Copy code
endpoint: ${env:PRISMA_ENDPOINT}

secret: ${env:PRISMA_SECRET}

# the file path pointing to your data model
datamodel: datamodel.graphql

# seed your service with initial data based on seed.graphql
seed:
  import: seed.graphql

hooks:
  post-deploy:
    - echo "Deployment finished"
    - graphql get-schema --project database
    - graphql codegen
and graphqlconfig
Copy code
projects:
  app:
    schemaPath: "src/schema.graphql"
    extensions:
      endpoints:
        default: "<http://localhost:4000>"
  database:
    schemaPath: "src/generated/prisma.graphql"
    extensions:
      prisma: database/prisma.yml
      codegen:
      - generator: prisma-binding
        language: typescript
        output:
          binding: src/generated/prisma.ts
heres a resolver
Copy code
async deletePost(parent, { id }, ctx: Context, info) {
    const { userId } = ctxUser(ctx);
    const postExists = await <http://ctx.db.exists.Post|ctx.db.exists.Post>({
      id,
      author: { id: userId },
    });
    if (!postExists) {
      throw new Error(`Post not found or you're not the author`);
    }

    return ctx.db.mutation.deletePost({ where: { id } });
  },
};
this was working for me a few days ago and both query and mutation are working
m
Odd. Recreating your code here throws the error as expected. Your code is just blasting past that?
p
yeah, in my prisma debug logs it’s aways just running a query for
Copy code
query:
{
  posts {
    id
  }
}
no matter what I put in the args
m
That's the intended behavior.
The query is wrapped in a function that returns true or false depending on the results of the query
Here's the code in prisma-binding:
Copy code
private buildExists(): Exists {
    const queryType = this.schema.getQueryType()
    if (!queryType) {
      return {}
    }
    if (queryType) {
      const types = getTypesAndWhere(queryType)

      return types.reduce((acc, { type, pluralFieldName }) => {
        return {
          ...acc,
          [type]: args =>
            this.delegate(
              'query',
              pluralFieldName,
              { where: args },
              buildExistsInfo(pluralFieldName, this.schema),
            ).then(res => res.length > 0),
        }
      }, {})
    }

    return {}
  }
p
yeah but even if I put
<http://ctx.db.exists.Post|ctx.db.exists.Post>({ title: 'fake' })
is still just runs the id query
m
Can you copy and paste the whole debug message?
p
Copy code
Request to <http://localhost:4466/backend/dev>:
query:
{
  posts {
    id
  }
}
operationName: null
variables:
{}
Response from <http://localhost:4466/backend/dev>:
{
  "posts": [
    {
      "id": "cjhf0v2x5000i09817s7dhdhz"
    },
    {
      "id": "cjhf0v2x5000j0981dsjdvnns"
    }
  ]
}
thanks for helping out by the way!
it feels like something isn’t being generated properly
m
No prob. So its definitely weirding me out that your variables are not being reflected in your debug message.
p
same
m
Can you check that both variables are defined
Copy code
let id, ownerId
  const mediaExists = await ctx.db.exists.Media({ id, owner: {id: ownerId} })
returns true for me.
p
at this point I’m hard coding them so yes
m
hm.
p
this is what I’m sending
<http://ctx.db.exists.Post|ctx.db.exists.Post>({ title: 'fake' })
and its not reading the args at all
m
and you're using the TS generator, correct?
p
yeah should be
Copy code
codegen:
      - generator: prisma-binding
        language: typescript
        output:
          binding: src/generated/prisma.ts
even deleted the whole generated folder
m
For the life of me, I cannot recreate 😕
p
yeah this is pretty weird, I can’t really do anything without this working
if you are interested I can show you the full codebase
m
Sure. I have to jump in the car for a bit, but will be online later. Happy to take a look.
p
no problem
maybe you are wrapping your args with where otherwise I’m not sure how it’s working for you
m
It works as advertised with me—no where wrapper required.
So weird.
p
you are using codegen to generate the bindings?
m
Sorry for the delayed response, yes, using codegen to generate the bindings.