All Projects β†’ VitorLuizC β†’ graphql-raw-loader

VitorLuizC / graphql-raw-loader

Licence: MIT license
πŸ– With Webpack, loads GraphQL files as raw strings and handle it's import directive & comment statement.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to graphql-raw-loader

sizeof-loader
Webpack loader that works like url-loader (or file-loader) but with extracted information such as image dimensions and file-size.
Stars: ✭ 20 (+5.26%)
Mutual labels:  webpack-loader
angular-hmr-loader
πŸ”₯ Angular HMR Webpack Loader by @AngularClass
Stars: ✭ 32 (+68.42%)
Mutual labels:  webpack-loader
svelte-loader-hot
Webpack loader for svelte components with HMR support
Stars: ✭ 22 (+15.79%)
Mutual labels:  webpack-loader
jsx-compress-loader
βš›οΈJSX optimisation loader to reduce size of React application
Stars: ✭ 40 (+110.53%)
Mutual labels:  webpack-loader
fengari-loader
Webpack loader for fengari
Stars: ✭ 27 (+42.11%)
Mutual labels:  webpack-loader
webpack-webmanifest-loader
Minimalistic webpack loader to generate webmanifest file (and process icons URLs).
Stars: ✭ 16 (-15.79%)
Mutual labels:  webpack-loader
One Loader
Single-file components for React
Stars: ✭ 233 (+1126.32%)
Mutual labels:  webpack-loader
webpack-modernizr-loader
Get your modernizr build bundled with webpack, use modernizr with webpack easily
Stars: ✭ 35 (+84.21%)
Mutual labels:  webpack-loader
css-raw-loader
🌁 CSS Raw loader module for Webpack
Stars: ✭ 13 (-31.58%)
Mutual labels:  webpack-loader
angular-translate-loader
"angular-translate" loader for webpack
Stars: ✭ 15 (-21.05%)
Mutual labels:  webpack-loader
image-minimizer-webpack-plugin
Webpack loader and plugin to compress images using imagemin
Stars: ✭ 180 (+847.37%)
Mutual labels:  webpack-loader
webpack-demos
webpack小练习
Stars: ✭ 17 (-10.53%)
Mutual labels:  webpack-loader
react-spa-template
This is a sample template for single page applications built using React + Router to work with webpack dev server
Stars: ✭ 19 (+0%)
Mutual labels:  webpack-loader
gzip-loader
[DEPRECATED] gzip loader module for webpack
Stars: ✭ 15 (-21.05%)
Mutual labels:  webpack-loader
markup-inline-loader
a webpack loader to embed svg/MathML to html
Stars: ✭ 24 (+26.32%)
Mutual labels:  webpack-loader
Vue Template Loader
Vue.js 2.0 template loader for webpack
Stars: ✭ 253 (+1231.58%)
Mutual labels:  webpack-loader
lodash-loader
Cherry-picks Lodash functions and require them explicitly to reduce the webpack bundle size.
Stars: ✭ 13 (-31.58%)
Mutual labels:  webpack-loader
preprocessor-loader
Bring the awesome "Conditional Compilation" to the Webpack, and more.
Stars: ✭ 32 (+68.42%)
Mutual labels:  webpack-loader
color-loader
🎨 A webpack loader that extracts the color palette of an image
Stars: ✭ 14 (-26.32%)
Mutual labels:  webpack-loader
virtual-dependency-loader
webpack loader that takes a single file, and declare pieces of that file as "dependencies" as if it existed.
Stars: ✭ 33 (+73.68%)
Mutual labels:  webpack-loader

GraphQL raw loader

Build Status

Load GraphQL files as raw strings and handle it's import directive & comment statement.

Installation

Install it using NPM/Yarn.

# using NPM
npm i -D graphql-raw-loader

# using Yarn
yarn add graphql-raw-loader --dev

Configuration

Add graphql-raw-loader to your webpack configuration:

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.(graphql|gql)$/,
        loader: 'graphql-raw-loader'
      }
    ]
  }
}

Usage example

fragment UserProfile on User {
  # Some fields.
}
query Users {
  users () {
    ...UserProfile @import(from: "./UserProfile.graphql")
  }
}
import query from './User.graphl'

export const getUsers = async () => {
  const response = await fetch('/api/graphql', {
    body: JSON.stringify({ query }),
    headers: {
      'Content-Type': 'application/json',
    },
  })
  const users = await response.json()
  return users
}

Importing on GraphQL

Officially there's no way to import GraphQL files inside each other. Other loaders fixed it by parsing import statement inside a comment.

Also, theres a thread about implementing import statements on GraphQL. One of the best suggestions is about using a directive to import fragments.

This loader supports both ways. 😎

Using comment import statement

# import "./UserDataFragment.graphql"
# The comment statement above is importing a file with UserDataFragment fragment
# inside it.

query Users {
  users (is_active: True) {
    data {
      ...UserDataFragment
    }
  }
}

Using @import directive

query Users {
  users (is_active: True) {
    data {
      ...
    }
    ...PaginationFragment @import(from: "./PaginationFragment.graphql")
    # The directive above is importing a file with PaginationFragment fragment
    # inside it.
  }
}
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].