prisma-binding icon indicating copy to clipboard operation
prisma-binding copied to clipboard

executeRaw support

Open terion-name opened this issue 5 years ago • 12 comments

Why does executeRaw is not supported here?

Using Prisma client is not an option for my case. Can this be added?

terion-name avatar Nov 21 '18 13:11 terion-name

Hey @terion-name 👋,

Could you explain in a bit more detail what you have in mind with executeRaw?

maticzav avatar Nov 21 '18 13:11 maticzav

@maticzav https://github.com/prisma/prisma/issues/2052

terion-name avatar Nov 21 '18 13:11 terion-name

@terion-name I believe this hasn't been implemented after all. I checked the schema which is exposed by Prisma instance itself, and there seems to be no executeRaw field in any of the types.

Please note that prisma-binding doesn't give any additional functionality to one already exposed by Prisma.

maticzav avatar Nov 21 '18 17:11 maticzav

@maticzav it was: https://github.com/prisma/prisma/releases/tag/1.17.0

terion-name avatar Nov 22 '18 10:11 terion-name

Hey @terion-name, I cannot reproduce your issue. Prisma Binding correctly generates executeRaw for me. Here's the code I get;

prisma.mutation.executeRaw({
  query: ""
})

I advise you check out the instructions in the documentation. I followed them, and it seems to be working. I hope they help you as well 🙂

In case they don't, please compose a CodeSandbox or a simple Github repo with reproduction.

Additionally, I would like to point out this is not connected to prisma-binding. Codegen is not bound to Prisma but rather simply obtains the schema from the remote endpoint and generates definitions for every field it can find. No extra field exists in prisma-binding or is omitted by it. It merely mirrors the schema.

https://www.prisma.io/docs/prisma-graphql-api/reference/raw-database-access-qwe4/

maticzav avatar Nov 22 '18 20:11 maticzav

@maticzav hm. I've tried, but it didn't work. This is strange, I'll check once more. Thank you

terion-name avatar Nov 23 '18 21:11 terion-name

@terion-name, are you trying to use executeRaw on Prisma hosted server, or self-hosted instance?

maticzav avatar Nov 24 '18 08:11 maticzav

@maticzav self-hosted (1.19 running in docker)

terion-name avatar Nov 26 '18 20:11 terion-name

@terion-name I am unable to reproduce your issue. Did you restart the docker and included executeRaw option from Prisma documentation? Could you compose a reproduction repository or CodeSandbox? Whichever suits you best! Otherwise, there is scarcely a chance to resolve this issue.

maticzav avatar Nov 27 '18 17:11 maticzav

Can you try to regenerate your schema.graphql ? I had this issue and my schema.graphql was too old.

According to prisma doc, your files should look like this :

.graphqlconfig.yml

projects:
  db:
    schemaPath: "src/schema.graphql"
    extensions:
      prisma: prisma.yml

prisma.yml

datamodel: datamodel.prisma
endpoint: http://localhost:4466/myservice/dev
secret: mysecret
hooks:
  post-deploy:
    - graphql get-schema --project db

Running prisma deploy will regenerate your schema.graphql. Try searching executeRaw in it.

Now, use the generated schema.graphql as the typedef argument of your Prisma instance :

import typeDefs from "./schema.graphql"

const prisma = new Prisma({
  typeDefs,
  endpoint: https://localhost:4466/myservice/dev
  secret: mysecret
});

You now have access to executeRaw in prisma.mutation.executeRaw.

telaoumatenyanis avatar Nov 28 '18 15:11 telaoumatenyanis

my prisma-binding also doesn't expost executeRaw , prisma server version 1.28

gabrieltong avatar Mar 19 '19 10:03 gabrieltong

  1. I added to my prisma config rawAccess: true flag:
PRISMA_CONFIG:
  port: 4466
  databases:
  default:
  connector: mysql
  host: mysql
  port: 3306
  user: root
  password: prisma
  migrations: true
  rawAccess: true
  1. With prisma deploy I regerated the prisma.graphql schema:
prisma deploy --force --env-file .env.local 

Now in the prisma.graphql file the executeRaw is added as mutation:

type Mutation {  
 executeRaw(database: PrismaDatabase, query: String!): Json!
}
  1. From this point you can reach executeRaw function from prisma-binding:
const { Prisma } = require('prisma-binding')

const db = new Prisma({
  typeDefs: process.env.PRISMA_SCHEMA || 'src/generated/prisma.graphql',
  endpoint: process.env.PRISMA_ENDPOINT,
  debug: process.env.PRISMA_DEBUG,
  secret: process.env.PRISMA_SECRET
})

db.mutation.executeRaw({
  query: 'CREATE INDEX Agent_heartbeat_IDX USING BTREE ON `dev2`.Agent (heartbeat);'
})

I hope it helped.

szabi84 avatar Jun 24 '21 09:06 szabi84