Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
24b4c1e8
Commit
24b4c1e8
authored
Nov 28, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added frontend GraphQL docs
parent
385e8f71
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
0 deletions
+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
No files found.
doc/development/fe_guide/graphql.md
0 → 100644
View file @
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
View file @
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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment