Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
gql-api-loader
Advanced tools
Readme
自动请求生成 graphql 请求的 webpack loader
npm install --save-dev gql-api-loader
在 webpack 配置中加上 gql-api-loader
的配置
{
// ... 其他配置
module: {
rules: [
{
test: /\.(graphql|gql)$/,
// use: { loader: 'gq-loader'}, // 最简单配置
use: { loader: 'gql-api-loader'
options: { // 选项
endpoint: '/graphql' // 可选,该值可以再运行时改变,这里可以理解为是一个默认值
}
}
}
]
}
}
loader 的 options 可选项为
{
raw: false, // 如果为true,直接导出 graphql 查询语句,已自动解析 Fragment 依赖,如果为false,导出可直接执行的查询函数,默认为false
debug: false, // 调试模式
endpoint: '/graphql', // 默认的 graphql url,可以在运行时更改
}
示例
fragment.graphql
定义共用的部分
fragment userFields on User {
uid
userName
}
业务接口,先导入 fragment.graphql
,然后定义两个查询
#import './fragment.gql'
query check {
me {
...userFields
nickName
}
}
mutation create($param: UserParam) {
userCreate(input: $param) {
...userFields
nickName
}
}
在业务代码中引用,调用接口
import gqlConfig from 'gql-api-loader/lib/config'
gqlConfig({
endpoint: 'http://127.0.0.1:9000/gql', // graphql 的 url
credentials: 'include', // fetch 参数的 credentials 配置,是否携带 cookies
headers: { Authorization: 'Beare XXXXXXXXXXXXXX' }, // 可以配置请求的headers
fetch: (url, options) => window.fetch(url, options), // 完全自己定义请求函数,参数与 window.fetch 一致
})
import user from './user.graphql'
;(async function(){
const { me } = await user.check() // 直接请求
console.log(me)
const {userCreate: userinfo} = await user.create({input: {userName: 'eyas'}}) // 参数要以object形式传入
console.log(userinfo)
})()
FAQs
自动请求生成 graphql 请求的 webpack loader
The npm package gql-api-loader receives a total of 0 weekly downloads. As such, gql-api-loader popularity was classified as not popular.
We found that gql-api-loader 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.