File tree Expand file tree Collapse file tree 7 files changed +389
-230
lines changed Expand file tree Collapse file tree 7 files changed +389
-230
lines changed Original file line number Diff line number Diff line change 29
29
"eslint-plugin-import" : " ^2.2.0" ,
30
30
"eslint-plugin-prettier" : " ^2.6.0" ,
31
31
"flow-bin" : " ^0.42.0" ,
32
- "jest" : " ^20 .0.0" ,
32
+ "jest" : " ^23 .0.0" ,
33
33
"jest-fetch-mock" : " ^1.0.8" ,
34
34
"prettier" : " ^1.12.1"
35
35
},
Original file line number Diff line number Diff line change
1
+ // @flow
2
+
3
+ /**
4
+ * @property {string } variable - The variable of this field
5
+ */
6
+ export default class Filter {
7
+ property : string ;
8
+ variable : string ;
9
+
10
+ /**
11
+ * @param {string } property
12
+ * @param {string } variable
13
+ */
14
+ constructor ( property : string , variable : string ) {
15
+ this . property = property ;
16
+ this . variable = variable ;
17
+ }
18
+ }
Original file line number Diff line number Diff line change 1
1
// @flow
2
2
3
3
import Field from "./Field" ;
4
+ import Filter from "./Filter" ;
4
5
import Operation from "./Operation" ;
5
6
6
7
type ResourceOptions = {
@@ -9,6 +10,7 @@ type ResourceOptions = {
9
10
deprecated ?: boolean ,
10
11
readableFields ?: Field [ ] ,
11
12
writableFields ?: Field [ ] ,
13
+ filters ?: Filter [ ] ,
12
14
operations ?: Operation [ ]
13
15
} ;
14
16
Original file line number Diff line number Diff line change
1
+ import Filter from "../Filter" ;
2
+ import fetchResource from "./fetchResource" ;
3
+
4
+ export default api => {
5
+ const promises = [ ] ;
6
+
7
+ for ( const resource of api . resources ) {
8
+ let promise = fetchResource ( resource . url ) . then ( response => {
9
+ if ( ! response . filters ) {
10
+ return [ ] ;
11
+ }
12
+
13
+ const resourceFilters = [ ] ;
14
+
15
+ for ( const filter of response . filters ) {
16
+ let property = filter . property ;
17
+
18
+ if ( property === null ) {
19
+ continue ;
20
+ }
21
+
22
+ resourceFilters . push ( new Filter ( property , filter . variable ) ) ;
23
+ }
24
+
25
+ return resourceFilters ;
26
+ } ) ;
27
+
28
+ promises . push ( promise ) ;
29
+ }
30
+
31
+ return Promise . all ( promises ) . then ( values => {
32
+ api . resources . map ( ( resource , index ) => {
33
+ resource . filters = values [ index ] ;
34
+ } ) ;
35
+
36
+ return api ;
37
+ } ) ;
38
+ } ;
Original file line number Diff line number Diff line change
1
+ import fetchJsonLd from "./fetchJsonLd" ;
2
+ import get from "lodash.get" ;
3
+
4
+ export default async entrypointUrl => {
5
+ return await fetchJsonLd ( entrypointUrl , { itemsPerPage : 0 } ) . then (
6
+ d => ( {
7
+ filters : get ( d , "body.hydra:search.hydra:mapping" )
8
+ } ) ,
9
+ ( ) => {
10
+ throw new Error ( "Unreachable resource" ) ;
11
+ }
12
+ ) ;
13
+ } ;
You can’t perform that action at this time.
0 commit comments