Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphql tooling #166

Merged
merged 4 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pytest = ">=2.7.2"
PyYAML = ">=5.1"
rdflib = ">=6.0.0"
vss-tools = {editable = true, path = "."}
graphql-core = "*"

[dev-packages]

Expand Down
34 changes: 25 additions & 9 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Examples on tool usage can be found in the [VSS Makefile](https://github.com/COV
[vspec2ocf.py](contrib/ocf/vspec2ocf.py) | Parses and expands a VSS and generates a OCF specification | Contrib (Obsolete, no longer functional) | - |
[vspec2proto.py](contrib/vspec2protobuf.py) | Parses and expands a VSS and generates a Protobuf specification | Contrib (Beta) | - |
[vspec2ttl.py](contrib/vspec2ttl/vspec2ttl.py) | Parses and expands a VSS and generates a TTL specification | Contrib | - |
[vspec2graphql.py](contrib/vspec2graphql.py) | Parses and expands a VSS and generates a GraphQL specification | Contrib | - |
[vspec2graphql.py](contrib/vspec2graphql.py) | Parses and expands a VSS and generates a GraphQL specification | Community Supported | [Documentation](docs/VSS2GRAPHQL.md) |

## Tool Architecture

Expand Down
129 changes: 0 additions & 129 deletions contrib/vspec2graphql.py

This file was deleted.

72 changes: 72 additions & 0 deletions docs/VSS2GRAPHQL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
## vspec2graphql

This exporter allows to automatically generate a graphql schema that can represent VSS data.
The resulting schema does only allow querying information. Mutations are not supported.

The resulting schema will look something like this:
```
type Query {
vehicle(
"""VIN of the vehicle that you want to request data for."""
id: String!

"""
Filter data to only provide information that was sent from the vehicle after that timestamp.
"""
after: String
): Vehicle
}

"""Highlevel vehicle data."""
type Vehicle {
"""Attributes that identify a vehicle"""
vehicleIdentification: Vehicle_VehicleIdentification
...
}

type Vehicle_VehicleIdentification {
...
}
...
```

Leaves look like this:
```
"""Vehicle brand or manufacturer"""
type Vehicle_VehicleIdentification_Brand {
"""Value: Vehicle brand or manufacturer"""
value: String

"""Timestamp: Vehicle brand or manufacturer"""
timestamp: String
}
```

Every leaf has a timestamp. This is supposed to contain the date of the last modification of the value.
Queries can then filter data that has been recorded after a given timestamp.

### Additional leaf parameters

As for `timestamp` in some scenarios it makes sense to add certain metadata like the `source` of a
served signal or additional privacy information. Therefore the tool has an additional calling parameter
`--gqlfield <name> <description>`, which takes the name and description of the additional field, like:

```
--gqlfield "source" "Source System"
```

Resulting in the following leaf in the schema:

```
"""Vehicle brand or manufacturer"""
type Vehicle_VehicleIdentification_Brand {
"""Value: Vehicle brand or manufacturer."""
value: String

"""Timestamp: Vehicle brand or manufacturer."""
timestamp: String

""" Source System: Vehicle brand or manufacturer."""
source: String
}
```
17 changes: 17 additions & 0 deletions vspec2graphql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3
#
#
# (c) 2022 BMW Group
#
# All files and artifacts in this repository are licensed under the
# provisions of the license provided by the LICENSE file in this repository.
#
#
# Convert vspec2grahql wrapper for vspec2x
#

import sys
import vspec2x

if __name__ == "__main__":
vspec2x.main(["--format", "graphql"]+sys.argv[1:])
3 changes: 2 additions & 1 deletion vspec2x.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import sys
import vspec

from vssexporters import vss2json, vss2csv, vss2yaml, vss2binary, vss2franca, vss2ddsidl
from vssexporters import vss2json, vss2csv, vss2yaml, vss2binary, vss2franca, vss2ddsidl, vss2graphql



Expand All @@ -34,6 +34,7 @@ def export(config: argparse.Namespace, root: VSSNode):
binary = vss2binary
franca = vss2franca
idl = vss2ddsidl
graphql = vss2graphql

def __str__(self):
return self.name
Expand Down
Loading