Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executeRaw support #262

Open
terion-name opened this issue Nov 21, 2018 · 12 comments
Open

executeRaw support #262

terion-name opened this issue Nov 21, 2018 · 12 comments

Comments

@terion-name
Copy link

Why does executeRaw is not supported here?

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

@maticzav
Copy link
Collaborator

Hey @terion-name 👋,

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

@terion-name
Copy link
Author

@maticzav
Copy link
Collaborator

@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.

@terion-name
Copy link
Author

@maticzav
Copy link
Collaborator

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/

@terion-name
Copy link
Author

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

@maticzav
Copy link
Collaborator

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

@terion-name
Copy link
Author

@maticzav self-hosted (1.19 running in docker)

@maticzav
Copy link
Collaborator

@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.

@telaoumatenyanis
Copy link

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.

@gabrieltong
Copy link

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

@szabi84
Copy link

szabi84 commented Jun 24, 2021

  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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants