Skip to content

Avoid the need for @Schema decorator #35

@felipesabino

Description

@felipesabino

While doing the decorators code refactory I noticed that the GraphQL schema cold be defined on the queries/mutation/subscription directly (similar to how routing-controllers project works) by adding the @Query decorator directly into query fields.

This approach goes against the current approach where everything is a @Field or @ObjectType and some are queries defined in the schema elsewhere, making it harder to visualize what the schema actually is and IMO being less declarative than it could possibly be.

A proposed approach would be to get rid of the @Schema decorator in favor of loading all classes with decorators from a specific folder (routing-controllers example) or passing an array of classes (routing-controllers example)

An example schema definition would be


// TypeScript definitions


// Output type
@ObjectType()
export class Foo {
    bars: string;
}

@ObjectType()
export class MyQuery {
    @Query({ type: Foo } )
    AQuery() : Promise<Foo> {
     // return Foo
    }

    @Mutation({ type: Foo } )
    AMutation(
          @Arg() aValue: string,
    ): Promise<Foo> { 
     // return Foo
    }
}

// Resulting GraphQL Schema

type Foo {
  bars: String
}

type Query {
  AQuery(): Foo
}

type Mutation {
  AMutation(aValue: String): Foo
}

schema {
  query: Query
  mutation: Mutation
}

This would be a breaking change but would avoid having to create a file with the @Schema manually referencing all queries and mutations.

So my question is if this a reasonable (breaking) change for a 1.0.0 release?

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions