All Projects → glennreyes → Graphpack

glennreyes / Graphpack

Licence: mit
☄️ A minimalistic zero-config GraphQL server.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Graphpack

Ssr Sample
A minimum sample of Server-Side-Rendering, Single-Page-Application and Progressive Web App
Stars: ✭ 285 (-85.71%)
Mutual labels:  graphql, webpack, babel
Project Webcube
Continuously updated JS infrastructure for modern web dev
Stars: ✭ 141 (-92.93%)
Mutual labels:  graphql, webpack, babel
Crate
👕 👖 📦 A sample web and mobile application built with Node, Express, React, React Native, Redux and GraphQL. Very basic replica of stitchfix.com / krate.in (allows users to get monthly subscription of trendy clothes and accessories).
Stars: ✭ 2,281 (+14.39%)
Mutual labels:  graphql, webpack, babel
Woo Next
🚀 React WooCommerce theme, built with Next JS, Webpack, Babel, Node, Express, using GraphQL and Apollo Client
Stars: ✭ 342 (-82.85%)
Mutual labels:  graphql, webpack, babel
React Starter Kit
React Starter Kit — front-end starter kit using React, Relay, GraphQL, and JAM stack architecture
Stars: ✭ 21,060 (+956.17%)
Mutual labels:  graphql, webpack, babel
Tkframework
react + relay + redux + saga + graphql + webpack
Stars: ✭ 83 (-95.84%)
Mutual labels:  graphql, webpack, babel
React App
Create React App with server-side code support
Stars: ✭ 614 (-69.21%)
Mutual labels:  graphql, webpack, babel
Serverless Prisma
AWS Serverless Prisma Boilerplate
Stars: ✭ 126 (-93.68%)
Mutual labels:  graphql, webpack, babel
React Starter Kit
完美使用 React, Redux, and React-Router!超好用的脚手架
Stars: ✭ 1,755 (-11.99%)
Mutual labels:  webpack, babel
Js Stack Boilerplate
Final boilerplate code of the JavaScript Stack from Scratch tutorial –
Stars: ✭ 145 (-92.73%)
Mutual labels:  webpack, babel
Graphql Tag.macro
Babel Macro for graphql-tag
Stars: ✭ 168 (-91.57%)
Mutual labels:  graphql, babel
Iceberg
Front-End Boilerplate built with React + Babel + Webpack + SASS
Stars: ✭ 144 (-92.78%)
Mutual labels:  webpack, babel
Webpack Babel Multi Target Plugin
A Webpack plugin that works with Babel to allow differential loading - production deployment of ES2015 builds targeted to modern browsers, with an ES5 fallback for legacy browsers.
Stars: ✭ 150 (-92.48%)
Mutual labels:  webpack, babel
Breko Hub
Babel React Koa Hot Universal Boilerplate
Stars: ✭ 145 (-92.73%)
Mutual labels:  webpack, babel
Book
《现代化前端工程师权威指南》https://guoyongfeng.github.io/book/
Stars: ✭ 141 (-92.93%)
Mutual labels:  webpack, babel
Generator Phaser Plus
[🛑 DISCONTINUED] It has been a long journey but development of `generator-phaser-plus` is now over. I recommend you have a look and fork `yandeu/phaser-project-template` instead.
Stars: ✭ 148 (-92.58%)
Mutual labels:  webpack, babel
Preact Minimal
🚀 Minimal preact structure
Stars: ✭ 136 (-93.18%)
Mutual labels:  webpack, babel
Keepformac
keep for mac
Stars: ✭ 147 (-92.63%)
Mutual labels:  webpack, babel
Reactql
Universal React+GraphQL starter kit: React 16, Apollo 2, MobX, Emotion, Webpack 4, GraphQL Code Generator, React Router 4, PostCSS, SSR
Stars: ✭ 1,833 (-8.07%)
Mutual labels:  graphql, webpack
Reactconfbr
Public infos and issues about React Conf Brasil organization
Stars: ✭ 156 (-92.18%)
Mutual labels:  graphql, webpack

Graphpack

☄️ A minimalistic zero-config GraphQL server

Check out the demo on CodeSandbox: https://codesandbox.io/s/k3qrkl8qlv


What is included?

Graphpack lets you create GraphQL servers with zero configuration. It uses webpack with nodemon and Apollo Server under the hood, so we get features like Live Reloading, GraphQL Playground, GraphQL Imports and many more right out of the box.

Install & Usage

yarn add --dev graphpack

Add src/schema.graphql and src/resolvers.js

src
├── resolvers.js
└── schema.graphql

In your schema, add some sample types in SDL:

type Query {
  hello: String
}

In src/resolvers.js:

const resolvers = {
  Query: {
    hello: () => 'world!',
  },
};

export default resolvers;

Setup package.json run scripts

Add following scripts to your package.json:

  "scripts": {
    "dev": "graphpack",
    "build": "graphpack build"
  },

Start development server

To start the development server, simply run:

yarn dev

Create production build

To create a production-ready build run following command:

yarn build

Use production build

Add following script that executes our build:

  "scripts": {
    "start": "node ./build/index.js"
  },

The following command will run the build and start the app

yarn start

Make sure to create a build before running the start script.

CLI Commands

graphpack (alias graphpack dev)

Runs graphpack in development mode. After a successful build your output should look something like this:

Graphpack

Graphpack will watch for changes in your ./src folder and automatically reload the server.

graphpack build

Creates a production-ready build under the project roots build folder.

Entry files

src/resolvers.js (required)

In this file you define all your resolvers:

// src/resolvers.js
const resolvers = {
  Query: {
    article: (obj, args) => getArticleById(args.id),
    articles: () => getArticles(),
  },
};

export default resolvers;

You can use any of these folder/file structure:

  • src/resolvers.js
  • src/resolvers/index.js

src/schema.graphql (required)

Here you define all your GraphQL type definitions:

# src/schema.graphql
type Article {
  title: String
  body: String
}

type Query {
  article: Article
  articles: [Article!]!
}

Alternatively you can create a src/schema.js and use the template literal tag gql by graphql-tag:

// src/schema.js
import { gql } from 'graphql-tag';

const typeDefs = gql`
  type Article {
    title: String
    body: String
  }

  type Query {
    article: Article
    articles: [Article!]!
  }
`;

export default typeDefs;

Note that in this case, you will need to install graphql-tag.

Graphpack can resolve both .js and .graphql files. This means you can use any of these folder/file structures:

  • src/schema.js
  • src/schema/index.js
  • src/schema.graphql
  • src/schema/index.graphql

src/context.js

Create src/context.js and do following:

const context = req => ({
  /* context props here */
});

export default context;

You can use any of these folder/file structures:

  • src/context.js
  • src/context/index.js

Custom configuration

For custom configuration you can create a graphpack config file in cosmiconfig format:

  • graphpack.config.js (recommended)
  • graphpack field in package.json
  • .graphpackrc in JSON or YAML
  • .graphpackrc with the extensions .json, .yaml, .yml, or .js

Note that the config file (eg. graphpack.config.js) is not going through babel transformation.

Customize Server configuration

In your graphpack.config.js configure your server as follows:

// graphpack.config.js
module.exports = {
  server: {
    introspection: false,
    playground: false,
    applyMiddleware: { app, path }, // app is from an existing (Express/Hapi,...) app
  },
};

Return config as a function to get the env variable:

// graphpack.config.js

// `mode` will be either `development` or `production`
module.exports = (mode) => {
  const IS_DEV = mode !== 'production';

  server: {
    introspection: IS_DEV,
    playground: IS_DEV,
    mocks: IS_DEV,
    mocks: IS_DEV,
    // ...
  }
};

export default config;

Refer to the Apollo Server docs for more details about the options.

Note that it's not possible to set resolvers, typeDefs or context in the config file. For this please refer to entry files.

Configure server port

Configure the server port with:

module.exports = {
  server: {
    port: 4000, // default,
  },
};

Applying express middlewares to the server

In your graphpack.config.js add your applyMiddleware field as follows:

// graphpack.config.js
const express = require('express');

const app = express();

app.get('/hello', (req, res) => {
  res.send('Hello world!');
});

module.exports = {
  server: {
    applyMiddleware: {
      app,
      path: '/graphql', // default
    },
  },
};

Your GraphQL endpoint will be available under http://localhost:4000/graphql. To configure the server options refer to https://www.apollographql.com/docs/apollo-server/api/apollo-server.html#ApolloServer-applyMiddleware

Customize Webpack configuration

To extend webpack, you can define a function that extends its config via the config file:

// graphpack.config.js
module.exports = {
  webpack: ({ config, webpack }) => {
    // Add customizations to config
    // Important: return the modified config
    return config;
  },
};

Customize Babel configuration

Add an optional babel.config.js to your project root with the following preset:

// babel.config.js
module.exports = api => {
  // Cache the returned value forever and don't call this function again
  api.cache(true);

  return {
    presets: ['graphpack/babel'],
    // ... Add your plugins and custom config
  };
};

Acknowledgements

Graphpack was heavily inspired by:

Thanks to @richardbmx for designing the logo! 🙌

Contributors

This project exists thanks to all the people who contribute. contributors

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].