Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
24b4c1e8
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
24b4c1e8
编写于
11月 28, 2018
作者:
P
Phil Hughes
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added frontend GraphQL docs
上级
385e8f71
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
86 addition
and
0 deletion
+86
-0
doc/development/fe_guide/graphql.md
doc/development/fe_guide/graphql.md
+83
-0
doc/development/fe_guide/index.md
doc/development/fe_guide/index.md
+3
-0
未找到文件。
doc/development/fe_guide/graphql.md
0 → 100644
浏览文件 @
24b4c1e8
# GraphQL
We use
[
Apollo] and [Vue Apollo
][
vue-apollo
]
for working with GraphQL
on the frontend.
In order to use GraphQL, you need to enable the
`graphql`
feature flag,
read more about
[
Feature Flags
][
feature-flags
]
.
## Apollo Client
To save duplicated clients getting created in different apps, we have a
[
default client
][
defualt-client
]
that should be used. This setups the
Apollo client with the correct URL and also sets the CSRF headers.
## GraphQL Queries
To save query compilation at runtime, webpack can directly import
`.graphql`
files. This allows webpack to preprocess the query at compile time instead
of the client doing compilation of queries.
## Usage in Vue
To use Vue Apollo, import the
[
Vue Apollo
][
vue-apollo
]
plugin as well
as the default client. This should be created at the same point
the Vue application is mounted.
```
javascript
import
Vue
from
'
vue
'
;
import
VueApollo
from
'
vue-apollo
'
;
import
defaultClient
from
'
~/lib/graphql
'
;
Vue
.
use
(
VueApollo
);
const
apolloProvider
=
new
VueApollo
({
defaultClient
,
});
new
Vue
({
...,
apolloProvider
,
...
});
```
Read more about
[
Vue Apollo
][
vue-apollo
]
in the
[
Vue Apollo documentation
][
vue-apollo-docs
]
.
### Testing
With
[
Vue test utils
][
vue-test-utils
]
it is easy to quickly test components that
fetch GraphQL queries. The simplest way is to use
`shallowMount`
and then set
the data on the component
```
javascript
it
(
'
tests apollo component
'
,
()
=>
{
const
vm
=
shallowMount
(
App
);
vm
.
setData
({
...
mock
data
});
});
```
## Usage outside of Vue
It is also possible to use GraphQL outside of Vue by directly importing
and using the default client with queries.
```
javascript
import
defaultClient
from
'
~/lib/graphql
'
;
import
query
from
'
./query.graphql
'
;
defaultClient
.
query
(
query
)
.
then
(
result
=>
console
.
log
(
result
));
```
Read more about the
[
Apollo] client in the [Apollo documentation
][
apollo-client-docs
]
.
[
Apollo
]:
https://www.apollographql.com/
[
vue-apollo
]:
https://github.com/Akryum/vue-apollo/
[
vue-apollo-docs
]:
https://akryum.github.io/vue-apollo/
[
feature-flags
]:
../feature_flags.md
[
default-client
]:
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/app/assets/javascripts/lib/graphql.js
[
apollo-client-docs
]:
https://www.apollographql.com/docs/tutorial/client.html
[
vue-test-utils
]:
https://vue-test-utils.vuejs.org/
doc/development/fe_guide/index.md
浏览文件 @
24b4c1e8
...
...
@@ -54,6 +54,9 @@ Vuex specific design patterns and practices.
## [Axios](axios.md)
Axios specific practices and gotchas.
## [GraphQL](graphql.md)
How to use GraphQL
## [Icons and Illustrations](icons.md)
How we use SVG for our Icons and Illustrations.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录