FrEDA

FrEDA

  • Docs
  • Tutorial
  • Demo

›Backend

Präambel

  • Architektur
  • MonoRepo Struktur

External

  • PostgreSQL / Postgraphile
  • GraphiQL

Backend

  • GraphQL Server
  • GraphQL-Modules
  • TypeGraphQL
  • GraphQL-Playground
  • Besonderheiten
  • REST-Endpoints

Frontend

  • FrEDA ReactJS-Basics
  • Common Frontend-Library
  • CLI-Tools

Deploy

  • Deployment

Roadmap

  • geplante Weiterentwicklung

TypeGraphQL

Was ist TypeGraphQL

TypeGraphQL ist eine Bibliothek, die den Entwicklungs-Prozess eines GraphQL-Servers mithilfe TypeScript und Typensicherheit unterhaltsam macht, indem das Schema nur mit Klassen und ein bisschen Dekorationsmagie definiert wird.

Beispielobjekttyp:

@ObjectType()
class Recipe {
  @Field()
  title: string;

  @Field(type => [Rate])
  ratings: Rate[];

  @Field({ nullable: true })
  averageRating?: number;
}

Es verfügt außerdem über eine Reihe nützlicher Funktionen wie Validierung, Autorisierung und Dependency-Injektion , mit denen sich GraphQL-APIs schnell und einfach entwickeln lassen.

TypeGraphQL erlaubt es, ohne separate SDL-Definitionen GraphQL-Server direkt über Code zugenerieren. Das Framework verfolgt demzufolge einen Code-First-Ansatz. TypeGraphQL lässt sich zusammen mit den Tool wie GraphQL-Modules, TypeORM und Apollo-Server verwenden.

Ein Beispiel mit GraphQL-Modules findet man hier: https://graphql-modules.com/docs/recipes/type-graphql

Für eine ausführliche Dokumentation auf die offizielle TypeGraphQL-Doc gehen: https://typegraphql.com/

Resolver-Class Beispiel

TypeGraphQL für User

zu finden unter backend/freda-middleware/src/modules/auth/resolver/user.resolver.ts:

@Resolver(() => User)
export class UserResolver {

  @Query(() => User, { nullable: true })
  async me(
    @Ctx() { injector }: MyContext,
    @Info() info: GraphQLResolveInfo,
  ): Promise<User | null> {
    return injector.get<AuthProviderInterface>(AUTH).currentUser(info);
  }

  @Mutation(() => User)
  async updateUserAccount(
    @Arg('input') data: UpdateUserAccountInput,
    @Ctx() { injector }: MyContext,
    @Info() info: GraphQLResolveInfo,
  ): Promise<User> {
    return injector.get<AuthProviderInterface>(AUTH).update(data, info);
  }

  @Mutation(() => User)
  async signUp(
    @Arg('data') data: RegisterInput,
    @Ctx() { injector }: MyContext,
    @Info() info: GraphQLResolveInfo,
  ): Promise<User> {
    return injector.get<AuthProviderInterface>(AUTH).signUp(data, info);
  }

  @Mutation(() => User, { nullable: true })
  async signIn(
    @Arg('email') email: string,
    @Arg('password') password: string,
    @Ctx() { injector }: MyContext,
    @Info() info: GraphQLResolveInfo,
  ): Promise<User | null> {
    return injector.get<AuthProviderInterface>(AUTH).signIn({ email, password }, info);
  }

  @Mutation(() => User)
  async signInAdmin(
    @Arg('email') email: string,
    @Arg('password') password: string,
    @Ctx() { injector }: MyContext,
    @Info() info: GraphQLResolveInfo,
  ): Promise<User> {
    return injector.get<AuthProviderInterface>(AUTH).signInAdmin({ email, password }, info);
  }

  @Mutation(() => Boolean)
  async signOut(
    @Ctx() { injector }: MyContext,
  ): Promise<Boolean> {
    return injector.get<AuthProviderInterface>(AUTH).signOut();
  }

  @FieldResolver()
  name(@Root() parent: User): String {
    return `${parent.firstName} ${parent.lastName}`;
  }

}

Provider-Class Beispiel

siehe: GraphQL-Modules Providers

← GraphQL-ModulesGraphQL-Playground →
  • Was ist TypeGraphQL
  • Resolver-Class Beispiel
    • TypeGraphQL für User
  • Provider-Class Beispiel
FrEDA
Docs
Getting StartedFrontendBackendFrEDA Users
Tutorial
RequirementsSetup DevelopmentQuick run
Mehr
Prodat-SQLHochschule MittweidaDEVTIM IT Softwareentwicklung
Facebook Open Source
Copyright © 2021 Prodat-SQL. Built with ❤ and Docusaurus.