在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):gajus/babel-plugin-graphql-tag开源软件地址(OpenSource Url):https://github.com/gajus/babel-plugin-graphql-tag开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):babel-plugin-graphql-tagCompiles GraphQL tagged template strings using graphql-tag. MotivationCompiling GraphQL queries at the build time:
Removing the Implementation
Example compilationInput: 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 fragmentsUsing GraphQL fragments requires to:
Example: import gql from 'graphql-tag';
const bar = gql`
fragment barFragment on Foo {
field1
field2
}
`;
const foo = gql`
query foo {
foo {
...barFragment
}
}
${bar}
`; Options
// 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
};
}
}
]
] Known IssuesSome cases are really hard to track down:
If you have this kind of syntax, this plugin won't work for you. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论