Jump to content

dadish

Members
  • Posts

    124
  • Joined

  • Last visited

  • Days Won

    8

Posts posted by dadish

  1. On 3/8/2024 at 8:53 AM, louisstephens said:

    I was just curious if anyone has tried installing this lately and ran into any problems regarding "Module requirements are not fulfilled so installing may cause problems."..  The module page lists that the required versions is >= 3.0.62 but when I go to install the module it is saying >= 3.0.210 is required. I am currently running 3.0.98 and if I go through with the install I get a warning regarding that I am not meeting the processwire requirements. It seems to install just fine, but I was just worried of creating other issues if I proceeded.

    I updated the requirement in the code but forgot to update the requirements listed in the docs. My bad, I'll try to update it this weekend or so.

    Unfortunately we don't have bandwidth to test and support all the ProcessWire versions. So, just to be safe, we default to the later versions. Generally speaking though, ProcessWire is very stable and rarely break anything with patch updates. As long as it works without problems you should be good to go. One thing to keep an eye though, is PHP version. The underlying library (webonyx/graphql-php) requires PHP version `^7.4 || ^8`. So make sure you meet that requirement.

    • Like 1
  2. On 3/5/2024 at 10:10 AM, CrazyAppel said:

    I could obviously solve this by renaming the options in my dropdown but that would break functionality in other places and would make my work a lot harder. I'm wondering if there is any other approach to this besides renaming the dropdown values.

    Not sure what to tell. You can use hooks and create an alias field that would work with GraphQL and add hooks that would sync with your current dropdown field. But that is a bit hacky and will need to be kept up to date with every new logic that involves your dropdown field. You might as well rename your dropdown option names throughout your code if it is just renaming it.

    As for the future, my personal advice for ProcessWire users, do not use FieldtypeOptions. Just use FieldtypePage for dropdowns, radio buttons or any type of options field. FieldtypePage takes a bit more time to set up properly as an options field, but in the long run it is always a better approach and much easier to deal with.

    On 3/5/2024 at 10:10 AM, CrazyAppel said:

    Maybe unrelated to ProcessWire, I'm running a Vue application that executes queries using Axios on my PW backend. Initially, I kept getting a CORS related error:

    Sorry, but you'll have to figure that out for yourself. Ask ChatGPT or Google about how to make PHP server to allow requests from any origin.

    • Like 1
  3. 3 minutes ago, martind said:

    i don't think it's a problem with the module, in postman everything works finde. the session consists. But the react app seems to do here something diffrent.

    Most likely the react app is not including the cookie headers in it's requests. Like I mentioned before, sometimes you need to explicitly include them. Like for the fetch api you need to set credentials option to "include".

  4. 1 hour ago, martind said:

    So, do i have a possibility on the serverside to prevent this?

    Prevent what exactly? I'm still trying to understand what you're trying to achieve. You want all those requests to log under a single session id? Because it's the same person?

    1 hour ago, martind said:

    When quering access restricted contents it comes to problems.

    What kind of problems? The logged out user gets access to restricted content which you want to prevent? Or the logged in user can't get the content that it should have access to?

  5. 13 minutes ago, martind said:

    i have some content queries that get executed as guest, later comes a login query.
    after that, the previous content queries further get executed as guest (with the old session id), where eg. the me query gives me the correct user data.
    so the guest session remains in place for all queries executed before login.
    What is the beste way to prevent this?

    Not entirely sure if I understood you correctly. Once you login, subsequent requests will include the session cookies that were set by ProcessWire.

    If you want to omit cookies for certain requests, then you probably can explicitly exclude cookies in your ajax calls? For example if you're using fetch api, you can omit the credentials when executing a request.

  6. On 10/14/2023 at 5:09 PM, Matoseb said:

    Is there a way to query any page based on their url?

    This, without even knowing their template name.

    No, we don't have that ability. We had it as an experimental feature in initial version of the module. But we dropped it because of the security concerns.

    Could you describe a hypothetical, real world example where you would need it? If I am convinced that it is a popular use case I might consider adding it back.

  7. Hey @sodesign

    On 10/4/2023 at 4:46 PM, sodesign said:

    I wonder if you can help with a recent issue I've had since updating Processwire core from 3.0.200 to 3.0.227+?

    I tested the module against the latest ProcessWire(3.0.229) and it works. It performs mutations. See the screenshot below.

    My best guess is that there is something doesn't work with your custom mutation. But it's hard to find out what it is, because I don't know what it does.

    The error message points to the graphiql client script. But I am not sure why it's failing for you and not for me.

    One thing I can suggest is to debug this without the graphiql. Make the request from your script and log the response/error and see if that gives some more insight.

    Meanwhile I'll try to upgrade the graphiql to the latest version. Maybe that will solve your problem.

    Screenshot 2023-10-08 at 11.19.19.png

  8. 1 hour ago, martind said:

    i have this values and have to provide it over the api for an upcoming expansion step. Isn't it possible to add such fields with a getQueryFields hook instead the modules field configuration? How do you handle such cases for existing sites and data?

    Not sure tbh. I would create an alias field. Create the a similar field. If your field is called `options` call the alias field `options_graphql`. Set the same set of options to your alias field, but make sure to have their title be prefixed with some word. So if your options are `1, 2, 3` then have your alias options `gql_1, gql_2, gql_3` or similar. Add the `options_graphql` field into graphql. Then use hooks to synchronize the two fields when page is saved and loaded with `Pages:saveReady` and `Page:loaded` hooks.

    • Like 1
  9.  

    On 4/18/2023 at 2:28 PM, martind said:

    What is the best way to avoid naming conflicts when querying Option-Select Field with values starting with numbers, which breaks the Schema. This occures when adding the (options) field in the module config screen for fields to serve.

    Hey @martind,

    So I looked into this and it looks like it's not possible. The values for the FieldtypeOptions are described in Enums. The values for the Enums in GraphQL spec should conform to the GraphQL Name. Which must start with a letter and followed by zero or more letters and/or numbers. So an option in the FieldtypeOptions that starts with or only have digits will not compile properly.

  10. On 1/2/2022 at 12:55 AM, ngrmm said:

    UPDATE: seems it has something to do with my site-settings
    I tried it in JS and it works

    Glad to see you progressed on this.

    On 1/2/2022 at 12:55 AM, ngrmm said:

    However when I use /graphql/ as URL i see an object in the console. When I use /processwire/setup/graphql/ I see a json in the console

    The /processwire/setup/graphql/ is for internal/admin use only. You should focus on the /graphql/ endpoint.

  11. 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.

    4 hours ago, Matoseb said:

    The way RepeaterMatrix works is it is differentiating the types based on the repeater_matrix_type. It doesn't seem to work with templates. I tried to use the constructor `new Template()` to create some based on this property but I don't know where to add this line.

    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.

    5 hours ago, Matoseb said:

    Also should I create a new RepeaterMatrixPageArrayType based on your PageArrayType?

    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.

    5 hours ago, Matoseb said:

    Any chance you would take a look? I know it's a ProField, but if you got some time I would be very grateful

    Sorry bud. The ProFields are out of the scope of this plugin.

  12. 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.

  13. 5 hours ago, Tom. said:

    It's just a default text field with the HTML Entity Encoder enabled. 

    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.

  14. 2 minutes ago, Tom. said:

    That would suit most peoples needs. It would make it more feature rich out of the box.

    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.

  15. 4 minutes ago, Tom. said:

    Seems really simple to implement. I'm unsure whether it's worth shipping with that functionality or have people build it in? What do you think @dadish?

    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.

  16. On 7/25/2021 at 11:30 PM, zynth said:

    Is there a way to transform the data like that before it is returned to my frontend, like make the list operation return the object instead of an array when the list operation result only yields one item?

    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.

    • Like 2
  17. 5 hours ago, Tom. said:

    May I ask if you are using Node JS server? I believe this may be the reason it's not working as mine is apache with vanilla JavaScript.

    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.

     

    • Like 3
  18. 11 hours ago, Neue Rituale said:

    Hi Guys,

    i want to get a hooked page property into my graphql schema. Does anybody know how i can configure/implement this?

    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.

    • Like 1
  19. 42 minutes ago, Tom. said:

    Shameless Bump ?

    No problem. Sorry for not answering sooner.

    On 7/16/2021 at 6:39 PM, Tom. said:

    Didn't work for me, maybe it's an issue with Fetch API. What do you use to make your HTTP requests? 

    I used fetch api. Just like you.

    On 7/16/2021 at 6:39 PM, Tom. said:

    Better still, could you provide me with example code where you have CORs working through JavaScript requests?

    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.

    • Like 1
  20. On 7/8/2021 at 1:24 PM, Tom. said:

    I have corrected my cors headers so it doesn't return an error, but it's still not working. Have you had any success having the login work cross-origin? I imagine so as this is a pretty common use case for use an API cross-origin. 

    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?

  21. 1 hour ago, Tom. said:

    Also, I'm logged in as Admin (superuser) and I can't seem to use the mutation to "create" only "update" and I can't seem to find the reason why. How do I add the ability to create pages?

    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.

    2 hours ago, Tom. said:

    Also is there an option to create pages but not edit them. It isn't possible with the permissions on ProcessWire, but I wouldn't want people exploiting the API and editing content, but I would like user submitted content. e.g. storing form submission data.

    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()

    4 hours ago, Tom. said:

    "Adds me query field. Allows user to query her credentials."

    Should be "Allows user to query their credentials." 

    Thanks. Will update. ?

    • Like 1
  22. 11 hours ago, Tom. said:

    Figured it out, I needed to give Guest permissions to access. I was wondering how do you do the login flow through JavaScript so I can make requests that only certain users could view, I like the fact that this uses ProcessWires permission system! Very clever. 

    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.

    • Like 1
  23. @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
              }
            }
          }
        }
      }
    }

     

    • Thanks 1
  24. 3 minutes ago, markus_blue_tomato said:

    but still not in Insomnia Client...

    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?

×
×
  • Create New...