0.4.0 โ€ข Published 6 years ago

graphql-aot v0.4.0

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

graphql-aot

NPM version NPM downloads CircleCI donate chat

Install

yarn add graphql-aot

Usage

If you only want to work with the import statement, you will only need the webpack loader:

๐Ÿ“ webpack.config.js:

module.exports = {
  entry: './index.js',
  module: {
    rules: [
      {
        test: /\.gql$/,
        loader: 'graphql-aot/loader',
        options: {
          defaultClientOptions: {
            uri: 'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn'
          }
        }
      }
    ]
  }
}

๐Ÿ“ query.gql:

{
  allPosts (first: 5) {
    id
    title
  }
}

๐Ÿ“ index.js:

import data from './query.gql'

console.log(data.allPosts)

If you want to use inline graphql tag, you will also need the babel plugin:

๐Ÿ“ .babelrc.js:

module.exports = {
  plugins: [
    require.resolve('graphql-aot/babel')
  ]
}

๐Ÿ“ index.js:

const { allPosts } = graphql`
{
  allPosts (first: 5) {
    id
    title
  }
}
`

console.log(allPosts)

API

loaderOptions

defaultClientOptions

Options for the default Apollo client.

client

Provide your own Apollo client instance.

getVariables

  • Type: function

A function to get the variables you want to use with the client.query() call.

The signature is: loaderContext => any

babelOptions

tagName

  • Type: string
  • Default: graphql

importFrom

  • Type: string
  • Default: undefined

Ensure the tagged template literal identifier is imported from a module.

import { gql } from 'a-module'

const data = gql`query { id }`

The above code will only work when you have following config for the babel plugin:

{
  importFrom: 'a-module',
  tagName: 'gql'
}

removeImportStatement

  • Type: boolean
  • Default: true when you set importFrom to a module name

Remove relevant import statement if necessary.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

graphql-aot ยฉ egoist, Released under the MIT License. Authored and maintained by egoist with help from contributors (list).

github.com/egoist ยท GitHub @egoist ยท Twitter @_egoistlily

0.4.0

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago