Skip to content

Schema Type

Alex Ald edited this page Apr 29, 2019 · 4 revisions

What is it for?

This decorator doesn't specifically create a PostGraphile plugin, but is simply assists in creating one. When attempting to modify a type in the PostGraphile schema, SchemaType will assist in specifying which Graphql Type you are trying to manipulate.

Decorator Parameters

Decorator takes a single parameter of type SchemaTypeOptions

interface SchemaTypeOptions {
  typeName: string;
}

Example

Create a class with the decorator specifying the graphql type

@SchemaType({ typeName: 'User'})
export class UserType {
...
}

Add an additional decorator to manipulate the schema type

@SchemaType({ typeName: 'User'})
export class UserType {

  @ChangeNullability({ fieldName: 'name'})
  public nameNullability() {
    return true;
  }
}

As you can see from the code block above, to change the nullability of a field we can simply use the ChangeNullability decorator specify the field name it applies to. There's no need to add additional information since we already know the decorator applies to the schema type specified in the SchemaType decorator.

Be sure to add the class as a provider to your module

@Module({
  imports: [
    PostGraphileModule.forRoot({
      pgConfig: process.env.POSTGRAPHILE_URL,
    }),
  ],
  providers: [UserType],
})
export class AppModule {}

Allowed Method Decorators