How to use the @graphql-modules/core.GraphQLModule function in @graphql-modules/core

To help you get started, we’ve selected a few @graphql-modules/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github accounts-js / accounts / packages / graphql-api / src / modules / accounts / index.ts View on Github external
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,
github maapteh / graphql-modules-app / packages / server / src / app.ts View on Github external
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],
});
github dotansimha / docker-node-graphql-api / src / index.ts View on Github external
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}`);
  });
}
github darkbasic / graphql-modules-seed / src / modules / chats / index.ts View on Github external
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/'),
});
github Urigo / graphql-modules / examples / apollo-federation / services / inventory / index.ts View on Github external
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)
github Urigo / WhatsApp-Clone-Server / server.ts View on Github external
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
})
github ardatan / graphql-modules-accountsjs-boilerplate / server / src / modules / app / app.module.ts View on Github external
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,
});
github darkbasic / graphql-modules-seed / src / modules / messages / index.ts View on Github external
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/'),
});
github Urigo / graphql-modules / examples / basic / src / app / auth / auth.module.ts View on Github external
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,
    },
github Urigo / graphql-modules / examples / basic / src / modules / user / index.ts View on Github external
import {GraphQLModule} from '@graphql-modules/core';
import {resolvers, types} from './schema';

export const userModule = new GraphQLModule({
  name: 'user',
  typeDefs: types,
  resolvers,
});