Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export interface AccountsModuleContext {
authToken?: string;
userAgent: string;
ip: string;
user?: IUser;
userId?: string;
}
// You can see the below. It is really easy to create a reusable GraphQL-Module with different configurations
export const AccountsModule: GraphQLModule<
AccountsModuleConfig,
AccountsRequest,
AccountsModuleContext
> = new GraphQLModule({
name: 'accounts',
typeDefs: ({ config }) =>
mergeTypeDefs(
[
TypesTypeDefs(config),
getQueryTypeDefs(config),
getMutationTypeDefs(config),
...getSchemaDef(config),
],
{
useSchemaDefinition: config.withSchemaDefinition,
}
),
resolvers: ({ config }) =>
({
[config.rootQueryName || 'Query']: Query,
import { GraphQLModule } from '@graphql-modules/core';
// When you have an OpenApi key from Bol.com
import { productModule } from './modules/product';
import { offerModule } from './modules/offer';
import { commonModule } from './modules/common';
export const appModule = new GraphQLModule({
name: 'root',
/** a list of `GraphQLModule` you wish to load to your app */
imports: [productModule, offerModule, commonModule],
});
async function main(): Promise {
const port = process.env.PORT || 3002;
const socketPath = process.env.DOCKER_SOCK || '/var/run/docker.sock';
const docker = new Docker({ socketPath });
const api = new GraphQLModule({
name: 'app',
imports: [
containerModule.forRoot({ docker }),
imageModule.forRoot({ docker }),
networkModule.forRoot({ docker }),
volumeModule.forRoot({ docker }),
],
});
const { schema, context } = api;
const server = new ApolloServer({ schema, context });
server.listen({ port, playground: true }).then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
}
import { GraphQLModule } from '@graphql-modules/core';
import { loadResolversFiles, loadSchemaFiles } from 'graphql-toolkit';
import { CommonModule } from "@modules/common";
import { ChatsProvider } from "@modules/chats/providers/chats.provider";
export const ChatsModule = new GraphQLModule({
imports: [
CommonModule
],
providers: [
ChatsProvider,
],
typeDefs: loadSchemaFiles(__dirname + '/schema/'),
resolvers: loadResolversFiles(__dirname + '/resolvers/'),
});
import { ApolloServer, gql } from 'apollo-server';
import { buildFederatedSchema } from '@apollo/federation';
import { GraphQLModule } from '@graphql-modules/core';
const InventoryModule = new GraphQLModule({
name: 'InventoryModule',
typeDefs: gql`
extend type Product @key(fields: "upc") {
upc: String! @external
weight: Int @external
price: Int @external
inStock: Boolean
shippingEstimate: Int @requires(fields: "price weight")
}
`,
resolvers: {
Product: {
__resolveReference(object) {
return {
...object,
...inventory.find(product => product.upc === object.upc)
import 'reflect-metadata';
import { ApolloServer } from 'apollo-server-express'
import { GraphQLModule } from '@graphql-modules/core'
import usersModule from './modules/users'
import chatsModule from './modules/chats'
export const rootModule = new GraphQLModule({
name: 'root',
imports: [usersModule, chatsModule]
})
export const server = new ApolloServer({
schema: rootModule.schema,
context: rootModule.context
})
import { GraphQLModule } from '@graphql-modules/core';
import { AccountsModule } from '@accounts/graphql-api';
import AccountsServer from '@accounts/server';
import { Db } from 'mongodb';
import { PostsModule } from '@modules/posts/posts.module';
import { DbModule } from '@modules/db/db.module';
export interface AppModuleConfig {
accountsServer: AccountsServer;
db: Db;
}
export const AppModule = new GraphQLModule({
name: 'app',
imports: ({ config: { accountsServer, db } }) => [
AccountsModule.forRoot({ accountsServer }),
DbModule.forRoot({ db }),
PostsModule,
],
configRequired: true,
});
import { GraphQLModule } from '@graphql-modules/core';
import { loadResolversFiles, loadSchemaFiles } from 'graphql-toolkit';
import { MessagesProvider } from "@modules/messages/providers/messages.provider";
import { CommonModule } from "@modules/common";
import { ChatsModule } from "@modules/chats";
export const MessagesModule = new GraphQLModule({
imports: [
CommonModule,
ChatsModule,
],
providers: [
MessagesProvider,
],
typeDefs: loadSchemaFiles(__dirname + '/schema/'),
resolvers: loadResolversFiles(__dirname + '/resolvers/'),
});
import { GraphQLModule } from '@graphql-modules/core';
import { Request } from 'express';
import gql from 'graphql-tag';
import { UserModule } from '../user/user.module';
export const AuthModule = new GraphQLModule({
typeDefs: gql`
type Query {
me: User
}
type User {
id: String
}
`,
resolvers: {
User: {
id: user => user._id,
},
Query: {
me: (root, args, context) => context.authenticatedUser,
},
import {GraphQLModule} from '@graphql-modules/core';
import {resolvers, types} from './schema';
export const userModule = new GraphQLModule({
name: 'user',
typeDefs: types,
resolvers,
});