Jump to content

dadish

Members
  • Posts

    115
  • Joined

  • Last visited

  • Days Won

    8

Everything posted by dadish

  1. Glad to see you progressed on this. The /processwire/setup/graphql/ is for internal/admin use only. You should focus on the /graphql/ endpoint.
  2. Hello @Matoseb, I haven't used any of the pro fields, myself. So I don't know much about them. But conceptually they should be very similar to list of pages. You should take a closer look what I do in PageType. I create the fields of the page by inspecting it's template. I don't know what kind of API the repeater_matrix_type has, but I suspect similar. But even then, I have a separate type generator for each supported field. If RepeaterMatrix does not use those as underlying FieldType classes, then you'll have to recreate for each of them on your own. Yes, but the bulk of the work would be implementing the equivalent of PageType that would be responsible for creating types for each repeater_matrix_type. The PageArrayType simply wraps the PageType into an array and adds things like pagination, first item, last item, total count, etc. Sorry bud. The ProFields are out of the scope of this plugin.
  3. Hi @ngrmm. I suggest you to start debugging the request from your template. Depending on how you are sending the request, first try to simply echo it. In your template, simply echo back the graphql request. Could look something like this. <?php echo $input->post('query'); // Or: // echo $_POST['query'] // Or: // $rawBody = file_get_contents('php://input'); // $requestData = json_decode($rawBody ?: '', true); // echo $requestData['query'] And see if your PW installation correctly receives the graphql request. You can look at how GraphQL module makes different attempts to capture the request itself here. https://github.com/dadish/ProcessGraphQL/blob/530a72e349d7a262d26af9452f5681fa36ee5d33/ProcessGraphQL.module#L161-L183 When you find out a proper way to capture a request in your template file, you can manually pass the request to the Graphql module. Something like below <?php $query = $input->post('query'); $variables = $input->post('variables'); echo json_encode($modules->get('ProcessGraphQL')->executeGraphQL($query, $variables), true); Let me know if this helps.
  4. Whatever it is, I suspect it's causing problems. Try changing the field type for job_title to another field that ProcessGraphQL module supports and see if the error is gone. Then, if it is possible you can share your custom field in github and I can take a look at it.
  5. Hi @Tom.. I am trying to figure out what is EntryCreateInput type. Looks like you're extending graphql module somehow. If you can tell me more about that input type, I might be able to figure out the problem.
  6. Or in other words, it would force people to use a predefined method of authentication, instead of allowing them to use their own preferred version. Some people may prefer JWT tokens, others might want cookie based auth or maybe people need to use third party authentication like AWS Incognito..., the list goes on.
  7. I would prefer people implement their own authenticaton/session flow. The thing you describe above should be simple to implement with the ProcessGraphQL::getMutationFields hook. I think I will remove the login(name: "name", pass: "pass") query field in the future and add a clear documentation/example on how you could implement your own authentication flow. Thanks a lot for the idea @Tom.. I think it would be more flexible this way.
  8. You can do it manually on the ProcessWire side. Before returning the result to the client, simply do the JS trick that you posted in PHP and return the result to the client.
  9. Hey Tom. What do you mean "using Node JS server?" Do you mean where the JavaScript files coming from? If that's your question, then it should not matter. It does not matter where the javascript files are coming from. I did a little research and found out that it works in Firefox but not in Chrome. I don't use Chrome, that's why I couldn't reproduce your issue. Have you tried the above JS code in Firefox? If not please try it out and tell me the results. If that works then we will work on fixing it for the Chrome browser.
  10. Haven't tried it, but something like this should work. https://webonyx.github.io/graphql-php/getting-started/ Scroll down to the first example and see how fields are defined in GraphQL. In your case it should look similar to this. <?php $fields[] = [ 'name' => 'intro', 'type' => Type::string(), 'resolve' => function ($page) { return $page->intro; } ]; Play around with it and you'll get there.
  11. No problem. Sorry for not answering sooner. I used fetch api. Just like you. Sure. I created a sample app with create-react-app. Then I start the app with `npm start`. And here is my App.js file. const query = async (query) => { const res = await fetch("https://skyscrapers.nurgulyashyrov.com/graphql/", { method: "POST", credentials: "include", headers: { "Content-Type": "application/json", Accept: "application/json", }, body: JSON.stringify({ query }), }); const json = await res.json(); console.log("json", json); }; const execute = async () => { await query(`{ logout { statusCode }}`); await query(`{ me { name }}`); await query(`{ login(name: "name", pass: "pass") { statusCode } }`); await query(`{ me { name }}`); }; execute(); function App() { return null; } export default App; Note that the app starts a server that runs on http://localhost:3000. If you are testing by simply opening a file in the browser then it will probably not work. So you need your browser address bar to start with http(s):// and not with file:/// EDIT: You will have to substitute the url with your own, of course. The graphql api is setup exactly as in my previous post. I assume you noticed that the CORS headers are inside the cors() function and that you have to call that function before final response.
  12. Here is the CORS setup that works for me. <?php // https://github.com/dadish/ProcessGraphQL/blob/622c9db61cb7cf3ef998edb31e4e0e47b3c96669/test/server.php#L20-L43 function cors() { // Allow from any origin if (isset($_SERVER['HTTP_ORIGIN'])) { // Decide if the origin in $_SERVER['HTTP_ORIGIN'] is one // you want to allow, and if so: header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}"); header('Access-Control-Allow-Credentials: true'); header('Access-Control-Max-Age: 86400'); // cache for 1 day } // Access-Control headers are received during OPTIONS requests if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) // may also be using PUT, PATCH, HEAD etc header("Access-Control-Allow-Methods: GET, POST, OPTIONS"); if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}"); exit(0); } } Could you try it and let me know if it solves your problem with different domains?
  13. Probably because there are some conditions that are required. One of those things is that in order for user to be able to create a page they require a `page-create` permission for the template that is going to be created, but also `page-add` permission for the template that will be a parent of the created page. You could probably achieve this by just removing some mutation fields with hooks. Should look something like below. <?php $wire->addHookAfter("ProcessGraphQL::getMutationFields", function (HookEvent $event) { $fields = $event->return; $newFields = []; foreach ($fields as $field) { if (!in_array($field['name'], ['updatePost', 'updateComment'] )) { // list the name of mutation fields you want to disable $newFields[] = $field; } } $event->return = $newFields; }); Make sure this code is run before the module has responded to the query. Before $modules->get('ProcessGraphQL')->executeGraphQL() Thanks. Will update. 👍
  14. Login should work as regular processwire login flow. Just do a first request as { login(name: "username", pass: "password") { statusCode } } Then all subsequent requests from the browser will automatically include the processwire cookies.
  15. @markus_blue_tomato I assume job_group is a page field. Page fields in GraphQL return Page interface that has only built-in fields (id. name, url...). If you want to get custom fields like (title, job_group_id...) you need to use fragments. { jobDetail { list { id job_name job_group { list { id name ... on JobGroupPage { // <== you need to use the actual type name here title job_group_id } } } } } }
  16. Make sure you have rights to see it in insomnia. You probably not authenticated in insomnia, which means you're a guest user and those fields are not configured to be accessible by the guest user. Can you check if my assumptions are correct?
  17. Hi @markus_blue_tomato. Do you see your fields in PW admin? At Setup -> GraphQL page?
  18. New Release v1.3.0 Adds support for Page interface. Updates webonyx/graphql-php to the latest version. Adds hook that enables to modify the GraphQL schema. (#26 @sebastiandittrich) Fixes error when creating/updating a page with DateTime field. (#28 @sebastiandittrich) @sodesign Not sure if you still need this but this release brings support for interfaces that I previously talked about. Hope you'll find it helpful.
  19. You can add support for Repeater Matrix Fieldtypes via custom third-party modules. Refer to documentation on how you can create one. https://github.com/dadish/ProcessGraphQL#third-party-fieldtypes-support
  20. You need to use the language field. In your graphql endpoint there is a language field. So it will look like { language(name:"<language_name_here>") test { list { testtext } } }
  21. For some reason this is an issue only with this module. You're not the first one to stumble on it. I updated the Readme to add Troubleshooting section that explains this issue in details.
  22. @Miguel Scaramozzino Also, just wanted to confirm with you that you're making request to the correct url. In default PW settings "/graphql" and "/graphql/" are different. If you happen to make a request to "/graphql" (without forward slash at the end) it will be redirected to "/graphql/" and the content of your POST request gets lost in the middle.
  23. In your graphql template file. Try manually extracting the query and variables and passing them to ProcessGraphQL. Should looks something like this. <?php namespace ProcessWire; header('Content-Type: application/json'); $query = $input->post->query; $variables = $input->post->variables || []; echo json_encode($modules->get('ProcessGraphQL')->executeGraphQL($query, $variables), true); It might be slightly different how you extract the query but the bottom line is make sure you're getting it in your graphql template file and passing it to ProcessGraphQL.
  24. Can you post the code in your graphql.php template file. My only guess is that something happening in that file.
  25. I understand why you are asking for this feature. You're not the first one. But it's not as obvious as it seems. The 'title' field is not the same as all other built-in fields. You can't modify the behavior of the built-in fields per template basis. Which means they all behave the same no matter what template the page has. That's why we have a generic type 'Page' that has all the built-in fields. No matter what template the page we can confidently serve those fields for every page. The 'title' field's behavior could change depending on the template. I understand that it is almost never the case, but semantically it is. For example, you can set different access settings for 'title' field depending on the template. You make it that user can view the 'title' on one template and not on the other. You can change the description of the field for each template and it will appear in the GraphQL documentation. You can also make 'title' field 'not required' for one template and 'required' for others. So, including 'title' field into the Page type will break the semantics. I understand that 'title' field is almost always treated as a built-in field but I just can't overcome this feeling that it is the 'wrong' way to do it. I would like do it only the 'right' way. And the right way brings us to your second question. If we implement it properly and add the ability to get the values of the template fields for generic Page types, then 'title' field should also be solved. For this we will be adding interfaces. It will allow you to get template fields for Page types by providing a template. It will look something like this. { city{ list{ children{ # <== let's say children are the pages with template skyscraper and architect list{ id name ... on SkyscraperPage { # <== you basically say: "for skyscraper pages give me these fields" title images{ url width height } } ... on ArchitectPage { # <== "and for architect pages give me these fields" born email resume{ url filesize } } } } } } } this way you can fetch values for all template fields on Page types. This will work with everything that returns a Page type. Including 'child', 'children', 'parent', 'parents' and Page Reference fields too. And the best part is, it will be semantically correct! 😄
×
×
  • Create New...