Jump to content

dadish

Members
  • Posts

    124
  • Joined

  • Last visited

  • Days Won

    8

Posts posted by dadish

  1. More updates!

    Here is what was added since my last post:

    • FieldtypeDatetime now supports format argument. Which allows you to pass PHP date format string and retrieve your datetime values formatted the way you want. Besides FieldtypeDatetime fields, the built-in fields created and modified are also support new format argument.
    • FieldtypeOptions is now supported.
    • first and last fields on PageArray types are now supported. As per @eelkenet's request. See above post for details on those.
    • Finally, now there is a way to add support for any fieldtype you want via third-party module. What you need to do is create a module with the name exactly as the fieldtype you want to add support for with "GraphQL" prefix. So for FieldtypeMapMarker it would be GraphQLFieldtypeMapMarker. Then you need to add three required methods and install it. This will automatically add GraphQL support for your desired fieldtype and it will be available in your GraphQL api. Checkout the documentation and an example module for reference.
    • Like 18
    • Thanks 1
  2. On 10/2/2017 at 10:13 PM, eelkenet said:

    Hi @Nurguly Ashyrov, this looks like a great module - thank you for developing it!

    I'm a complete noob to the world of GraphQL, and have been trying for two days to get this module running in combination with Ember.js. If I could get it to work, it sure would be a glorious combination. But so far it has been pretty frustrating :o

    One thing that I keep running into, is that your implementation always returns an array of pages, using the 'list' field* inside the query.
    However, this makes it impossible to request a single page. Even when using something like limit=1 in the selector. 

    For instance, I could imagine this to work fine

    
    {
      basic_page(s: "name:contact") {
        first {
          id
          name
        }
      }
    }

    Which then could return 

    
    {
        "data": {
            "basic_page": {
                "first": {
                    "id": "1017",
                    "name": "contact"
                }
            }
        }
    }

    Basically, any of PW's regular PageArray methods to find something would be a welcome addition ( ie. ->eq(n), ->get(selector), ->first(), ->last(), etc.)

    Is this something I can achieve with the getQuery hook? Or in another way?
    Thanks in advance for any pointers or help. 

    (* I have to say, this use of the field keyword is very confusing for a long time PW user). 

    Hey @eelkenet!
    That seems reasonable to me. I was planning to add those fields. Didn't have time till now. I'll let you know as soon as I implement them.

    You won't be able to add those fields via getQuery hook btw. The getQuery hook is there for very trivial custom fields to be honest. Like your api version number, or your contact data or anything you want to send via GraphQL api without creating templates, fields and pages for it.

    • Like 2
  3. Hey everyone!

    It's been a while since I last had a time to work on this module. But now I finally managed to focus on this module. So here are the latest updates.

    The codebase of the module grew very big and the more features I added the more time I had to spend to make sure the changes I made does not break anything. Because I had to manually verify if everything works as expected. After long night hours of trial and error I managed to setup tests for this module. Tests will help us quickly add/remove features as needed, because now there is no need for manually verifying all edge cases. Also I setup the Travis-CI so people can contribute more confidently and I can merge pull requests without worrying! There are already bunch of tests, but there is still some I'll be adding.

    ? ProcessGraphQL.svg?branch=master ?

    I will add some documentation on how to run tests locally in github wiki pages soon and let you know here.

    Another thing to note is that the master branch of our module no longer tracks the vendor code. This means that if you download the master branch and put it into your /site/modules directory it will not work. Instead you should use release builds that are a cleaned version of the module. It includes required vendor codes and does not have extra files that are not relevant to ProcessWire. Like presentation gif images, test files and so on. This makes the module size smaller!

    • Like 15
    • Thanks 3
  4. 2 hours ago, thomasaull said:

    I Just played around with it a little. Looks awesome so far! It would be great if PageTable was supported, or is it already possible with a workaround?

    PageTable is not supported yet. To be honest I am very busy right now and don't have much time to update this module. So I can't say when additional features will be added. Until then, you'll have to figure out your own way. Sorry :) 

    • Like 1
  5. On 9/28/2017 at 2:32 AM, Rudy said:

    How would you set up authentication to consume GraphQL data remotely?

    Hey, Rudy! I couldn't fully understand your use case. I guess you want to restrict access to certain entities, like your other site. It is very easy to restrict access to certain ip address. Just before serving GraphQL API you could check for the requested entities ip address and behave accordingly. For example:

    <?php
    if ($_SERVER['REMOTE_ADDR'] == 123.234.34.1 ) {
      echo $modules->get('ProcessGraphQL')->executeGraphQL();
    } else {
      echo 'Access Denied';
    }

    I can't say for sure if that's what you are asking though. If not, please give more details on what you are trying to achieve.

    • Like 2
  6. @abdus First of all you don't need to import ProcesGraphQL's vendor.php file. It is done automatically when you do 

    $processGraphQL = modules()->get('ProcessGraphQL');
    

    Second is, I don't see where you include your /site/templates/api/SubscriptionField.php file into graphql.php. So replace the 

    require_once '../modules/ProcessGraphQL/vendor/autoload.php';

    with

    require_once "./api/SubscriptionType.php";

    in your graphql.php and it should work.

    Also, your SubscriptionField class requires the public function getName().

    • Like 2
  7. On 4/8/2017 at 4:58 AM, abdus said:

    Also, is it possible for you to add some hookable functions to the module so that we can add custom queries and mutations?...

    Done! :)

    The latest version now allows you to hook into getQuery & getMutation methods of the ProcessGraphQL class. Those hooks are solely there so you could modify the query and mutation operations. Here how it might look like in your template file.

    <?php namespace ProcessWire;
    use Youshido\GraphQL\Type\Scalar\StringType;
    
    $processGraphQL = $modules->get('ProcessGraphQL');
    
    wire()->addHookAfter('ProcessGraphQL::getQuery', function ($event) {
        $query = $event->return;
      
        $query->addField('hello', [
            'type' => new StringType(),
            'resolve' => function () {
                return 'world!';
            }
        ]);
    });
    
    echo $processGraphQL->executeGraphQL();

    The above code will add a hello field into your GraphQL query that responds with the string "world!". You'll have to use the Youshido\GraphQL library that ProcessGraphQL module uses internally. The same thing could be done with the mutation operation via getMutation  hook method.

    • Like 5
  8. 20 hours ago, abdus said:

    Thanks for the clarification. The problem is that if I dont specify any selector, I get empty array, also an error

    I'm not sure if this is the expected behavior.

    Well now I am embarrassed. :( So sorry. It turns out upgrading to the latest graphql library broke some stuff. For some reason I did not check the queries without the selectors. I made some fixes. This should solve your problem. Please get the latest version and try again.

    • Like 4
  9. 13 hours ago, abdus said:

    When I go to GraphiQl interface, selector argument for template fields does not appear to be optional as it's in the screencast. However, if I provide a selector, it works as expected. Do I need to set up something on backend?

    Hi @abdus. You are good to go actually. The argument is required only when there is an exclamation mark after it. It does not have to be = false. Sorry for the confusion, the way I explain it in screencast is a bit misleading. To sum it up, if there is an exclamation mark "!" at the end, it means it is required, of not then it is optional. The = false part means, the default value is false. I know, it sounds stupid. It was a bug in the library I used for this module. I updated it to the latest version since the screencast and now it shows correctly. The = false part is actually is a bug in older version of the module. You probably installed the latest version which shows correctly.

    So, your version is actually is the way it supposed to be. The version in the screencast is a bit misleading, but still correct.

    • Like 2
  10. 16 hours ago, mvdesign said:

    @Nurguly Ashyrov Hi, is there a way to add images/files to a page with the updatePage method ? If not, do you plan to implement it or do I have to do this another way ?

    Unfortunately not yet. I am planning to implement them. But I am a bit busy now and it would definitely take some time to implement it. For now, you will have to do it some other way. Sorry :( 

    • Like 2
  11. 18 minutes ago, mvdesign said:

    @Nurguly Ashyrov Thanks for the video ! i'm using your module with Vue.js for a web application, really nice. I'm juste facing a problem right now, i get an error when trying to get checkboxes : Not valid resolved type for field \"checkbox_name\" (the field access is allowed in graphql settings). Any idea ?

    Yes. It was my bad. I did not make sure the FieldtypeCheckbox always returned a boolean. I think it returns 0/1 in ProcessWire. Anyways, just patched it. Update to the latest version and it should work.

    Edit: As always, thanks for the feedback.

    • Like 2
  12. On 3/31/2017 at 6:31 PM, Soma said:

    Just wanted to mention I got caught by a redirect scenario and language stuff. :) If you have multilange installed and configured to have language segments "/en/", "/de/" ...  so trying out ajax requests to "/graphql/" would redirect to "/en/graphql/ " but you get a response:

    
    {"errors":[{"message":"Must provide an operation."}]}

    So it took me a while to figure out and was looking at the query instead. Doing the request to "/en/graphql/" works flawless.

    Yeah, I had my nightmares with this situation too. There are lots of scenarios when ProcessWire could redirect your ajax requests and the graphql will not receive the query. The ones that I had encountered were:

    • If the url ends without slash: ...website.com/graphql ==> ...website.com/graphql/
    • If there is now www prefix: website.com/graphql/ ==> www.website.com/graphq/

    And now I guess when languages are enabled you also gotta make sure ProcessWire is not redirecting you to the respective language url of the graphql api. I haven't tested the module with the languages enabled yet, but I am sure there would be some additional caveats.

    On 3/31/2017 at 6:31 PM, Soma said:

    Permission so far seem to work. The template access setting seem no to be inherited, I guess that is intentional? I may have missed it and it was mentioned. Then I'm sorry.  – Like in a default install "home" has guest view access enabled, so all pages inherit that (unless you set it no to). But I had to give basic-page explicit guest view access to get querying. I think it's ok to not have all templates inherit access for graphQL. 

    Yes, that's the expected behavior. Unfortunately to support permission inheritance would be too expensive. Because it means to check template permissions of each ancestor of each returned page. I think the module is already slow and supporting permission inheritance would make it even slower. I guess I have to mention about not supporting permission inheritance somewhere in the documentation of the module.

    23 hours ago, Soma said:

    ... Lol hmm I added it to allowed fields and still same error. System fields "created",  "modified" work fine.

    That's right, it turns out there was a bug. I pushed an update regarding the datetime field. Grab the latest version of the module and it should work properly.

    23 hours ago, Soma said:

    Also if you only want to get one specific page is it correct to do for example a

    
    {
      basic_page(s: "id=1001"){ 
        list{ 
          title
        }
      }
    }

    or are there any other methods?

    Yep. That's the way. I know, it's ugly. But I can't think of a less verbose way to return a single page from the api. We could, of course introduce an additional field for each template like basic_page_single or something. But I don't think it's worth it, plus it will make the schema bigger for very little gain.

    23 hours ago, Soma said:

    So we can request a size that doesn't exist and it will create it if we have rights to do so. Thats would be pretty cool. Would be crazy to allow some stranger creating 1million sizes through public API :). But still if one has write access it is possible, but maybe thats no real issue. 

    I'm still trying to grasp the concept of graphQL and your implementation in PW. So every new Fieldtype and InputfieldType would have to be implemented to work with graphQL?

    I totally agree. We can't allow everyone to create images. The size field of the image type creates images only if the user has an edit permission on that image field. It is still available to the users who do not have edit permission, but only for getting existing variations, and it should return null if there isn't an image variation with the requested size.

    Edit: By the way, thanks a lot for the feedback.

    • Like 4
  13. 5 hours ago, Robin S said:

    Thanks for the video, and also a separate thanks for updating the Skyscrapers profile and making the export of that available. Would it be okay to mention your repo of that over in the Skyscrapers Profile thread so people can use it until we have an official profile release by Ryan?

    Sure, by all means.

    5 hours ago, Soma said:

    @Nurguly Ashyrov awesome cast! Thanks for making all this and taking your time to make it awesome :) This is really cool stuff and opens up a lot of possibilities.

    Thanks. I am glad you like it @Soma.

    • Like 1
  14. Thanks @adrian! I rerecorded the video many times before I could make it watchable. Trust me, you wouldn't say the same thing for the very first ones :D 

    About the field access rules. Yeah that's true. By default the behavior is the opposite to the one in ProcessWire. I think it would be better for security if the module initially treats everything private. But I get what you mean. In cases where you have dozens of fields in one template, it would be too tedious to configure access for each of them. That's why there is an option to reverse the behavior in the advanced section of the module configuration. You can learn more about it here. This option basically makes all fields without Access rules available to the public and you can restrict access by enabling rules only to couple ones.

    • Like 9
  15. On 3/21/2017 at 7:59 PM, mvdesign said:

    Hi, and thanks for this great module :)

    Can you provide an example on how to create/update a page from GraphQL API ?

    Hi @mvdesign. So sorry that I could not respond earlier. I decided to make an introduction video for this module to help people that are trying to use it. But then, I never made a screencast video before, and on top of that, the last time I spoke english was 2011. So I had to take dozens of try-outs till I got something watchable.

    So here is the video. It shows how you would create/update pages with this module. The video is far from OK, so I will probably record another one after I get some feedback. Until then please refer to this video to learn about how the module works.

     

    • Like 23
  16. 19 minutes ago, microcipcip said:

    Now it works!! This is so cool...I wish I could like this thread twice :). Do you have any plan of adding the RepeaterField?

    I am happy it works now :). The plan is to add support for all core fieldtypes. That includes RepeaterField also. I will try to keep everyone updated via this thread, and you can also keep with the changelog.

    • Like 6
  17. 1 hour ago, microcipcip said:

    ...

    Do you know why? If I try the query in the GraphiQl admin I get the right data back. Do I have the wrong permissions set in the module?

    No, it's not the permissions. You're doing everything properly.

    I never tried this module with axios before, therefore this error is new to me. It turns out that axios sets the Content-Type header to application/json;charset=UTF-8 instead of application/json. That's where the problem was, because the ProcessGraphQL module would parse json payload only if Content-Type was set to just application/json. I changed the behavior and now it will look to your query in json payload if Content-Type contains application/json string in it. Please grab the latest version of the module and try again. It should work now.

    Thank you for taking time to report the issue.

    • Like 6
  18. 2 hours ago, teppo said:

    Personally I think that this thread already includes so much great content that it'd be a shame to abandon it -- not to mention that it's more than likely that folks looking for details about this module would end up here anyway.

    It's your choice obviously, but if you want, I (or any other moderator here) would be more than happy to move this thread to the modules section. Just let us know when you have decided what to do with it :) 

    I agree with you on that. I think it would be best if we move this thread to modules section. So, please move it to the modules section. Then after I will update my first post of this thread a bit and add a module tag I guess :) 

    • Like 3
  19. I am happy that you like it @Sebastian, thank you for your support. I started the thread here because I thought this would be more like a discussion on how GraphQL and ProcessWire could fit together and wanted to get some feedback first. But this thread quickly become this module's official place here in the ProcessWire forums. Also @teppo included the link to this thread as the "dedicated support forum thread" in the 143 issue of the weekly.pw (which I was flattered to see :)).

    Now I don't really know how to go on with this thread. Should we abandon it and start new thread in the modules section? Or maybe this thread could be moved to modules section? What @moderators think of this?

    Meanwhile, for those who are following this thread I wanted to mention that there are some additions in the dev branch, such as mutations that allows you to create/update pages and there is also support for FieldtypeMapMarker field. I stopped developing the module for some time because I thought that it needed a good testing before moving further with it and decided to built an SPA using this module, to see if there is something that need to be added or changed. But then I got carried away and started to make usage of third-party APIs such as Wikipedia and GoogleMaps. As a result the app does not make heavy usage of the ProcessGraphQL module, but it is still relevant to showcase the module's abilities. It is a US Skyscrapers app, duh... You can see it live here and the source code here (though I doubt that the code will interest you if you are not a React developer).

    I was finished with this demo SPA just couple of days ago. Now I will be back to continue to work on this module again.

    • Like 11
  20. Hey @bcartier and everyone who is following. I implemented a basic language support. Nothing really changed, except now with LanguageSupport enabled in your ProcessWire app, the GraphQL api will return the content in whatever language the user is assigned.

    In addition, when Language Support module is activated, there is a language field in your GraphQL api. So you can request the exact language you want. It looks like this.

    {
      language(name: "de")
      basic_page{
        list{
          title
          summary
        }
      }
    }

    You need to put the language field on the top. Well, not exactly on top but just before fields that return translatable content, like title, headline, body etc. It's because GraphQL processes requested fields from top to bottom and it will not know what language you want till it gets to language field. Did you also know that in GraphQL you can query same field multiple times with aliases? Here, take a look at this

    {
      basic_page_default: basic_page{
        list{
          title
          summary
        }
      }
      language(name: "de")
      basic_page_de: basic_page{
        list{
          title
          summary
        }
      }
    }

    Curious what will be the response? Try this with site-languages  profile and find out.

    • Like 10
  21. 14 minutes ago, microcipcip said:

    is it possible, for example, to get cropped images? Or more of a general question, can you manipulate the data before you fetch it?

    No there isn't at the moment. There will be support for it of course. The way it will work is if the user has a view access to the image field she will be able to fetch all the available image information, including the thumbnail variations. For user to be able to create thumbnails herself, she will need an edit access for that field.

    • Like 4
  22. @Oliver, @bcartier Thanks guys. Glad you like it.

    3 hours ago, bcartier said:

    Does this handle Language fields yet? For example, I have translated titles, summaries for an "article"  template, and I've allowed the article template, along with the "title" and "summary" fields in the module settings, but the the translatable fields are still not available through GraphiQL, even though the other non-translatable fields are. 

    No, Language fields are not supported yet. There will be support for them too. Maybe I will implement them this weekend. In any case I will let you know when they are available.

    For those who are following this module, I make releases almost everyday. Sometimes I introduce new bugs but patch them as soon as I find them. There are bunch of features added since the first introduction. You can follow up the changes/additions in the changelog. Lots of parts are not documented yet but I will provide full documentation and possibly introduction video targeted to ProcessWire users, on what the module is about, how you can use it, along with some todo app tutorial.

    But for now, feel free to play with it and provide some feedback either here or in issue tracker. It is always easier to make changes in the beginning.

    • Like 9
  23. Hey @zota. I made some changes on how the GraphiQL assets are loaded in the admin interface. Before that it was a quick stupid hack, sorry. Now it is as it supposed to be loaded for Process modules. I don't know why I didn't do it from the start. Please remove the old version and install the latest from repository. The error you are getting will most likely go away.

    • Like 3
  24. 6 hours ago, zota said:
    
    Parse Error: syntax error, unexpected '^', expecting ']' (line 9 of /home/zota/www/pw-logica/site/modules/ProcessGraphQL/GraphiQL/build/static/js/main.059c7daf.js) 

    Any clue?
    thanks

    Just to make sure. Is this a PHP error, or is it a JavaScript error in your browser console?

    Could you also give some environment details. Which version of PHP, ProcessWire?

    • Like 1
×
×
  • Create New...