我实现了oauth2 web流程,以便从我的app的用户那里获取access_token.通过access_token,我想执行以下操作:
我已经成功获取用户信息(1)并创建了一个仓库(2)
我运行的命令:
git remote add origin https://gitlab-ci-token:<mytoken>@gitlab.com/myuser/myrepo.git
最好的祝福.
git push origin master
我想知道是否可以使用 InMemoryCache 的 typePolicies 来嵌套值 现在您可以定义平面字段策略
new InMemoryCache({
typePolicies: {
Query: {
fields: {
hello: {
read() {
return 'hello'
},
},
hola: {
read() {
return 'hola'
},
},
},
},
},
})
// query flat local field using apollo
const QUERY_USER_PAGE = gql`
query UserPage {
hello
hola
}
`
Run Code Online (Sandbox Code Playgroud)
如果我想要反映我的应用程序结构的 typePolicies 该怎么办,这似乎是一个很好的做法。
扁平结构在大型项目的扩展和维护方面会受到限制。
new InMemoryCache({
typePolicies: {
Query: {
fields: {
userPage: {
hello: {
read() {
return 'hello'
},
},
hola: {
read() {
return 'hola' …Run Code Online (Sandbox Code Playgroud) 我想使用 Jest/enzyme 测试受控组件。
我有一个<Input>给定的组件max,并且props 会在触发事件min时自动完成该值change
// Input.tsx
const Input = ({value, onChange, max, min}) => {
const handleChange = (evt) => {
const newValue = Number(evt.target.value)
if(min !== undefined && newValue < min) {
onChange(min)
return
}
if(max !== undefined && newValue > max) {
onChange(max)
return
}
onChange(newValue)
}
return (
<div>
<label>My input</label>
<input type="number" value={value} onChange={handleChange} />
</div>
)
}
Run Code Online (Sandbox Code Playgroud)
我想用玩笑来测试该组件及其不同的change用例。
因为它是一个完全受控的组件,所以我开始编写以下代码:
const onChangeSpy = jest.fn()
const Wrapper …Run Code Online (Sandbox Code Playgroud) 我希望 Typescript 推断过滤数组上的类型。
我根据“已拒绝”或“已完成”状态(来自 Promise.allSettled)过滤结果。
由于某种原因,Typescript 无法推断我的过滤结果。
这是我想要实现的目标的一个最小示例:
type FullFilledResults = {
status: 'fullfilled';
value: any;
}
type RejectResults = {
status: 'rejected';
reason: string;
}
type Results = RejectResults | FullFilledResults
const results: Results[] = [{
status: 'rejected',
reason: 'err'
}, {
status: 'fullfilled',
value: {}
}]
// Type infer Results[] but I want FullFilledResults[]
const fullfilledResults = results.filter(v => v.status === 'fullfilled')
// Type infer Results[] but I want RejectedResults[]
const rejectedResults = results.filter(v => v.status === 'rejected')
Run Code Online (Sandbox Code Playgroud) 如果管道出现故障,有没有办法防止推送到gitlab?
这是一个包含多个作业的gitlab-ci.yml示例.每次推送都会触发此管道.
如果其中一个作业失败,我不希望我的代码被推送到我的存储库.(我知道拉取请求存在此功能).
image: node:9.4.0
cache:
paths:
- node_modules/
before_script:
- npm install
stages:
- lint
- test
lint:
stage: lint
script:
- npm run lint
test:
stage: test
script:
- npm run test
Run Code Online (Sandbox Code Playgroud) javascript ×3
typescript ×3
git ×2
gitlab ×2
push ×2
apollo ×1
enzyme ×1
gitlab-ci ×1
jestjs ×1
oauth ×1
promise ×1
react-apollo ×1
reactjs ×1
testing ×1
token ×1