Prisma ClientFeatures

GraphQL Requests (JavaScript)

Overview

The Prisma client lets you send GraphQL queries and mutations directly to your Prisma service using the $graphql method:

$graphql: <T = any>(query: string, variables?: {[key: string]: any}) => Promise<T>;

Examples

Fetching a single user:

const query = `
  query {
    user(id: "cjcdi63j80adw0146z7r59bn5") {
      id
      name
    }
  }
`

prisma.$graphql(query).then(result => console.log(result))
// sample result:
// {"data": { "user": { "id": "cjcdi63j80adw0146z7r59bn5", "name": "Sarah" } } }

Fetching a single user using variables:

const query = `
  query ($userId: ID!){
    user(id: $userId) {
      id
      name
    }
  }
`

const variables = { userId: 'cjcdi63j80adw0146z7r59bn5' }

prisma.$graphql(query, variables).then(result => console.log(result))
// sample result:
// {"data": { "user": { "id": "cjcdi63j80adw0146z7r59bn5", "name": "Sarah" } } }
Content
Overview