Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Latest commit

History

History
57 lines (45 loc) 路 1.12 KB

graphql-requests-JAVASCRIPT-pyl3.mdx

File metadata and controls

57 lines (45 loc) 路 1.12 KB

import Collapse from 'components/Markdown/Collapse'

export const meta = { title: 'GraphQL Requests (JavaScript)', position: 100, technology: "node", technologyOrder: 1, articleGroup: "GraphQL Requests", }

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" } } }