Socket
Socket
Sign inDemoInstall

babel-plugin-graphql-js-client-transform

Package Overview
Dependencies
9
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.3 to 1.1.0

26

lib/index.js

@@ -24,3 +24,3 @@ /**

*
* Version: 1.0.3 Commit: 08b7df7
* Version: 1.1.0 Commit: e5f3eb1
**/'use strict';

@@ -35,6 +35,11 @@

visitor: {
ImportSpecifier: function ImportSpecifier(path, state) {
// Find the gql import
if (path.node.imported.name === 'gql') {
// Save the name of the import
state.tag = path.node.local.name;
}
},
TaggedTemplateExpression: function TaggedTemplateExpression(path, state) {
var tag = state.opts.tag || 'gql';
if (path.node.tag.callee && path.node.tag.callee.name === tag) {
if (path.node.tag.callee && path.node.tag.callee.name === state.tag) {
path.traverse(templateElementVisitor, { parentPath: path, clientId: path.node.tag.arguments[0] });

@@ -47,2 +52,4 @@ }

exports.gql = gql;
var _language = require('graphql/language');

@@ -80,2 +87,11 @@

}
};
};
/**
* This function should not be invoked.
* This function is used to tag raw GraphQL queries that will be
* transcompiled into graphql-js-client's query builder syntax.
*/
function gql() {
throw new Error('This function should not be invoked. It should be used to tag template literals that will be\n transcompiled into graphql-js-client\'s query builder syntax.');
}

2

package.json
{
"name": "babel-plugin-graphql-js-client-transform",
"version": "1.0.3",
"version": "1.1.0",
"description": "Babel plugin for transforming raw GraphQL queries into graphql-js-client query builder syntax",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -26,16 +26,24 @@ # babel-plugin-graphql-js-client-transform

By default, the plugin will search for the tag `gql`. This value is configurable by passing in a `tag` option to the plugin.
## Usage
```js
// Finds template literals tagged with gql
import {gql} from 'babel-plugin-graphql-js-client-transform';
// Finds template literals tagged with customTagName
import {gql as customTagName} from 'babel-plugin-graphql-js-client-transform';
```
{
"plugins": [
["graphql-js-client-transform", {"tag": "customTag"}]
]
}
The plugin will pick up any template literals tagged with the imported `gql` function.
Do not reassign the function to another variable after it has been imported.
```js
import {gql} from 'babel-plugin-graphql-js-client-transform';
...
const newTag = gql;
newTag(client)`...`; // Don't do this. This template literal won't be transformed.
```
## Usage
Simply tag your raw GraphQL queries and the plugin will transform them. An instance of
[Shopify/graphql-js-client](https://github.com/Shopify/graphql-js-client)
An instance of [Shopify/graphql-js-client](https://github.com/Shopify/graphql-js-client)
must be supplied to the tag.

@@ -45,3 +53,3 @@

The following are example usages with the default variable name.
The following are example usages.

@@ -53,2 +61,6 @@ #### Example 1

``` js
import {gql} from 'babel-plugin-graphql-js-client-transform';
...
client.send(gql(client)`

@@ -65,2 +77,6 @@ query {

```js
import {gql} from 'babel-plugin-graphql-js-client-transform';
...
const _document = client.document(); // Creates a document to store the query

@@ -82,2 +98,6 @@ _document.addQuery((root) => {

```js
import {gql} from 'babel-plugin-graphql-js-client-transform';
...
const query = gql(client)`

@@ -96,2 +116,6 @@ query {

```js
import {gql} from 'babel-plugin-graphql-js-client-transform';
...
const _document = client.document(); // Creates a document to store the query

@@ -98,0 +122,0 @@ _document.addQuery((root) => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc