Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.