Skip to content

Latest commit

 

History

History
81 lines (59 loc) · 1.85 KB

gql-schema.md

File metadata and controls

81 lines (59 loc) · 1.85 KB

Tweaking GraphQL Schema

Prisma-AppSync provides ways to tweak and customise the GraphQL Schema output.

👉 Models directives

Tweaking the GraphQL schema for a given model require to write directives via AST comments (triple-slash ///).

/// @gql(mutations: null, subscriptions: null)
/// @gql(fields: { password: null })
/// @gql(scalars: { email: "AWSEmail" })
model User {
  id       Int       @id @default(autoincrement())
  email    String
  password String
}

👉 Usage with @gql syntax

Disabling an entire model

// Disable all queries, mutations and subscriptions
@gql(model: null)

Disabling queries

// Disable all queries (get, list, count, ...)
@gql(queries: null)

// Disable granular queries
@gql(queries: { list: null, count: null })

Disabling mutations

// Disable all mutations (create, update, upsert, delete, ...)
@gql(mutations: null)

// Disable granular mutations
@gql(mutations: { update: null, delete: null })

Cascading Rules:

  • Disabling update will also disable upsert
  • Disabling create will also disable upsert
  • Disabling mutations will also disable subscriptions

Disabling subscriptions

// Disable all subscriptions (onCreated, onUpdated, ...)
@gql(subscriptions: null)

// Disable granular subscriptions
@gql(mutations: { onCreated: null, onUpdated: null })

Hiding fields

// If applied to a model with a `password` field:
// hide `password` field from the generated Type
@gql(fields: { password: null })

Note: To maintain Prisma Client integrity, hidden fields remain writable in mutation operations.

Custom scalars on fields

// If applied to a model with a `website` (string) field:
// use scalar `AWSURL` instead of default `String`
@gql(scalars: { website: "AWSURL" })