Jump to content
dadish

GraphQL for ProcessWire

Recommended Posts

1 hour ago, DavidBerlin said:

Children results work with "name" instead of "title"...

The children results only have with built-in page fields. They don't have template fields. You have to make sure the field title exists in GraphiQL before querying it. When you go to Setup -> GraphQL and enter the above query it will tell you that there is no "title" field for children list. If the field is not in your GraphQL schema you cannot query it.

If you want to query your task pages with template fields like title, you can set them as a Page field like you do with your job_client field. That way your tasks will have all the template fields you enabled.

  • Like 2

Share this post


Link to post
Share on other sites

dadish,

First, thank you for this wonderful module, it's been awesome working with GraphQL.

The problem: I have a field where the type is "Page Reference" and the input field type is "Page Auto Complete". In the details tab, the "Multiple pages PageArray" is selected.

If I only have one page reference, then it will return the result as expected using the "list". However, if I have multiple page references, then it will not display any results at all. Can you let me know if there is something I am doing wrong or is this is a bug/feature that needs to be worked?

All the best!

  • Like 1

Share this post


Link to post
Share on other sites

Hello @Brett.

Thank you for your feedback! I was able to reproduce your issue and hopefully tracked down the bug. Please, install the latest version and give it a try. Let me know if the issue is resolved for you.

New Release 1.1.3

- Fixed bug with FieldtypePage returning only single value.

  • Like 6

Share this post


Link to post
Share on other sites

Hi @dadish,

I'm upgrading a site to use the latest version of this module.

I'm having trouble with a page reference field when creating a new page with a mutation.

Before, I was using a mutation with variables like this:

mutation ($page: ConfiguratorQuoteUpdateInput!) {
  createConfiguratorQuote(page: $page) {
    id
  }
}

variables: {
  "page": {
    "name": "test-quote",
    "title": "Tets Quote",
    "parent": "22905",
    "colour": [10392] // this is the page reference field
  }
}

I noticed the field now uses the type InputfieldPage rather than [ID] and there are add and remove fields inside this InputfieldPage field.

I have tried formatting the variables in a couple of ways and I see this error in graphqil:

// "debugMessage": "Method NullPage::add does not exist or is not callable in this context",

// When using either of these

variables: {
  "page": {
    "name": "test-quote",
    "title": "Test Quote",
    "parent": "22905",
    "colour": {
      "add": 10392
    }
  }
}

variables: {
  "page": {
    "name": "test-quote",
    "title": "Test Quote",
    "parent": "22905",
    "colour": {
      "add": [10392]
    }
  }
}

Can you advise how I should be adding page reference fields? I have checked the page template and fields are legal, they return without issue in queries for existing pages.

 

Many thanks,

Tom

  • Like 1

Share this post


Link to post
Share on other sites

@sodesign

First, I want to clarify some stuff. You are saying that you want to create a page and using a mutation field "createConfiguratorQuote" but supplying it with "ConfiguratorQuoteUpdateInput" which is an incorrect input type. You should supply "ConfiguratorQuoteCreateInput" for creating and "ConfiguratorQuoteUpdateInput" for updating a page.

The "add" and "remove" for page references always expects an array of ids. So your latest format for variables is correct for creating a page. Just change UpdateInput type to CreateInput type.

But, if you're trying to update a page then "page" input variable should include "id" field. It should look like this...

variables: {
  "page": {
    "id" : 11111, // <=== you should tell which page you're trying to update.
    "name": "test-quote",
    "title": "Test Quote",
    "parent": "22905",
    "colour": {
      "add": [10392]
    }
  }
}

Let me know if I'm missing something.

  • Like 2

Share this post


Link to post
Share on other sites

Sorry - copy and paste error*. I am using a ConfiguratorQuoteCreateInput field when I get the error.

*(I tried using update as well in case the page reference needed a parent page to exist first)

 

  • Like 1

Share this post


Link to post
Share on other sites

@sodesign

Ok, I think I found the problem. I was able to get the same error as yours and patched the module to fix it, just now. Try the latest version and let me know if the issue is resolved for you.

New Release 1.1.4

- Fix FieldtypePage bug when FieldtypePage:derefAsPageOrNullPage option is enabled.

  • Like 3

Share this post


