API Reference
CONTEXT
CONTEXT
is an InjectionToken representing the provided GraphQLModules.GlobalContext
import { CONTEXT, Inject, Injectable } from 'graphql-modules'
@Injectable()
export class Data {
constructor(@Inject(CONTEXT) private context: GraphQLModules.GlobalContext) {}
}
MODULE_ID
MODULE_ID
is an InjectionToken representing module’s ID
import { MODULE_ID, Inject, Injectable } from 'graphql-modules'
@Injectable()
export class Data {
constructor(@Inject(MODULE_ID) moduleId: string) {
console.log(`Data used in ${moduleId} module`)
}
}
Application
A return type of createApplication
function.
typeDefs
- A list of type definitions defined by modules.resolvers
- An object with resolve functions defined by modules.schema
- Ready to use GraphQLSchema object combined from modules.injector
- The application (Singleton) injector.createOperationController
- Take over control of GraphQL OperationcreateSubscription
- Creates asubscribe
function that runs the subscription phase of GraphQL. Important when using GraphQL Subscriptions.createExecution
- Creates aexecute
function that runs the execution phase of GraphQL. Important when using GraphQL Queries and Mutations.createApolloExecutor
- Creates anexecutor
forApolloServer
ApplicationConfig
Application’s configuration object. Represents the first argument of createApplication
function.
modules
- A list of GraphQL Modulesproviders
- A list of Providers - read the “Providers and Tokens” chapter.middlewares
- A map of middlewares - read the “Middlewares” chapter.schemaBuilder
- Creates a GraphQLSchema object out of typeDefs and resolvers
createApplication
Creates Application out of Modules. Accepts ApplicationConfig
.
import { createApplication } from 'graphql-modules'
import { usersModule } from './users'
import { postsModule } from './posts'
import { commentsModule } from './comments'
const app = createApplication({
modules: [usersModule, postsModule, commentsModule]
})
createModule
Creates a Module, an element used by Application. Accepts ModuleConfig
.
import { createModule, gql } from 'graphql-modules'
export const usersModule = createModule({
id: 'users',
typeDefs: gql`
// GraphQL SDL
`,
resolvers: {
// ...
}
})
ModuleConfig
Module’s configuration object. Represents the first argument of createModule
function.
id
- Unique identifier of a moduledirname
- Pass__dirname
variable as a value to get better error messages.typeDefs
- An object or a list of GraphQL type definitions (SDL).resolvers
- An object or a list of GraphQL resolve functions.middlewares
- A map of middlewares - read the “Middlewares” chapter.providers
- A list of Providers - read the “Providers and Tokens” chapter.