Baeta
Schema first without the hassle
Schema First
Schema-first approach for a consistent and well-defined API.
Modular
Modular architecture for easy organization and scalability.
Type Safe
Automatic code generation for type safety, increased productivity, and reduced errors.
Advanced Features
Extensible, including support for middlewares, directives and plugins.
SDL
Baeta's schema-first pattern makes it easy to write and maintain GraphQL APIs that are easy to read and understand. By defining your schema first, you can focus on the API design and structure, rather than the implementation details.
type User {
id: ID!
name: String!
email: String!
age: Int
}
input UserWhereUnique {
id: ID
email: String
}
type Query {
user(where: UserWhereUnique!): User!
users: [User!]!
}
Typed resolvers
Baeta takes care of type safety and type definitions, so you can focus on implementing your resolvers in a flat and readable way.
import { getUserModule } from "./typedef";
const { Query } = getUserModule();
Query.user(({ args }) => {
return dataSource.user.find(args.where);
});
Query.users(() => {
return dataSource.user.findMany();
});
Extend other modules
Baeta's modular architecture allows you to easily extend other types and split your schema into small, reusable, and maintainable pieces. Here's an example of how to extend the User type with a photos field.
type Photo {
id: ID!
url: String!
description: String!
postedBy: User!
}
input PhotoCreateData {
url: String! @trim
description: String!
userId: ID!
}
extend type User {
photos: [Photo!]!
}
Directives
Baeta also supports custom directives, which allow you to define your own validation or mutation rules for input fields. Here's an example of a trim directive that trims whitespace from a string input.
const trimDirective = createInputDirective({
name: "trim",
target: "scalar",
resolve: ({ getValue, setValue }) => {
const value = getValue();
if (typeof value === "string") {
setValue(value.trim());
}
},
});