Link to post
Share on other sites
On 1/15/2020 at 6:53 AM, dadish said:

Hello @Brett.

Thank you for your feedback! I was able to reproduce your issue and hopefully tracked down the bug. Please, install the latest version and give it a try. Let me know if the issue is resolved for you.

New Release 1.1.3

- Fixed bug with FieldtypePage returning only single value.

I can confirm that 1.1.4 fixed the issue we were having. Thank you for getting back so quickly. 🙂

  • Like 1

Share this post


Link to post
Share on other sites

  

14 hours ago, dadish said:

@sodesign

Ok, I think I found the problem. I was able to get the same error as yours and patched the module to fix it, just now. Try the latest version and let me know if the issue is resolved for you.

New Release 1.1.4

- Fix FieldtypePage bug when FieldtypePage:derefAsPageOrNullPage option is enabled.

Just updated and the issue is fixed, thank you for such a speedy patch!

  • Like 1

Share this post


Link to post
Share on other sites

One other small thing - can you add support for the built in 'title' field in the Page type? 

I tried this locally editing the getBuiltInFields() function at line 41 in src/Type/PageType.php

Thanks,

Tom

  • Like 1

Share this post


Link to post
Share on other sites
On 12/13/2019 at 4:11 PM, dadish said:

The children results only have with built-in page fields.

I have one more question - do you plan to include child template fields?

If not, what is your recommendation for querying child pages?

Thanks

Share this post


Link to post
Share on other sites
On 1/17/2020 at 9:36 PM, sodesign said:

One other small thing - can you add support for the built in 'title' field in the Page type? 

I tried this locally editing the getBuiltInFields() function at line 41 in src/Type/PageType.php

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.

22 hours ago, sodesign said:

I have one more question - do you plan to include child template fields?

If not, what is your recommendation for querying child pages?

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! 😄

  • Like 5

Share this post


Link to post
Share on other sites

Thank you for explaning these details and your plans.

If you'd like any help testing, I'd be happy to do what I can; this module is a great asset for PW develoment.

  • Like 2

Share this post


Link to post
Share on other sites

Hi! I'm getting this error when I post to /graphql:

{
    "errors": [
        {
            "message": "Syntax Error: Unexpected <EOF>",
            "extensions": {
                "category": "graphql"
            },
            "locations": [
                {
                    "line": 1,
                    "column": 1
                }
            ]
        }
    ]
}

I'm using POST with Content-Type: application/json and the post body looks like this:

{
	"query": "{ integrante { title } }"
}

When I try with GraphiQL (which posts to /processwire/setup/graphql instead of /graphql), everything works perfectly. Of course the templates are installed, field and templates access are configured, etc.

I've tried using a public GraphQL API like https://countries.trevorblades.com/ and it works fine.

What am I doing wrong? I've tried manually from Postman and also using Gatsby's gatsby-source-graphql plugin. Both get the same <EOF> error.

It's a new blank ProcessWire installation, master branch. Please help! Thanks in advance!

Share this post


Link to post
Share on other sites
On 3/7/2020 at 7:19 AM, Miguel Scaramozzino said:

When I try with GraphiQL (which posts to /processwire/setup/graphql instead of /graphql), everything works perfectly. Of course the templates are installed, field and templates access are configured, etc.

Can you post the code in your graphql.php template file. My only guess is that something happening in that file.

  • Like 1

Share this post


Link to post
Share on other sites
On 3/8/2020 at 1:19 PM, dadish said:

Can you post the code in your graphql.php template file. My only guess is that something happening in that file.

Here it is:

<?php namespace ProcessWire;

header('Content-Type: application/json');

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

 

Share this post


Link to post
Share on other sites

Here's something interesting, I've created a /test.php file with the following code:

<?php
namespace ProcessWire;

require("index.php");

header('Content-Type: application/json');

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

This works fine.

So there must be something wrong with the way that the graphql template is being processed. Maybe ProcessWire is taking control of the post body before it reaches the module and this doesn't happen when you bootstrap PW from an external file?

  • Like 1

Share this post


Link to post
Share on other sites
12 hours ago, Miguel Scaramozzino said:

So there must be something wrong with the way that the graphql template is being processed. Maybe ProcessWire is taking control of the post body before it reaches the module and this doesn't happen when you bootstrap PW from an external file?

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.

