-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgraphql-client.html
120 lines (90 loc) · 2.98 KB
/
graphql-client.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<link rel="import" href="../polymer/polymer-element.html">
<!--
## GraphQL client
Use to create a connection to your GraphQL endpoint.
### Usage
Import the `build/apollo-client.js` in your website for a default setup.
```html
<script src="bower_components/polymer-apollo-client/build/apollo-client.js"></script>
```
If you need GraphQL subscriptions support, import the `build/apollo-client-subscription.js`
instead of `build/apollo-client.js`.
```html
<script src="bower_components/polymer-apollo-client/build/apollo-client-subscription.js"></script>
```
If you need file upload via GraphQL support, import the `build/apollo-client-subscription-file-upload.js`
instead of `build/apollo-client.js`.
```html
<script src="bower_components/polymer-apollo-client/build/apollo-client-subscription-file-upload.js"></script>
```
Create a single instance of the `<graphql-client.html>`.
```html
<link rel="import" href="bower_components/polymer-apollo-client/graphql-client.html">
<graphql-client config='{"uri": "https://graphql.endpoint/graphql"}'></graphql-client>
```
This will create an instance of Apollo Client.
### Custom Apollo Client
You can use your own `apollo-client-***.js` file. It should include:
- `window.Apollo.client` an instance of `ApolloClient`
- `window.Apollo.gql` an export of `graphql-tag`
The _only_ thing `<graphql-client>` exposes:
```js
window.Apollo.namedClient['default'] = apolloClientInstance;
```
For an example how to set this up, take a look at `apollo-client.js`, `apollo-client-subscription.js`
and at the `webpack.config.js` to see how to compile your version.
@group ApolloClient
@polymer
@customElement
@demo demo/graphql-query-simple.html Simple query
@demo demo/full-demo.html Full demo
-->
<script>
const CLIENT_NAME_DEFAULT = 'default';
class GraphQLClient extends Polymer.Element {
static get is() {
return 'graphql-client';
}
static get properties() {
return {
/**
* Will be passed to `HttpLink()`.
*/
config: {
type: Object
},
/**
* Will be passed to `WebSocketLink()`.
*/
wsConfig: {
type: Object
},
/**
* Will be passed to `ApolloClient()`.
*/
apolloConfig: {
type: Object
},
/**
* Name of the client. When using only a single endpoint in your app, you can omit this parameter.
*/
clientName: {
type: String,
value: CLIENT_NAME_DEFAULT
}
};
}
/**
* @protected
*/
connectedCallback() {
super.connectedCallback()
window.Apollo.namedClient[this.clientName] = window.Apollo.init(this.config, this.wsConfig, this.apolloConfig);
if (this.clientName === CLIENT_NAME_DEFAULT) {
window.Apollo.client = window.Apollo.namedClient[CLIENT_NAME_DEFAULT]
window.__APOLLO_CLIENT__ = window.Apollo.client
}
}
}
customElements.define(GraphQLClient.is, GraphQLClient);
</script>