API Reference
CONTEXT
source file (opens in a new tab)
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
source file (opens in a new tab)
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
source file (opens in a new tab)
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 asubscribefunction that runs the subscription phase of GraphQL. Important when using GraphQL Subscriptions.createExecution- Creates aexecutefunction that runs the execution phase of GraphQL. Important when using GraphQL Queries and Mutations.createApolloExecutor- Creates anexecutorforApolloServer
ApplicationConfig
source file (opens in a new tab)
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
source file (opens in a new tab)
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
source file (opens in a new tab)
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
source file (opens in a new tab)
Module's configuration object. Represents the first argument of createModule function.
id- Unique identifier of a moduledirname- Pass__dirnamevariable 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.