ClaudeAPI design

محول REST إلى مخطط GraphQL

مشاركة:
محول REST إلى مخطط GraphQL

لماذا تهم هذه المطالبة

Manual REST-to-GraphQL conversions often miss pagination, proper nullability, and input validation. This structured prompt catches those gaps.

فيم نستخدمها

API design

المطالبة

Convert these REST API endpoints into a GraphQL schema. Include: 1) Type definitions with proper nullability, 2) Query and Mutation types, 3) Input types for mutations, 4) Connection types for pagination, 5) Resolver pseudocode for complex fields. Preserve existing validation rules.

النتيجة

```graphql type User { id: ID! email: String! name: String orders(first: Int, after: String): OrderConnection! createdAt: DateTime! }

type OrderConnection { edges: [OrderEdge!]! pageInfo: PageInfo! totalCount: Int! }

type Query { user(id: ID!): User users(filter: UserFilter, first: Int, after: String): UserConnection! }

input CreateUserInput { email: String! name: String }

type Mutation { createUser(input: CreateUserInput!): User! } ```

غالباً ما تتغاضى التحويلات اليدوية من REST إلى GraphQL عن التصفح، والتعامل الصحيح مع القيم الفارغة، والتحقق من صحة المدخلات. هذا الأسلوب المنظم يكشف تلك الثغرات. يوضح هذا النهج أسلوباً منظمًا لتصميم واجهات برمجة التطبيقات، ويُنتج نتائج متسقة وعالية الجودة يمكن البناء عليها بشكل تكراري.
مشاركة: