1- var fs = require ( 'fs' )
2-
3- var apiSchema = fs . readFileSync ( './app/prisma/api-schema/api-schema.json' , { encoding : 'utf8' , flag : 'r' } )
4- apiSchema = JSON . parse ( apiSchema ) ;
5- var schemas = Object . entries ( apiSchema . schemas )
1+ var fs = require ( 'fs' ) ;
62
73function getGraphQLSchemas ( ) {
4+ var apiSchema = fs . readFileSync ( './app/api-schema.json' , { encoding : 'utf8' , flag : 'r' } )
5+ apiSchema = JSON . parse ( apiSchema ) ;
6+ var schemas = Object . entries ( apiSchema . schemas )
87 var types = [ ] ;
98 for ( const [ key , value ] of Object . entries ( schemas ) ) {
109 var type = value [ 0 ] ;
1110 var endpoints = Object . entries ( value [ 1 ] ) ;
1211 for ( const [ endpointKey , endpointValue ] of endpoints ) {
1312 if ( endpointValue != null && endpointValue [ 'input_validation_rules' ] != null ) {
14- rules = Object . entries ( endpointValue [ 'input_validation_rules' ] ) ;
13+ var rules = Object . entries ( endpointValue [ 'input_validation_rules' ] ) ;
1514 var startLine = ` type ` + type + ` {`
1615 var fieldLines = { } ;
1716 for ( const [ fieldName , rulesValue ] of rules ) {
@@ -55,12 +54,12 @@ function getGraphQLSchemas() {
5554 ` ;
5655 schemas = Object . entries ( apiSchema . schemas ) ;
5756 for ( const [ key , value ] of schemas ) {
58- queryString = queryString + ' ' + key + ': [' + key + ']\n' ;
57+ queryString = queryString + ' ' + key + ': [' + key + ']\n' ;
5958 }
6059 queryString = queryString + `
6160 }` ;
6261 string = string + queryString ;
63-
62+
6463 return string ;
6564
6665 // GraphQL Schema String example:
@@ -84,6 +83,32 @@ function getGraphQLSchemas() {
8483 */
8584}
8685
86+ function getGraphQLResolvers ( ) {
87+ var apiSchema = fs . readFileSync ( './app/api-schema.json' , { encoding : 'utf8' , flag : 'r' } )
88+ apiSchema = JSON . parse ( apiSchema ) ;
89+ var schemas = Object . entries ( apiSchema . schemas )
90+ var types = [ ] ;
91+ var resolvers = { } ;
92+ for ( const [ key , value ] of Object . entries ( schemas ) ) {
93+ const { Resource } = require ( '../models/resource' ) ;
94+ var resource = new Resource ( value [ 0 ] ) . browse ( ) ;
95+ resolvers [ value [ 0 ] ] = ( ) => resource ;
96+ }
97+
98+ return resolvers ;
99+
100+ /*
101+ // Result should produce an object that looks like this:
102+ var resolvers =
103+ {
104+ Query: {
105+ 'analytic_events': () => data.browse()
106+ },
107+ };
108+ */
109+ }
110+
87111module . exports = {
88- getGraphQLSchemas
112+ getGraphQLSchemas,
113+ getGraphQLResolvers
89114}
0 commit comments