0.0.33 • Published 6 years ago
aerographql v0.0.33
AeroGraphQL is a small and opinionated Typescript toolkit to create GraphQL server using a declarative approach.
Overview
Install AeroGraphQL
yarn add aerographql
Note that graphql is a needed peer dependency, you must install it beforehand
Define your schema
@ObjectDefinition( { name: 'User' } )
export class User {
@Field( { type: 'ID' } ) id: string;
@Field( ) name: String;
@Field( { nullable: true }) description: String;
}
@ObjectImplementation( { name: 'RootQuery' } )
export class RootQuery {
constructor( private userService: UserService ) { }
@Resolver( { type: User } )
user( @Arg() name: string ): User | Promise<User> {
return this.userService.find( name );
}
}
@Schema( {
rootQuery: 'RootQuery',
components: [ RootQuery, User ]
} )
export class MySchema extends BaseSchema {
}
Inject the schema within a GraphQL server
Apollo Server with Express in this case:
let mySchema = new MySchema();
this.app = express();
this.app.use( '/graphql', bodyParser.json(), graphqlExpress( { schema: mySchema.graphQLSchema } );
this.app.listen( config.get( 'server.port' ), () => {
console.log( 'Up and running !' );
} );
Documentation
Checkout the AeroGraphQL documentation and explore basic examples.
License
AeroGraphQL is freely distributable under the terms of the MIT license.