├── .babelrc
├── .eslintrc
├── .gitignore
├── LICENSE
├── README.md
├── docs
└── example-query.png
├── example
├── index.js
└── static
│ └── index.html
├── package.json
├── src
├── adapters
│ ├── Adapter.js
│ ├── connectedVehicleStatus.js
│ └── electricVehicleStatus.js
├── authContext.js
├── index.js
├── resolvers
│ ├── index.js
│ └── vehicle.js
├── scopes.js
└── typeDefs
│ ├── index.js
│ └── vehicle.js
└── yarn.lock
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "@babel/preset-env"
4 | ],
5 | "plugins": [
6 | ["@babel/plugin-transform-runtime",
7 | {
8 | "regenerator": true
9 | }
10 | ]
11 | ],
12 | }
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "@callstack"
3 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .DS_Store
3 | build-example
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Callstack
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # benz-ql
2 |
3 | An Apollo GraphQL server for the [Mercedes-Benz REST APIs](https://developer.mercedes-benz.com/). Allows to query them via a single endpoint, using GraphQL.
4 |
5 | ```graphql
6 | query {
7 | getVehicle(id: "1234567890ABCD1234") {
8 | licenseplate
9 | stateofcharge {
10 | value
11 | }
12 | location {
13 | longitude {
14 | value
15 | }
16 | }
17 | }
18 | }
19 | ```
20 |
21 | ## Try it now
22 |
23 | You can explore the query response by playing around with the [online playground](https://benz-ql.herokuapp.com/).
24 |
25 | ## Getting started
26 |
27 | To get started, install the package from the registry:
28 |
29 | ```bash
30 | $ yarn add benz-ql
31 | ```
32 |
33 | ## Configuraton
34 |
35 | ### Setting up the server
36 |
37 | This package can be used with different server frameworks supported by Apollo. In this example, we will be using Express.
38 |
39 | ```js
40 | import express from "express";
41 | import { ApolloServer } from "apollo-server-express";
42 | import benzQL, { scopes } from "benz-ql";
43 |
44 | const app = express();
45 | const PORT = 3000;
46 | const server = new ApolloServer(benzQL(scopes.SANDBOX)); // chose your environment - SANDBOX or PROD
47 |
48 | server.applyMiddleware({ app, path: "/benz-ql" });
49 |
50 | app.listen(PORT, () => {
51 | console.log(`App listen on ${PORT}`);
52 | console.log(`Benz-ql avaliable on ${server.graphqlPath}`);
53 | });
54 | ```
55 |
56 | ### Connecting from the client
57 |
58 | Once you set up a development server and start it successfuly, you can connect with it by using GraphQL client of your choice. In this section, we are using a `apollo-boost` package in context of a React Native application.
59 |
60 | > Note: You will need a token for accessing Mercedes APIs. Please consult [official documentation](https://developer.mercedes-benz.com/apis) for steps to do so.
61 |
62 | Below example demonstrates accessing battery level from the API, including potential error handling.
63 |
64 | ```js
65 | import React from "react";
66 | import { View, Text } from "react-native";
67 | import ApolloClient, { gql } from "apollo-boost";
68 |
69 | const client = new ApolloClient({
70 | uri: "http://localhost:3000/benz-ql",
71 | headers: {
72 | authorization: "a1b2c3d4-a1b2-a1b2-a1b2-a1b2c3d4e5f6"
73 | }
74 | });
75 |
76 | class Home extends React.Component {
77 | state = { batteryStatus: "unknown" };
78 |
79 | async componentDidMount() {
80 | const { data, error } = await client.query({
81 | query: gql`
82 | query {
83 | getVehicle(id: "1234567890ABCD1234") {
84 | stateofcharge {
85 | value
86 | }
87 | }
88 | }
89 | `
90 | });
91 |
92 | if (!error) {
93 | this.setState({
94 | batteryStatus: data.getVehicle.stateofcharge.value
95 | });
96 | }
97 | }
98 |
99 | render() {
100 | const { batteryStatus } = this.state;
101 | return (
102 |
103 | Battery Status: {batteryStatus}
104 |
105 | );
106 | }
107 | }
108 | ```
109 |
110 | ## Contributing
111 |
112 | ### Run example server
113 |
114 | This project comes with a development server that is useful for debugging and developing the library. In order to get started, follow the steps below:
115 |
116 | 1. Clone this repo
117 | 2. `yarn install`
118 | 3. `cd example`
119 | 4. `node index.js`
120 | 5. Open [http://localhost:3000](http://localhost:3000)
121 |
122 | > Note: Example server uses sandbox environment
123 |
124 | ## Coverage table
125 |
126 | Here is the list of supported APIs. Contributions are welcome to support the remaining list.
127 |
128 |
129 |
130 |
API Name
131 |
API Resource
132 |
Status
133 |
134 |
135 |
Connected Vehicle (experimental)
136 |
Vehicles
137 |
implemented
138 |
139 |
140 |
Tires
141 |
implemented
142 |
143 |
144 |
Doors
145 |
implemented
146 |
147 |
148 |
Location
149 |
implemented
150 |
151 |
152 |
Odometer
153 |
implemented
154 |
155 |
156 |
Fuel
157 |
implemented
158 |
159 |
160 |
State of Charge
161 |
implemented
162 |
163 |
164 |
Car Configurator
165 |
References
166 |
pending
167 |
168 |
169 |
Configurations
170 |
pending
171 |
172 |
173 |
Images
174 |
pending
175 |
176 |
177 |
Saved configurations
178 |
pending
179 |
180 |
181 |
Dealer
182 |
Dealer search
183 |
pending
184 |
185 |
186 |
References
187 |
pending
188 |
189 |
190 |
Electric Vehicle Status
191 |
Container Electric Vehicle Status
192 |
pending
193 |
194 |
195 |
Resources
196 |
pending
197 |
198 |
199 |
State of charge resource
200 |
pending
201 |
202 |
203 |
Range electric resource
204 |
pending
205 |
206 |
207 |
Fuel Status
208 |
Container Fuel Status
209 |
pending
210 |
211 |
212 |
Resources
213 |
pending
214 |
215 |
216 |
Tank level resource
217 |
pending
218 |
219 |
220 |
Range liquid resource
221 |
pending
222 |
223 |
224 |
Pay As You Drive Insurance
225 |
Container Pay As You Drive Insurance
226 |
pending
227 |
228 |
229 |
Resources
230 |
pending
231 |
232 |
233 |
Odometer resource
234 |
pending
235 |
236 |
237 |
Remote Diagnostic Support
238 |
Resources
239 |
pending
240 |
241 |
242 |
Electronical Control Units (ECU's)
243 |
pending
244 |
245 |
246 |
Diagnostic Trouble Codes (DTC's)
247 |
pending
248 |
249 |
250 |
Diagnostic Trouble Code (DTC) Snapshots
251 |
pending
252 |
253 |
254 |
Vehicle Images
255 |
Vehicle Images Basic
256 |
pending
257 |
258 |
259 |
Vehicle Images 360
260 |
pending
261 |
262 |
263 |
Vehicle Lock Status
264 |
Resources
265 |
pending
266 |
267 |
268 |
Door Lock Status Resource
269 |
pending
270 |
271 |
272 |
Door Lock Deck Lid Status Resource
273 |
pending
274 |
275 |
276 |
Door Lock Gas Status Resource
277 |
pending
278 |
279 |
280 |
Position Heading Resource
281 |
pending
282 |
283 |
284 |
Vehicle Status
285 |
Container Vehicle Status
286 |
pending
287 |
288 |
289 |
Resources
290 |
pending
291 |
292 |
293 |
Decklid resource
294 |
pending
295 |
296 |
297 |
Front left door resource
298 |
pending
299 |
300 |
301 |
Front right door resource
302 |
pending
303 |
304 |
305 |
Rear left door resource
306 |
pending
307 |
308 |
309 |
Rear right door resource
310 |
pending
311 |
312 |
313 |
Interior front light resource
314 |
pending
315 |
316 |
317 |
Interior rear light resource
318 |
pending
319 |
320 |
321 |
Light switch position resource
322 |
pending
323 |
324 |
325 |
Front left reading lamp resource
326 |
pending
327 |
328 |
329 |
Front right reading lamp resource
330 |
pending
331 |
332 |
333 |
Convertible (roof top) resource
334 |
pending
335 |
336 |
337 |
Sunroof resource
338 |
pending
339 |
340 |
341 |
Front left windows resource
342 |
pending
343 |
344 |
345 |
Front right windows resource
346 |
pending
347 |
348 |
349 |
Rear left windows resource
350 |
pending
351 |
352 |
353 |
Rear right windows resource
354 |
pending
355 |
356 |
357 |
358 | ## Made with ❤️ at Callstack
359 |
360 | This is an open source project and will always remain free to use. If you think it's cool, please star it 🌟. [Callstack](https://callstack.com) is a group of React and React Native geeks, contact us at [hello@callstack.com](mailto:hello@callstack.com) if you need any help with these or just want to say hi!
361 |
--------------------------------------------------------------------------------
/docs/example-query.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/callstack/benz-ql/9ae8859c63eaf49a1f4f8b0d9f4923eca28411f6/docs/example-query.png
--------------------------------------------------------------------------------
/example/index.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable import/no-extraneous-dependencies */
2 | import express from 'express';
3 | import { ApolloServer } from 'apollo-server-express';
4 | import fs from 'fs';
5 | import path from 'path';
6 |
7 | import benzQL, { scopes } from '../src/index.js';
8 |
9 | const app = express();
10 | const PORT = process.env.PORT || 3000;
11 | const server = new ApolloServer({
12 | ...benzQL(scopes.SANDBOX),
13 | introspection: true,
14 | });
15 |
16 | server.applyMiddleware({ app, path: '/benz-ql' });
17 |
18 | app.use('*', (req, res) => {
19 | const stream = fs.createReadStream(path.join(__dirname, 'static/index.html'));
20 | stream.pipe(res);
21 | });
22 |
23 | app.listen(PORT, () => {
24 | console.log(`App listen on ${PORT}`);
25 | console.log(`Benz-ql avaliable on ${server.graphqlPath}`);
26 | });
27 |
--------------------------------------------------------------------------------
/example/static/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | GraphQL Playground
8 |
9 |
10 |
11 |
12 |
13 |
14 |