Jump to content

dadish

Members
  • Posts

    113
  • Joined

  • Last visited

  • Days Won

    8

Posts posted by dadish

  1. Please test your query in a Graphiql. Insert your query in the Graphiql and confirm that the "product_single.list" is an array of nulls. Now remove every field inside the list and leave "id" and confirm that the list now contains objects with single "id" property in it. If that was successful then keep adding your "product_single" fields one by one. Whenever you see that the list is an array of "null"s, it means that exact field is causing this issue.

    • Like 1
  2. Just now, patricktsg said:
    
    	// Build the query passing in the filters
    	productQuery: function(args) {
    		const PARAMS = args;
    		var data = {
    		    query: `
    		      query Products {
    				  product_single (s: ${PARAMS}) {
    				    list {
    				      title
    				      httpUrl
    				      product_code
    				      body_plain_text
    				      body
    				      product_primary_thumb {
    				        httpUrl
    				        size(width: 800, height: 600) {
    				          httpUrl
    				        }
    				      }
    				    }
    				    getTotal
    				  }
    		        }
    		      `
    		  }  
    		  return data;
    	},

    I was able to reproduce the similar response from your api. Seems like your guest user might not have access to one of the fields of the "product_single" page. You'll have to go to each of the "product_single" page fields that you are querying and make sure Access is enabled and the guest user has a view access to it.

    • Like 1
  3. @patricktsg

    As far as I understand, it's not the httpUrl you are having the problem with. It's the "item" in "item.httpUrl". The error "null is not an object" in JS means you're trying to access a property of a null, in this case "item". So whatever the "item" is in your query, you're getting "null" for it from your api. Then in your JS you're trying to access "httpUrl" of the "null" when you do "item.httpUrl". Hence the "null is not an object" error.

     

    So make sure your "item" is not null when returned from the api. If the "item" is a page, make sure the user (in this case guest) has access privileges for that page.

    • Like 1
  4. On 8/29/2018 at 3:11 AM, bcartier said:

    Love this module, but I'm concerned about the speed. In my tests, a native template returning the same records and data as the GraphQL endpoint:

    Returning 20 pages and some details about  page references:

    Native Template: 0.4s
    GraphQL Endpoint: 3.2s

    Is this performance something that could still be improved? 

    Unfortunately I haven't had much time in optimization for this module. I'm very busy so can't promise any timelines when this will happen. The only thing you can do now is to keep your graphql schema as small as possible by unchecking all the unwanted fields and templates in the module config page.

    There is supposed to be a way to cache the schema (https://github.com/youshido-php/GraphQL/pull/37) I was planning to look into it. But never had a time for it and thus is not implemented in this module yet.

    • Like 1
  5. On 9/17/2018 at 8:37 PM, patricktsg said:

    How do you get the name of Pages from a Page Reference field? I have one called 'colors' and it only lets me get the following total, limit, start - no means to get colors -> name or title

    It should be like this

    {
      product_single (s: "parent=X") {
        list {
          title
          product_code
            colors {
              getTotal
              getLimit
              getStart
              list { // list of colors
                name // name for each color
              }
            }
          }
        }
      }
    }

     

    • Like 1
  6. 21 hours ago, Karl_T said:

    Thank @dadish for this great module. I liked this post long time ago. I just have a chance to get my hand dirty on it. It turns Processwire to a powerful headless CMS with no pain! I am going to use this in my next project with Vue.js or Nuxt.js. 😋

    One noob question. Could this module query and mutate session data? I have modules that read/write user, including the unsigned guests, session data. I have no idea how to make it happen using only a GraphQL end point.

    Hi @Karl_T.

    The module has no ability to modify the session data. It only can modify PW pages. AFAIK session data is not stored as pages.

    What you can do is add a custom GraphQL mutation field for modifying your session. But that would require you to learn GraphQL and the PHP library that we use. Here is how it might look like

    <?php namespace ProcessWire;
    
    use Youshido\GraphQL\Type\Scalar\BooleanType;
    use Youshido\GraphQL\Type\Scalar\StringType;
    use Youshido\GraphQL\Type\Scalar\IntType;
    use Youshido\GraphQL\Execution\ResolveInfo;
    
    $processGraphQL = $modules->get('ProcessGraphQL');
    
    wire()->addHookAfter('ProcessGraphQL::getMutation', function ($event) {
        $mutation = $event->return;
        $mutation->addField('modifySessionData', [
            'type' => new BooleanType(),
            'args' => [
              'foo' => new StringType(),
              'bar' => new IntType(),
            ],
            'resolve' => function ($value, array $args, ResolveInfo $info) {
              $success = false;
    		  // modify session data here...
              if ($something) {
                $success = true;
              }
              return $success;
            }
        ]);
    });
    
    echo $processGraphQL->executeGraphQL();

    And then the query for this could look like this

    mutation {
      modifySessionData("foo": "boblibob", "bar": 12234)
    }

    Haven't tried it. So there might be something I'm missing. But I hope this gives you the idea of how you can achieve what you want.

    • Like 6
    • Thanks 1
  7. 8 hours ago, Zeka said:

    @dadish

    While installing the module I get 

    
    require_once(): Failed opening required ' ... modules/ProcessGraphQL/vendor/autoload.php'

    There is no 'vendor' folder on the master branch, but it exists on dev branch. Am I missing something? 

    Hi @Zeka. You should not install the main repository of the module. The main repository of the module is intended only for development of the module. You can install the module in two ways:

    • By module classname. Go to Modules -> Site -> Add New in your PW admin and write `ProcessGraphQL` in Module Class Name field and press Download and Install button.
    • By a zip file. You need to download the module for installation from the releases page of the module. There you can download a .zip file and place it's contents to the site/modules/ directory of the module.
    • Like 2
  8. On 4/2/2018 at 10:09 PM, chumneypwire said:

    @dadish I guess I have one question in regards to actually obtain an output in templates (sorry I am really new to ajax in general). I currently have

    
    $result = $modules->get('ProcessGraphQL')->executeGraphQL($query, $variables);

    in my header of a file, but need to have an "operation" included. I was testing it out with just trying to get the title and body of the current page. I geuss I am a little unsure of how to get started with this.

    You shouldn't use it to obtain output in your template file. ProcessWire already comes with the best API to access your content. The purpose of the GraphQL module is to let you access content via AJAX, using JavaScript from client side.

    • Like 1
  9. On 4/5/2018 at 7:47 PM, louisstephens said:

    Not really sure if this is the best place to post this (or if it belongs in the thread for the module itself, but if it needs to be moved please do so. I successfully got graphql set up and love how easy it makes it to query etc. 

    In my endpoint, I have:

    
    echo $modules->get('ProcessGraphQL')->executeGraphQL();

    And on another page, I was testing with:

    
    $.ajax({
    		type: "POST",
    		url: 'localhost/pw/graphql/',          
    		data: "{ modals(s: \"title=Test-Page\") { list { id title body } } }",      
    		
    		success: function(data) {
    			console.log(data);
    		} 
    	});

    However, I seem to be getting an error message returned with: "Must provide an operation.". I do apologize if I have just missed something basic (very new to ajax and how it all functions), but is there something missing from my initial request?

    @louisstephens Your query should be assigned to query variable. Try to change above code like this

    $.ajax({
      type: "POST",
      url: 'localhost/pw/graphql/',          
      data: {
        query: "{ modals(s: \"title=Test-Page\") { list { id title body } } }" // <-- change here
      },  
      success: function(data) {
        console.log(data);
      } 
    });

     

    • Like 1
  10. 27 minutes ago, louisstephens said:

    First of all, I love the module thus far. Unfortunately (for me), When I go to Setup->GraphQL, it pops up with "Loading...", but never actually loads anything . I am currently using php 5.6.30. Any idea what might be causing this? I dont currently have any errors in my console either. 

    Screen Shot 2018-03-28 at 3.48.57 PM.png

    This one is weird. I just installed the module on Classic profile and Skyscrapers profile with latest ProccessWire. Works fine for me.

    The "Loading..." is a placeholder till JavaScript kicks in. So this means the GraphiQL js assets are not loading or firing. Could you please try to see if GraphiQL works out of ProcessWire admin. You can either do that manually, using API that exposes GraphiQL in your template file. Or use GraphQL Pages generator. It's in the modules setting page. Looks like this.
    5abbfa69e4934_ScreenShot2018-03-29at2_23_50AM.thumb.png.b59965ccf4237c8e0634d51515e46a63.png

    Just press it and go to `/graphiql/` on your website and show us what you got there.

    • Like 1
  11. I'm very happy you like it @alan. You definitely can use this for any single page application. That's exactly why I built this module for. Please don't hesitate to share the issues that might come up when using this module. I would love hear some feedback and maybe fix bugs if there are any.

    • Like 3
    • Thanks 1
  12. So I made a mistake by not taking into account the ProcessWire's module naming convention. I totally forgot the fact that if module name starts with Fieldtype it becomes a fieldtype and PW will treat it like any other fieldtype. Like it would try to let you add a new field with that fieldtype. Which we do not want for our GraphQL extension modules. I already faced bugs because of this on admin side.

    So naming rule for GraphQL extension modules will be changed from suffixing the name with GraphQL to prefixing the name with GraphQL. So it is GraphQLFieldtypeMapMarker instead of FieldtypeMapMarkerGraphQL. Other than that, everything is the same as before. I'll also update the previous post to reflect this change. Sorry if this causes inconvenience to anyone.

    The updated version of ProcessGraphQL that works with new rules is available for use in latest release.

    • Like 7
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. @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
  19. 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
  20. 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
  21. 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
  22. 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
  23. 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
×
×
  • Create New...