GraphQL Schema Migration: Schema-First to Code-First
This directory contains the GraphQL resolvers for the Unraid API. We are currently migrating from a schema-first approach to a code-first approach using NestJS decorators.
We have started migrating the GraphQL schema from schema-first to code-first approach. The following resolvers have been migrated:
The following resolvers still need to be migrated:
- Docker Resolver
- Array Resolver
- Disks Resolver
- VMs Resolver
- Connect Resolver
- Display Resolver
- Info Resolver
- Owner Resolver
- Unassigned Devices Resolver
- Cloud Resolver
- Flash Resolver
- Config Resolver
- Vars Resolver
- Logs Resolver
- Users Resolver
- Notifications Resolver
- Network Resolver
- Registration Resolver
- Servers Resolver
- Services Resolver
- Shares Resolver
For each resolver, we follow these steps:
- Create a model file (e.g., resolver-name.model.ts)
- Define ObjectType classes for return types
- Define InputType classes for input parameters
- Update the resolver to use the new model classes
- Update the resolver decorators to use the new model classes
- Create a module file (e.g., resolver-name.module.ts)
- Test the resolver to ensure it works correctly
We have created the following tools to help with the migration:
- migration-plan.md: A detailed plan for migrating the GraphQL schema
- migration-script.ts: A script to help identify which resolvers need to be migrated
See the API Key Resolver for an example of a migrated resolver:
- api-key.model.ts: Contains the model classes for the API Key Resolver
- api-key.resolver.ts: Contains the resolver implementation using the model classes
- api-key.module.ts: Contains the module configuration for the API Key Resolver
Benefits of Code-First Approach
The code-first approach offers several benefits:
- Type Safety: TypeScript types are used directly in the GraphQL schema
- Better IDE Support: Better autocomplete and type checking
- Easier Refactoring: Refactoring is easier as the types are defined in one place
- Better Documentation: The schema is documented in the code
- Easier Testing: Easier to test as the types are defined in the code
- Continue migrating the remaining resolvers
- Update the GraphQL module configuration to use code-first approach
- Remove the schema files once all resolvers are migrated