Prisma GraphQL APIReference

Raw Database Access

Overview

You can access the native API of the underlying database and perform complex operations.

Datamodel for examples on this page

All example subscriptions on this page are based on a Prisma service configured with this datamodel:

type User {
  id: ID! @unique
  name: String!
  createdAt: DateTime!
  updatedAt: DateTime!
}

Docker configuration

To enable raw database access, add rawAccess to your docker-compose.yml file.

MySQL
PostgreSQL
version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.19
    restart: always
    ports:
      - '4466:4466'
    environment:
      PRISMA_CONFIG: |
        port: 4466
        databases:
          default:
            connector: mysql
            host: mysql
            port: 3306
            user: root
            password: prisma
            migrations: true
  mysql:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: prisma
    volumes:
      - mysql:/var/lib/mysql
volumes:
  mysql: ~
Copy

Examples

To create a new User through the native API, you can use the executeRaw mutation.

mutation {
  executeRaw(
    query: "INSERT INTO default$default."User" (Id, Name, "updatedAt","createdAt") VALUES ('cjnkpvm0b000d0b22j7csr04v', 'Abhi', '2018-10-22T19:54:47.606Z', '2018-10-22T19:54:47.606Z');"
  )
}

To find all Users

mutation {
  executeRaw(query: "SELECT * FROM default$default."User"")
}
Content
Overview