Share this post


Link to post
Share on other sites
13 hours ago, dadish said:

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.

Yes, this is the problem clearly. I've tried $input->post->query but that won't work cause it's not form-data but a json body. So I've tried file_get_contents("php://input") and it comes up empty. There must be something wrong with my PW installation, cause I've created REST APIs in the past parsing json data from php://input with no issues at all. I will try to downgrade the PW core and see what happens.

Share this post


Link to post
Share on other sites

BTW my /test.php file receives the php://input contents just fine. That's why the module has no problem parsing it when loaded from outside the PW template system. This is weird. I guess it's now a question for Ryan.

Share this post


Link to post
Share on other sites
21 minutes ago, Miguel Scaramozzino said:

Yes, this is the problem clearly. I've tried $input->post->query but that won't work cause it's not form-data but a json body. So I've tried file_get_contents("php://input") and it comes up empty. There must be something wrong with my PW installation, cause I've created REST APIs in the past parsing json data from php://input with no issues at all. I will try to downgrade the PW core and see what happens.

Make sure you check nginx/apache and PHP logs as well. If memory serves me correctly, I had a similar issue do to something was blocking because of XSS. There was a server change I had to make, so keep a close eye on those logs and the developer tools on your browser.

Share this post


Link to post
Share on other sites

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

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
2 hours ago, dadish said:

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

You are absolutely right sir! Adding the final slash fixes it. I've been using PW for years and I've never encountered that quirk. Thanks a lot!

Share this post


Link to post
Share on other sites
18 hours ago, Miguel Scaramozzino said:

