https://github.com/github0013/empty_yaml_load
https://github.com/github0013/empty_yaml_load
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/github0013/empty_yaml_load
- Owner: github0013
- License: mit
- Created: 2018-11-09T04:20:07.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-12T00:36:37.000Z (over 7 years ago)
- Last Synced: 2025-01-23T05:15:49.837Z (over 1 year ago)
- Language: CSS
- Size: 328 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# A way to query on an empty array yaml data
Yaml files are in [src/data][1]. If you simply create a yaml file with an empty array, the yaml file won't be picked up as a graphql query type at load.
e.g.
```
# src/data/empty_array.yml
[]
```
query like this will fail since `allEmptyArrayYaml` itself doesn't exist.
```
{
allEmptyArrayYaml{
edges{
node{
character
}
}
}
}
```
To avoid this query type mis-load, I placed a dummy type definition yaml (`type_def.yml`) file in [src/data/array][2] and [src/data/empty_array][3]. Then, when to query, filter the definition data to fetch only needed.
e.g.
```
{
# unfilterd all results
allArrayYaml{
edges{
node{
data{
character
}
}
}
}
# unfilterd all results
allEmptyArrayYaml{
edges{
node{
data{
character
}
}
}
}
# remove definition data
# shows array data in object.yml
filteredAllArrayYaml: allArrayYaml(filter:{ data:{elemMatch:{typeDef: {ne: true}}}}){
edges{
node{
data{
character
}
}
}
}
# remove definition data
# returns null instead of [], but it won't cause a build error
filteredAllEmptyArrayYaml: allEmptyArrayYaml(filter:{ data:{elemMatch:{typeDef: {ne: true}}}}){
edges{
node{
data{
character
}
}
}
}
}
```
[1]: https://github.com/github0013/empty_yaml_load/tree/master/src/data
[2]: https://github.com/github0013/empty_yaml_load/tree/master/src/data/array
[3]: https://github.com/github0013/empty_yaml_load/tree/master/src/data/emtpy_array