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 5

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 4

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

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
      This is a new module that 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) 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.
      Beta release
      Note that I consider this a Beta release. Since the module is relatively aggressive in deleting some caches, I would advise you to install in on a test environment before using it on a live site.
      Let me know if you're getting any errors, have trouble using the module or if you have suggestions for improvement!
      In particular, can someone let me know if this module causes any problems with the ProCache module? I don't own or use it, so I can't check. As far as I can tell, ProCache uses a folder inside the cache directory to cache static pages, so my module should be able to clear the ProCache site cache as well, I'd appreciate it if someone can test that for me.
      Future plans
      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

    • By joshua
      This module is (yet another) way for implementing a cookie management solution.
      Of course there are several other possibilities:
      - https://processwire.com/talk/topic/22920-klaro-cookie-consent-manager/
      - https://github.com/webmanufaktur/CookieManagementBanner
      - https://github.com/johannesdachsel/cookiemonster
      - https://www.oiljs.org/
      - ... and so on ...
      In this module you can configure which kind of cookie categories you want to manage:

      You can also enable the support for respecting the Do-Not-Track (DNT) header to don't annoy users, who already decided for all their browsing experience.
      Currently there are four possible cookie groups:
      - Necessary (always enabled)
      - Statistics
      - Marketing
      - External Media
      All groups can be renamed, so feel free to use other cookie group names. I just haven't found a way to implement a "repeater like" field as configurable module field ...
      When you want to load specific scripts ( like Google Analytics, Google Maps, ...) only after the user's content to this specific category of cookies, just use the following script syntax:
      <script type="optin" data-type="text/javascript" data-category="statistics" data-src="/path/to/your/statistic/script.js"></script> <script type="optin" data-type="text/javascript" data-category="marketing" data-src="/path/to/your/mareketing/script.js"></script> <script type="optin" data-type="text/javascript" data-category="external_media" data-src="/path/to/your/external-media/script.js"></script> <script type="optin" data-type="text/javascript" data-category="marketing">console.log("Inline scripts are also working!");</script> The type has to be "optin" to get recognized by PrivacyWire, the data-attributes are giving hints, how the script shall be loaded, if the data-category is within the cookie consents of the user. These scripts are loaded asynchronously after the user made the decision.
      If you want to give the users the possibility to change their consent, you can use the following Textformatter:
      [[privacywire-choose-cookies]] It's planned to add also other Textformatters to opt-out of specific cookie groups or delete the whole consent cookie.
      You can also add a custom link to output the banner again with a link / button with following class:
      <a href="#" class="privacywire-show-options">Show Cookie Options</a> <button class="privacywire-show-options">Show Cookie Options</button> This module is still in development, but we already use it on several production websites.
      You find it here: https://github.com/blaueQuelle/privacywire/tree/master
      Download: https://github.com/blaueQuelle/privacywire/archive/master.zip
      I would love to hear your feedback 🙂
      Edit: Updated URLs to master tree of git repo
       
    • By David Karich
      Admin Page Tree Multiple Sorting
      ClassName: ProcessPageListMultipleSorting
      Extend the ordinary sort of children of a template in the admin page tree with multiple properties. For each template, you can define your own rule. Write each template (template-name) in a row, followed by a colon and then the additional field names for sorting.
      Example: All children of the template "blog" to be sorted in descending order according to the date of creation, then descending by modification date, and then by title. Type:
      blog: -created, -modified, title  Installation
      Copy the files for this module to /site/modules/ProcessPageListMultipleSorting/ In admin: Modules > Check for new modules. Install Module "Admin Page Tree Multible Sorting". Alternative in ProcessWire 2.4+
      Login to ProcessWire backend and go to Modules Click tab "New" and enter Module Class Name: "ProcessPageListMultipleSorting" Click "Download and Install"   Compatibility   I have currently tested the module only under PW 2.6+, but think that it works on older versions too. Maybe someone can give a feedback.     Download   PW-Repo: http://modules.processwire.com/modules/process-page-list-multiple-sorting/ GitHub: https://github.com/FlipZoomMedia/Processwire-ProcessPageListMultipleSorting     I hope someone can use the module. Have fun and best regards, David
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version (has been tested up to v3.3), add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "https://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


×
×
  • Create New...