Jump to content

dadish

Members
  • Posts

    124
  • Joined

  • Last visited

  • Days Won

    8

Posts posted by dadish

  1. 6 minutes ago, dragan said:

    Do I see these error messages only because the site is in debug-mode?

    Yes. In debug mode it will return very verbose error messages. But ideally it should not return any errors. All my success tests check if the response has data in it and does not assert that there are no errors. So it might be that I have those errors as well, just didn't catch them. I'll try to reproduce your case and fix it.

    10 minutes ago, dragan said:

    If I remove "budget" field, it works. I double-checked it's in the allowed fields in the module config.

    What type of field your budget field is? I assume integer, but want to be certain.

    • Like 1
  2. New Version Release: 1.0.3

    - Improves performance for FieldtypeFile & FieldtypeImage fields.

    @dragan Looking forward to your feedback. I'm still very curious how you managed to get 6s response time from GraphQL. Let me know how the latest version works for you.

    @nbcommunication That's great to hear! Any involvement is absolutely welcome. If you have your module available on github or some other place I would love to look at your approach and maybe steal some ideas ?. Also, if your implementation is different than mine I would encourage you to finish it. We will only benefit from different approaches.

    • Like 5
  3. New version release! 1.0.2

    I am very happy to inform you guys that the new major version of the module is out.

    ⚠️ WARNING: Breaking Changes! ⚠️

    The module was rewritten to use webonyx/graphql-php instead of youshido/graphql. This was a big issue because the latter was not properly maintained anymore and the webonyx/graphql-php gone very further in development and supports more features that we need. There are some more breaking changes that are listed on the latest release page.

    What's new

    • trash(id: ID!): Page! field allows to move pages to trash via GraphQL api.
    • Solves N+1 problem for FieldtypePage field. Significantly improves response speed!
    • Support for even more ProcessWire permissions. Now the full list is:
      • page-add
      • page-create
      • page-delete
      • page-edit
      • page-move
      • page-view
      • page-edit-created
      • page-edit-trash-created

    It is already available in ProcessWire's modules directory. So you can install it via class name.

    • Like 12
    • Thanks 4
  4. 1 hour ago, charger said:

    Serializing the whole query just to get a unique cache name obviously isn’t optimal. How about if the module supported globally unique IDs that could then be used as cache name instead?

    The link you're referring to talks about the caching on the client side, not server. And we already have unique id for all the objects. They are page ids and are enabled by default. But that wont help you with caching on the server side.

    I think using a hash of your queries as a cache name is perfectly reasonable solution. Why do you feel uncomfortable with it?

    • Like 1
  5. 17 minutes ago, dragan said:

    Is that a general graphQL (architectural) performance issue, or just with this particular PHP library in particular? (which, as I have noticed, is not being maintained anymore)

    I'm not sure if I can blame the PHP library alone. It definitely could be one of the things that contribute to poor performance. But there are many more things going on. For example permissions is a big one. The schema needs to check the permissions for each field and subfields. So if you have lots of page-refs and fetching their subfields, it will check if the user has permission to view those fields. When you make a query inside your templates, the script already got access and don't do permission checks manually.

    It needs to be improved. Performance is very important. But right now I'm dealing with PHP library deprecation, because it's not maintained anymore.

    • Like 5
  6. On 2/8/2019 at 12:00 AM, sodesign said:

    Edit - to clarify - I'm generating a base64 image in vuejs on the front end, and need to save this to an image field. I'm planning to do this by sending the base64 string as part of  the request (I'm using vue apollo) - and then intercepting this with a hook, creating and saving as a png file in a temporary directory, and then setting this as the PageImage url in the query. 

    Unfortunately the getMotationHook requires you to use the Youshido/GraphQL library that this module depends on. The issue with it, is that the youshido/graphql is not maintained anymore. Which means that I'll be rewriting GraphQL module to get red of it and use some other library. So I can't give you the correct solution because it's being deprecated at the moment, and I can't tell when I'll finish the migration to another php graphql library because I'm limited with my spare time.

     

    Sorry for replying this late, I hope you found a solution.

    • Like 2
  7. 21 minutes ago, dragan said:

    I noticed that this module is actually quite slow in the backend. A native PW query in the Tracy Console takes 27ms, and the equivalent GraphQL query >6s (TTFB in the inspector network panel). Is that because of the overhead of the GraphQL playground frontend assets? Or in other words, would a real-life request take also that long?

    GraphQL requests are slow for sure, but 6 seconds is a bit too much. In my cases it usually took around 200-300ms. Not sure what's causing it to be so slow on your end.

    • Like 1
  8. 59 minutes ago, Torsten Baldes said:

    For example, I want to get a list of speakers with all the needed fields (name etc.) and their talks at conferences. The problem is, that I don't link the conferences on the speaker template, but reference the speakers on the conference template.

    AFAIK the only way to ask PW to get you conferences that has particular speakers in it, is to pass which speakers exactly you want. The selector looks like

    "template=conferences, speaker=1234|1235|1236..."

    So, you need get the speakers before you can query the conferences. My only solution is to query all your speakers first. Then make another query of all conferences that has those speakers in it. Query them all at once. And then, in the client when you are listing conferences for each speaker, just filter through them.

    I know, it's not a great solution, but I can't think of another way. I haven't used ProccessWire in a while, so there might be some better way.

    • Like 2
  9. 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
  10. 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
  11. @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
  12. 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
  13. 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
  14. 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 7
    • Thanks 1
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
×
×
  • Create New...