在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):apollographql/persistgraphql开源软件地址(OpenSource Url):https://github.com/apollographql/persistgraphql开源编程语言(OpenSource Language):TypeScript 99.9%开源软件介绍(OpenSource Introduction):PersistGraphQL
It scans a code directory and extracts GraphQL query documents from The npm package also provides a network interface for Apollo Client that manages the query lookups in InstallationFor only the CLI tool: npm install -g persistgraphql As a dependency (for Apollo Client network interface): npm install --save persistgraphql Build Tool SemanticsThe build tool binary is called
It can be called on a file containing GraphQL query definitions with extension persistgraphql queries.graphql It can also be called on a directory, which it will step through recursively: persistgraphql src/ By default, the output will be placed in
Adding Typenames to Extracted QueriesIt can also take the
Extracting Queries from TypeScriptTo extract GraphQL queries from TypeScript files, use
Extracting Queries from JavaScriptIt is also possible to extract GraphQL queries from JavaScript files using
Apollo Client Network InterfaceThis package provides an implementation of an Apollo Client network interface that provides persisted query support. It serves as a drop-in replacement for the standard network interface and uses the query map given by This package also provides a way for you to alter any generic NetworkInterface to use persisted queries from a provided query map with the See the implementation as well as some documentation for it within Server-sideIf you use the client network interface provided by this package, you can quickly roll your own middleware to get the GraphQL query instead of the query ID that the network interface sends. Here's an example with Express using the import queryMap from ‘../extracted_queries.json’;
import { invert } from 'lodash';
app.use(
'/graphql',
(req, resp, next) => {
if (config.persistedQueries) {
const invertedMap = invert(queryMap);
req.body.query = invertedMap[req.body.id];
}
next();
},
); Here's an example with a Hapi server extension using the import queryMap from ‘../extracted_queries.json’;
import { invert } from 'lodash';
server.ext('onPreHandler', (req: Request, reply) => {
if (config.persistedQueries && req.url.path.indexOf('/graphql') >= 0 && req.payload.id) {
const invertedMap = invert(queryMap);
req.payload.query = invertedMap[req.payload.id]
}
return reply.continue();
}); |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论