@@ -7,48 +7,54 @@ class VFA_ResolverStartupStartup extends VFA_Resolver
7
7
{
8
8
public function index ()
9
9
{
10
- if ($ this ->request ->get_param ('cors ' )) {
11
- if (! empty ($ _SERVER ['HTTP_ORIGIN ' ])) {
12
- header ('Access-Control-Allow-Origin: ' . $ _SERVER ['HTTP_ORIGIN ' ]);
13
- } else {
14
- header ('Access-Control-Allow-Origin: * ' );
10
+ if ($ this ->request ->get_method () === 'POST ' ) {
11
+ if ($ this ->request ->get_param ('cors ' )) {
12
+ if (! empty ($ _SERVER ['HTTP_ORIGIN ' ])) {
13
+ header ('Access-Control-Allow-Origin: ' . $ _SERVER ['HTTP_ORIGIN ' ]);
14
+ } else {
15
+ header ('Access-Control-Allow-Origin: * ' );
16
+ }
17
+ header ('Access-Control-Allow-Methods: POST, OPTIONS ' );
18
+ header ('Access-Control-Allow-Credentials: true ' );
19
+ header ('Access-Control-Allow-Headers: accept,Referer,content-type,x-forwaded-for,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,cache-control,Content-Type,Range,Token,token,Cookie,cookie,content-type ' );
15
20
}
16
- header ('Access-Control-Allow-Methods: POST, OPTIONS ' );
17
- header ('Access-Control-Allow-Credentials: true ' );
18
- header ('Access-Control-Allow-Headers: accept,Referer,content-type,x-forwaded-for,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,cache-control,Content-Type,Range,Token,token,Cookie,cookie,content-type ' );
19
- }
20
21
21
- $ this ->load ->model ('startup/startup ' );
22
- $ this ->load ->model ('common/vuefront ' );
22
+ $ this ->load ->model ('startup/startup ' );
23
+ $ this ->load ->model ('common/vuefront ' );
23
24
24
- try {
25
- $ resolvers = $ this ->model_startup_startup ->getResolvers ();
26
- $ files = array (VFA_DIR_PLUGIN . 'schema.graphql ' );
25
+ try {
26
+ $ resolvers = $ this ->model_startup_startup ->getResolvers ();
27
+ $ files = array (VFA_DIR_PLUGIN . 'schema.graphql ' );
27
28
28
- if ($ this ->model_common_vuefront ->checkAccess ()) {
29
- $ files [] = VFA_DIR_PLUGIN . 'schemaAdmin.graphql ' ;
30
- }
29
+ if ($ this ->model_common_vuefront ->checkAccess ()) {
30
+ $ files [] = VFA_DIR_PLUGIN . 'schemaAdmin.graphql ' ;
31
+ }
31
32
32
- $ sources = array_map ('file_get_contents ' , $ files );
33
+ $ sources = array_map ('file_get_contents ' , $ files );
33
34
34
- $ source = $ this ->model_common_vuefront ->mergeSchemas (($ sources ));
35
- $ schema = BuildSchema::build ($ source );
36
- $ rawInput = file_get_contents ('php://input ' );
37
- $ input = json_decode ($ rawInput , true );
38
- $ query = $ input ['query ' ];
35
+ $ source = $ this ->model_common_vuefront ->mergeSchemas (($ sources ));
36
+ $ schema = BuildSchema::build ($ source );
37
+ $ rawInput = file_get_contents ('php://input ' );
38
+ $ input = json_decode ($ rawInput , true );
39
+ $ query = $ input ['query ' ];
39
40
40
- $ variableValues = isset ($ input ['variables ' ]) ? $ input ['variables ' ] : null ;
41
- $ result = GraphQL::executeQuery ($ schema , $ query , $ resolvers , null , $ variableValues );
42
- } catch (\Exception $ e ) {
43
- $ result = [
41
+ $ variableValues = isset ($ input ['variables ' ]) ? $ input ['variables ' ] : null ;
42
+ $ result = GraphQL::executeQuery ($ schema , $ query , $ resolvers , null , $ variableValues );
43
+ } catch (\Exception $ e ) {
44
+ $ result = [
44
45
'error ' => [
45
46
'message ' => $ e ->getMessage ()
46
47
]
47
48
];
48
- }
49
-
49
+ }
50
50
51
- return $ result ;
51
+ $ this ->response ->set_data ($ result );
52
+ return $ this ->response ;
53
+ } else {
54
+ header ('Content-type: text/html ' );
55
+ echo "<html> <head> <title>Simple GraphiQL Example</title> <link href='https://unpkg.com/graphiql/graphiql.min.css' rel='stylesheet'/> </head> <body style='margin: 0;'> <div id='graphiql' style='height: 100vh;'></div><script crossorigin src='https://unpkg.com/react/umd/react.production.min.js' ></script> <script crossorigin src='https://unpkg.com/react-dom/umd/react-dom.production.min.js' ></script> <script crossorigin src='https://unpkg.com/graphiql/graphiql.min.js' ></script> <script>const fetcher=GraphiQL.createFetcher({url: window.location.href}); ReactDOM.render( React.createElement(GraphiQL,{fetcher: fetcher}), document.getElementById('graphiql'), ); </script> </body> </html> " ;
56
+ exit ;
57
+ }
52
58
}
53
59
54
60
public function determine_current_user ($ user )
0 commit comments