I've been using PW for years and I've never encountered that quirk.

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.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By MoritzLost
      Process Cache Control
      This module provides a simple solution to clearing all your cache layers at once, and an extensible interface to perform various cache-related actions.
      The simple motivation behind this module was that I was tired of manually clearing caches in several places after deploying a change on a live site. The basic purpose of this module is a simple Clear all caches link in the Setup menu which clears out all caches, no matter where they hide. You can customize what exactly the module does through it's configuration menu:
      Expire or delete all cache entries in the database, or selectively clear caches by namespace ($cache API) Clear the the template render cache. Clear out specific folders inside your site's cache directory (/site/assets/cache) Clear the ProCache page render cache (if your site is using ProCache) Refresh version strings for static assets to bust client-side browser caches (this requires some setup, see the full documentation for details). This is the basic function of the module. However, you can also add different cache management action through the API and execute them through the module's interface. For this advanced usage, the module provides:
      An interface to see all available cache actions and execute them. A system log and logging output on the module page to see verify what the module is doing. A CacheControlTools class with utility functions to clear out different caches. An API to add cache actions, execute them programmatically and even modify the default action. Permission management, allowing you granular control over which user roles can execute which actions. The complete documentation can be found in the module's README.
      Plans for improvements
      If there is some interest in this, I plan to expand this to a more general cache management solution. I particular, I would like to add additional cache actions. Some ideas that came to mind:
      Warming up the template render cache for publicly accessible pages. Removing all active user sessions. Let me know if you have more suggestions!
      Links
      https://github.com/MoritzLost/ProcessCacheControl ProcessCacheControl in the Module directory CHANGELOG in the repository Screenshots


    • By Macrura
      PrevNextTabs Module
      Github: https://github.com/outflux3/PrevNextTabs
      Processwire helper modules for adding page navigation within the editor.
      Overview
      This is a very simple module that adds Previous and Next links inline with the tabs on the page editor. Hovering over the tab shows the title of the previous or next page (using the admin's built in jqueryUI tooltips.)
      Usage
      This module is typically used during development where you or your editors need to traverse through pages for the purpose of proofing, flagging and/or commenting. Rather than returning to the page tree or lister, they can navigate with these links.
      Warnings
      If you are using PW version 2.6.1 or later, the system will prevent you from leaving the page if you have unsaved edits.
      For earlier versions, to avoid accidentally losing changes made to a page that might occur if a user accidentally clicks on one of these, make sure to have the Form Save Reminder module installed.
      http://modules.processwire.com/modules/prev-next-tabs/
    • By Gadgetto
      SnipWire - Snipcart integration for ProcessWire
      Snipcart is a powerful 3rd party, developer-first HTML/JavaScript shopping cart platform. SnipWire is the missing link between Snipcart and the content management framework ProcessWire.
      With SnipWire, you can quickly turn any ProcessWire site into a Snipcart online shop. The SnipWire plugin helps you to get your store up and running in no time. Detailed knowledge of the Snipcart system is not required.
      SnipWire is free and open source licensed under Mozilla Public License 2.0! A lot of work and effort has gone into development. It would be nice if you could donate an amount to support further development:

      Status update links (inside this thread) for SnipWire development
      2020-03-21 -- SnipWire 0.8.5 (beta) released! Improves SnipWires webhooks interface and provides some other fixes and additions 2020-03-03 -- SnipWire 0.8.4 (beta) released! Improves compatibility for Windows based Systems. 2020-03-01 -- SnipWire 0.8.3 (beta) released! The installation and uninstallation process has been heavily revised. 2020-02-08 -- SnipWire 0.8.2 (beta) released! Added a feature to change the cart and catalogue currency by GET, POST or SESSION param 2020-02-03 -- SnipWire 0.8.1 (beta) released! All custom classes moved into their own namespaces. 2020-02-01 -- SnipWire is now available via ProcessWire's module directory! 2020-01-30 -- SnipWire 0.8.0 (beta) first public release! (module just submitted to the PW modules directory) 2020-01-28 -- added Custom Order Fields feature (first SnipWire release version is near!) 2020-01-21 -- Snipcart v3 - when will the new cart system be implemented? 2020-01-19 -- integrated taxes provider finished (+ very flexible shipping taxes handling) 2020-01-14 -- new date range picker, discount editor, order notifiactions, order statuses, and more ... 2019-11-15 -- orders filter, order details, download + resend invoices, refunds 2019-10-18 -- list filters, REST API improvements, new docs platform, and more ... 2019-08-08 -- dashboard interface, currency selector, managing Orders, Customers and Products, Added a WireTabs, refinded caching behavior 2019-06-15 -- taxes provider, shop templates update, multiCURL implementation, and more ... 2019-06-02 -- FieldtypeSnipWireTaxSelector 2019-05-25 -- SnipWire will be free and open source Plugin Key Features
      Fast and simple store setup Full integration of the Snipcart dashboard into the ProcessWire backend (no need to leave the ProcessWire admin area) Browse and manage orders, customers, discounts, abandoned carts, and more Multi currency support Custom order and cart fields Process refunds and send customer notifications from within the ProcessWire backend Process Abandoned Carts + sending messages to customers from within the ProcessWire backend Complete Snipcart webhooks integration (all events are hookable via ProcessWire hooks) Integrated taxes provider (which is more flexible then Snipcart own provider) Useful Links
      SnipWire in PW modules directory SnipWire Docs (please note that the documentation is a work in progress) SnipWire @GitHub (feature requests and suggestions for improvement are welcome - I also accept pull requests) Snipcart Website  
      ---- INITIAL POST FROM 2019-05-25 ----
       
    • By horst
      Croppable Image 3
      for PW 3.0.20+
      Module Version 1.2.0
      Sponsored by http://dreikon.de/, many thanks Timo & Niko!
      You can get it in the modules directory!
      Please refer to the readme on github for instructions.
       
      - + - + - + - + - + - + - + - + - + - NEWS - 2020/03/19 - + - + - + - + - + - + - + - + - + - 
      There is a new Version in the pipe, that supports WebP too: 
       
      - + - + - + - + - + - + - + - + - + - NEWS - 2020/03/19 - + - + - + - + - + - + - + - + - + - 
       
       
      -------------------------------------------------------------------------
       
      Updating from prior versions:
       
      Updating from Croppable Image 3 with versions prior to 1.1.7, please do this as a one time step:
      In the PW Admin, go to side -> modules -> new, use "install via ClassName" and use CroppableImage3 for the Module Class Name. This will update your existing CroppableImage3 module sub directory, even if it is called a new install. After that, the module will be recogniced by the PW updater module, what makes it a lot easier on further updates.
      -------------------------------------------------------------------------
       
      For updating from the legacy Thumbnail / CropImage to CroppableImage3 read on here.
       
      -------------------------------------------------------------------------
       
×
×
  • Create New...