Skip to Content
HeronJS v4 is now available.
4.0.0GraphQLQuick Start

GraphQL Quick Start

Install @heronjs/gql@4.0.0 alongside matching core, common and HTTP packages. GraphQL uses graphql-http/lib/use/fastify on the application’s shared HTTP listener.

import 'reflect-metadata'; import {Module} from '@heronjs/common'; import {HeronJS} from '@heronjs/core'; import {GraphQL, Resolver} from '@heronjs/gql'; import {of} from 'rxjs'; @GraphQL({typeDefs: '', Query: 'greeting: String!'}) class Queries { @Resolver() greeting() { return of('Hello Heron'); } } @Module({graphqls: [Queries]}) class AppModule {} const app = await HeronJS.create({module: AppModule}); await app.listen({port: 3000, host: '127.0.0.1'}); // await app.close() when finished.

Query the default endpoint:

curl http://127.0.0.1:3000/graphql \ -H 'content-type: application/json' \ --data '{"query":"{ greeting }"}'

@GraphQL declares the schema module and @Resolver declares its resolver methods. Parameter decorators include @GqlContext(), @GqlInfo(), @GqlParams() and @GqlParent().

Resolver results can be values, Promises or Observables. The first emission supplies the result. Guard evaluation and resilience writes are awaited; unexpected resolver errors are masked at the response boundary. Disposing the extension cancels its active handlers.

See HTTP migration for native request/reply integration and reactive execution for cancellation and empty-result behavior.

Last updated on