### Start GraphQL Server Source: https://github.com/hakutakuai/zenstack-graphql/blob/main/examples/graphql-server/README.md Starts the GraphQL server, making it accessible via a local URL. ```bash bun run start ``` -------------------------------- ### Run Tests Source: https://github.com/hakutakuai/zenstack-graphql/blob/main/examples/graphql-server/README.md Executes the project's test suite after dependencies are installed and setup is complete. ```bash bun test ``` -------------------------------- ### Install Dependencies Source: https://github.com/hakutakuai/zenstack-graphql/blob/main/examples/graphql-server/README.md Installs the necessary project dependencies using the 'bun' package manager. ```bash bun install ``` -------------------------------- ### Generate GraphQL Schema Source: https://github.com/hakutakuai/zenstack-graphql/blob/main/examples/graphql-server/README.md Generates the GraphQL schema from the ZModel using a setup script. ```bash bun run setup ``` -------------------------------- ### Install ZenStack GraphQL Plugin Source: https://github.com/hakutakuai/zenstack-graphql/blob/main/README.md Instructions for installing the ZenStack GraphQL plugin using different package managers like bun, npm, and yarn. It's recommended to install it as a development dependency. ```bash # Using bun (Recommended) bun add @hakutakuai/zenstack-graphql -D # Using npm npm install @hakutakuai/zenstack-graphql --save-dev # Using yarn yarn add @hakutakuai/zenstack-graphql -D ``` -------------------------------- ### Basic ZenStack GraphQL Plugin Configuration Source: https://github.com/hakutakuai/zenstack-graphql/blob/main/README.md A basic example of how to configure the ZenStack GraphQL plugin in a schema.zmodel file. This specifies the provider and the output path for the generated GraphQL schema. ```zmodel plugin graphql { provider = '@hakutakuai/zenstack-graphql' output = './schema.graphql' } ``` -------------------------------- ### ZenStack GraphQL Plugin Configuration Reference Source: https://github.com/hakutakuai/zenstack-graphql/blob/main/README.md A comprehensive reference table detailing all available configuration options for the ZenStack GraphQL plugin. It includes the option name, type, default value, and a description of its purpose. ```APIDOC Configuration Reference: | Option | Type | Default | Description | |---|---|---|---| | `output` | `string` | `'./schema.graphql'` | Output path for the generated schema | | `scalarTypes` | `object` | *See below* | Custom mappings for scalar types | | `connectionTypes` | `boolean` | `true` | Generate Relay-compatible connection types | | `generateEnums` | `boolean` | `true` | Generate GraphQL enum types | | `generateScalars` | `boolean` | `true` | Generate GraphQL scalar types | | `generateFilters` | `boolean` | `true` | Generate filter input types | | `generateSorts` | `boolean` | `true` | Generate sort input types | | `fieldNaming` | `string` | `'camelCase'` | Field naming convention | | `typeNaming` | `string` | `'PascalCase'` | Type naming convention | | `includeRelations` | `boolean` | `true` | Include model relations in schema | Default scalar mappings: ``` { "DateTime": 'DateTime', "Json": 'JSON', "Decimal": 'Decimal', "Bytes": 'String' } ``` ``` -------------------------------- ### Generate GraphQL Schema Source: https://github.com/hakutakuai/zenstack-graphql/blob/main/README.md The command to execute after configuring the ZenStack GraphQL plugin to generate the GraphQL schema file based on the ZModel definitions. ```bash zenstack generate ``` -------------------------------- ### Advanced ZenStack GraphQL Plugin Customization Source: https://github.com/hakutakuai/zenstack-graphql/blob/main/README.md Demonstrates advanced customization options for the ZenStack GraphQL plugin within the schema.zmodel file. This includes setting field and type naming conventions, customizing scalar type mappings, and enabling/disabling features like connection types, filters, and sorts. ```zmodel plugin graphql { // Basic settings output = './schema.graphql' // Use your preferred naming style fieldNaming = 'snake_case' // Fields become like_this typeNaming = 'PascalCase' // Types become LikeThis // Customize scalar type mappings scalarTypes = { "DateTime": 'Date', // Use Date instead of DateTime "Json": 'JSONObject' // Use JSONObject instead of JSON } // Turn features on/off as needed connectionTypes = true // Add Relay pagination support generateFilters = true // Add filtering capabilities generateSorts = true // Add sorting functionality } ``` -------------------------------- ### ZModel Data Model Definition Source: https://github.com/hakutakuai/zenstack-graphql/blob/main/README.md Defines data models, datasource, generator, and plugin configuration for ZenStack. ```zmodel datasource db { provider = "postgresql" url = env("DATABASE_URL") } generator client { provider = "prisma-client-js" } plugin graphql { provider = "@hakutakuai/zenstack-graphql" output = "./schema.graphql" } model User { id Int @id @default(autoincrement()) email String @unique name String? posts Post[] } model Post { id Int @id @default(autoincrement()) title String content String? published Boolean @default(false) author User @relation(fields: [authorId], references: [id]) authorId Int } ``` -------------------------------- ### Generated GraphQL Schema Source: https://github.com/hakutakuai/zenstack-graphql/blob/main/README.md The GraphQL schema automatically generated by ZenStack, including types, scalars, and input filters. ```graphql """An object with a unique identifier""" interface Node { """The unique identifier for this object""" id: ID! } """A date-time string at UTC, such as 2007-12-03T10:15:30Z""" scalar DateTime """The `JSON` scalar type represents JSON values as specified by ECMA-404""" scalar JSON """An arbitrary-precision Decimal type""" scalar Decimal # Base model types type User { id: Int! email: String! name: String posts: [Post!]! } type Post { id: Int! title: String! content: String published: Boolean! author: User! authorId: Int! } # Pagination support (Relay-compatible) type PageInfo { hasNextPage: Boolean! hasPreviousPage: Boolean! startCursor: String endCursor: String } # Connection types for related lists type UserConnection { pageInfo: PageInfo! edges: [UserEdge!]! totalCount: Int! } type UserEdge { node: User! cursor: String! } type PostConnection { pageInfo: PageInfo! edges: [PostEdge!]! totalCount: Int! } type PostEdge { node: Post! cursor: String! } # Filtering and sorting inputs input StringFilterInput { equals: String not: String in: [String!] notIn: [String!] contains: String startsWith: String endsWith: String } input BooleanFilterInput { equals: Boolean not: Boolean } # ... and more generated types for complete API functionality ``` -------------------------------- ### ZenStack Model Customization with Attributes Source: https://github.com/hakutakuai/zenstack-graphql/blob/main/README.md Illustrates how to use attributes within ZModel definitions to fine-tune the generated GraphQL schema. This includes ignoring fields, renaming fields, adding descriptions, marking fields for sorting/filtering, and customizing model-level naming and pagination. ```zmodel model User { id Int @id email String @unique // Hide sensitive fields from the API password String @graphql.ignore // Rename fields for better API design emailAddress String @graphql.name("email") // Add clear descriptions for your API docs fullName String @graphql.description("User's complete name") // Mark fields for filtering and sorting createdAt DateTime @graphql.sortable @graphql.filterable // Model-level customization @@graphql.name("Member") // Rename the type @@graphql.description("Platform member") // Add type description @@graphql.connection(pageSize: 20) // Configure pagination } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.