在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):leoasis/graphql-tag.macro开源软件地址(OpenSource Url):https://github.com/leoasis/graphql-tag.macro开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):graphql-tag.macroBabel Macro for the graphql-tag library. What it doesIt inlines the result of parsing the GraphQL queries with Converts this: const query = gql`
query {
hello {
world
}
}
`; To this: const query = {
'kind': 'Document',
'definitions': [{
'kind': 'OperationDefinition',
'operation': 'query',
'variableDefinitions': [],
'directives': [],
'selectionSet': {
'kind': 'SelectionSet',
'selections': [{
'kind': 'Field',
'alias': null,
'name': {
'kind': 'Name',
'value': 'hello'
},
'arguments': [],
'directives': [],
'selectionSet': {
'kind': 'SelectionSet',
'selections': [{
'kind': 'Field',
'alias': null,
'name': {
'kind': 'Name',
'value': 'world'
},
'arguments': [],
'directives': [],
'selectionSet': null
}]
}
}]
}
}],
'loc': {
'start': 0,
'end': 45,
'source': {
'body': '\\\\n query {\\\\n hello {\\\\n world\\\\n }\\\\n }\\\\n',
'name': 'GraphQL request',
'locationOffset': {
'line': 1,
'column': 1
}
}
}
}; It also supports adding interpolated fragments: const frag = gql`
fragment Frag on Hello {
world
}
`;
const query = gql`
query {
hello {
universe
...Frag
}
}
${frag}
`; WhyTo avoid the runtime overhead of parsing a string into a GraphQL AST. Installation and setupInstall and configure babel-macros if you haven't already. Then install this package:
UsageThe usage is the same as using graphql-tag directly, the only difference is that you have to import import gql from 'graphql-tag.macro';
const query = gql`
query {
hello {
world
}
}
`; |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论