Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
babel-plugin-graphql-tag
Advanced tools
Compiles GraphQL tagged template strings using graphql-tag
Compiles GraphQL tagged template strings using graphql-tag.
Compiling GraphQL queries at the build time:
graphql-tag
dependencyRemoving the graphql-tag
dependency from the bundle saves approx. 50 KB.
graphql-tag
and removes them.gql
identifier and compiles them using graphql-tag
.Input:
import gql from 'graphql-tag';
// if using apollo v3
import { gql } from '@apollo/client';
const foo = gql`query {bar}`;
Output:
const foo = {
"definitions": [
{
"directives": [
],
"kind": "OperationDefinition",
"operation": "query",
"selectionSet": {
"kind": "SelectionSet",
"selections": [
{
"alias": null,
"arguments": [
],
"directives": [
],
"kind": "Field",
"name": {
"kind": "Name",
"value": "bar"
},
"selectionSet": null
}
]
},
"variableDefinitions": [
]
}
],
"kind": "Document",
"loc": {
"end": 11,
"start": 0
}
};
NOTE: require() is also supported.
Using GraphQL fragments requires to:
graphql-tag
.Example:
import gql from 'graphql-tag';
const bar = gql`
fragment barFragment on Foo {
field1
field2
}
`;
const foo = gql`
query foo {
foo {
...barFragment
}
}
${bar}
`;
importSources
- An array of names for modules to import (default = ["graphql-tag", "@apollo/client"]
)onlyMatchImportSuffix
- Matches the end of the import instead of the entire name. Useful for relative imports, e.g. ./utils/graphql
(default = false)strip
- Strips insignificant characters such as whitespace from the original GraphQL string literal to reduce the size of compiled AST (default = false)transform
- By default, graphql query strings will be replaced with their AST representations, but you can override that behavior and do whatever you like. One possible use case would be to implement persisted queries:gqlTagIdentifiers
- An array of names for gql tag identifiers (default = ["gql"]
)// babel.config.js
plugins: [
[
"babel-plugin-graphql-tag",
{
strip: true,
transform: (source, ast) => {
const h = hash(source); // use your favorite hashing method
graphqlAstHashes[h] = ast; // write this to a file when compilation is complete
return {
queryId: h
};
}
}
]
]
Some cases are really hard to track down:
const apolloClient = require('@apollo/client');
// or
import apolloClient from '@apollo/client';
const { gql } = apolloClient;
const foo = gql`...`;
If you have this kind of syntax, this plugin won't work for you.
FAQs
Compiles GraphQL tagged template strings using graphql-tag
The npm package babel-plugin-graphql-tag receives a total of 52,027 weekly downloads. As such, babel-plugin-graphql-tag popularity was classified as popular.
We found that babel-plugin-graphql-tag demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.