1.0.10 ā€¢ Published 3 years ago

@easy-express/graphql v1.0.10

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

A module that attaches an ApolloServer to your Easy-Express Server!

šŸ  Homepage

Introduction

To start using ApolloServer's awesome capabilities, simply attach a GraphQLModule to your EasyExpressServer and you're good to go!

Install

npm install @easy-express/graphql

Setup

Create a new directory to hold all of your GraphQL modules. Each file in this directory should export typeDefs and resolvers like the example below:

import { gql } from 'apollo-server-express';
import { Balances } from '../entities/Balances';
import { getRepository } from 'typeorm';

export const typeDefs = gql`
  type Balance {
    id: ID!
    date: String!
    balance: Float!
  }

  extend type Query {
    get_all_balances: [Balance]
  }

  extend type Mutation {
    insert_balance(id: ID!, date: String!, balance: Float!): Balance
  }
`;
export const resolvers = {
  Query: {
    get_all_balances: async () => getRepository(Balances).find(),
  },
  Mutation: {
    insert_balance: async (obj: any, args: any) => {
      const balance = new Balances();
      balance.date = args.date;
      balance.balance = args.balance;
      return getRepository(Balances).save(balance);
    },
  },
};

Usage

Create a new GraphQLModule and pass the path to the directory holding all your graphql modules. Then, simply attach the module to your EasyExpressServer. This will add the '/graphql' endpoint to your app.

Example

import { EasyExpressServer } from '@easy-express/server';
import { DatabaseModule } from '@easy-express/typeorm';
import { GraphQLModule } from '@easy-express/graphql';
import * as dotenv from 'dotenv';

// load env vars from .env file
dotenv.config();

// create a new server
let server = new EasyExpressServer();

// define routes for your server...
server.instance.get('/', (req, res) => {
  res.send('Hello World!');
});

// attach the modules
server.attachModule(new GraphQLModule(__dirname + '/graphql-modules/')).then(() => {
  server
    .attachModule(new DatabaseModule(__dirname + '/entities/'))
    .then(() => {
      // Start the server after you've attached the two module
      server.start();
    })
    .catch((e) => {
      console.error(e);
      return e;
    });
});

Author

šŸ‘¤ Leonard Parisi

šŸ¤ Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues page. You can also take a look at the contributing guide.

Show your support

Give a ā­ļø if this project helped you!

Bitcoin Wallet Address: 3PjDkxNznkx7HVmVdfSMYgGJeeJzoDH7e6

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.0

3 years ago