a wordpress plugin that improves wpgraphql usage together with wpml

Overview

WPGraphQL WPML Extension

  • Contributors: rburgst
  • Stable tag: 1.0.6
  • Tested up to: 5.6.1
  • Requires at least: 4.9
  • Requires PHP: 7.0
  • Requires WPGraphQL: 0.8.0+
  • Requires WPML: 4.4.5+
  • Tags: GraphQL, WPML, WPGraphQL
  • License: GPL-3
  • License URI: https://www.gnu.org/licenses/gpl-3.0.html

Description

Adds WPML functionality to wpgraphql so that translations can be queried and WPML default filters which disable the listing of all content are disabled.

Note that the primary use case for this plugin is to be used together with Gatsby where you can perform all filtering of your content within the Gatsby GraphQL schema.

Since Gatsby pulls the whole content out of the wordpress database, this plugin will ensure that all translations of the translated content is being returned (instead of only content in the default language).

If you dont intend to use this plugin together with Gatsby be aware that you will typically have to be creative with filtering, see #8, #9.

Thanks to https://github.com/shawnhooper/wpml-rest-api and https://github.com/valu-digital/wp-graphql-polylang

Caveats

In case you are getting issues querying data (i.e. http 302, or errors), please first try to see whether you can successfully query data without this plugin.

If it does not work without this plugin, then enabling this plugin wont magically heal your broken ACF config (see also #5). This plugin will only help in getting "more" content from your wordpress installation (which was previously disabled by WPML interfering with queries).

Limitations

Due to the main use case of using this plugin together with gatsby some often required filtering options are not yet available, such as

  • filtering menus by locale/language (see #3)
Comments
  • Querying pages set as child throws an error when WPML is enabled

    Querying pages set as child throws an error when WPML is enabled

    Hi,

    I am getting an error when querying pages that are set as child of other pages, and it seems related to WPML. The error says: "SyntaxError: Unexpected token < in JSON at position 0".

    wpgraphql-with-wpml-error-query-child-page

    If I have only WPGraphQL enabled it works fine and I can fetch all the pages. However if I enable WPML I get this error when fetching any page that has a parent. It doesn't matter if the pages have translations or not.

    Has anybody experienced something similar?

    Thanks in advance for any feedback!

    opened by juanramoncarceles 25
  • Incompatibility with WPGraphQL WooCommerce (WooGraphQL) and WooCommerce

    Incompatibility with WPGraphQL WooCommerce (WooGraphQL) and WooCommerce

    Adding a product to the cart is giving an error, while it is working with WPML and WPGraphQL WPML disabled. I tried to send the query from GraphiQL IDE, Postman and my Next.js app.

    The query: mutation MyMutation { addToCart(input: {productId: 32009, clientMutationId: "asdasd", quantity: 1}) { cartItem { key } } }

    The error: { "errors": [ { "debugMessage": "Call to a member function get_cart_from_session() on null", "message": "Internal server error", "extensions": { "category": "internal" }, "locations": [ { "line": 2, "column": 3 } ], "path": [ "addToCart" ], "trace": [ { "file": "/wp-content/plugins/wp-graphql-woocommerce/includes/mutation/class-cart-add-item.php", "line": 93, "call": "WPGraphQL\WooCommerce\Data\Mutation\Cart_Mutation::check_session_token()" },

    The website: https://dev.supplybeaver.ca/ Versions: WPGraphQL WPML - 1.0.7 WPML Multilingual CMS - 4.5.1 WPGraphQL WooCommerce (WooGraphQL) - 0.10.6 WooCommerce - 5.9.0 WP GraphQL - 1.6.7

    I am creating the same issue for WPGraphQL WooCommerce (WooGraphQL), as I don't know on which side exactly the issue is. I really hope that it will be possible to use a combination of these plugins on my website soon. Thank you!

    opened by opanasenkomaksim 18
  • Have not found a way to fetch Posts or Post by `locale`

    Have not found a way to fetch Posts or Post by `locale`

    Thank you to anyone who can help with this. Maybe my approach is wrong and you can tell me how you are getting the results I'm looking for.

    fragment AuthorFields on User {
      name
      firstName
      lastName
      avatar {
        url
      }
    }
    
    fragment PostFields on Post {
      title
      excerpt
      slug
      date
      featuredImage {
        node {
          sourceUrl
        }
      }
      author {
        node {
          ...AuthorFields
        }
      }
      categories {
        edges {
          node {
            name
          }
        }
      }
      tags {
        edges {
          node {
            name
          }
        }
      }
    }
    
    fragment AdditionalFields on Post {
      content
      locale {
        locale
      }
      translations {
        post_title
        locale
        href
      }
      seo {
        metaDesc
        metaKeywords
        metaRobotsNofollow
        metaRobotsNoindex
        opengraphAuthor
        opengraphDescription
        focuskw
        cornerstone
        canonical
        breadcrumbs {
          text
          url
        }
        opengraphImage {
          altText
          link
          uri
          title
          sourceUrl
        }
        opengraphModifiedTime
        opengraphPublishedTime
        opengraphPublisher
        opengraphSiteName
        opengraphTitle
        opengraphType
        opengraphUrl
        title
        twitterDescription
        twitterTitle
        twitterImage {
          altText
          caption
          uri
          sourceUrl
        }
      }
    }
    
    query PostBySlug($id: ID!, $idType: PostIdType!) {
      post(id: $id, idType: $idType) {
        ...PostFields
        ...AdditionalFields
      }
    }
    
    query AllPosts($length: Int!, $after: String) {
      posts(first: $length, after: $after, where: {orderby: {field: DATE, order: DESC}}) {
        edges {
          node {
            title
            excerpt
            slug
            date
            featuredImage {
              node {
                sourceUrl
              }
            }
            author {
              node {
                name
                firstName
                lastName
                avatar {
                  url
                }
              }
            }
          }
          cursor
        }
        pageInfo {
          hasNextPage
          hasPreviousPage
          startCursor
        }
      }
    }
    
    opened by retzion 14
  • No language data when query from external

    No language data when query from external

    wp-graphlql is working fine for default language.

    i installed wp-graphql-wpml but when i send my query. The data for for the second language is empty. It works fine with the GraphIQL.

    My query query MyQuery { menus { nodes { name slug menuItems(where: {parentId: "null"}) { nodes { title label } } } } } response external { "name": "Hauptmenü", "slug": "hauptmenue", "menuItems": { "nodes": [] } }

    response GraphIQL { "name": "Hauptmenü", "slug": "hauptmenue", "menuItems": { "nodes": [ { "title": null, "label": "Umsatzsteuer" } ] } }

    do have any ideas? thanks for your reply

    opened by ngongoll 7
  • List all posts (in all languages)?

    List all posts (in all languages)?

    I have installed your plugin, but when I query posts it still only shows the posts in the default language.

    How do I query all posts (regardless of language)?

    opened by pmkemper 7
  • URI of translated page on front should not contain the slug

    URI of translated page on front should not contain the slug

    Hello, thank you for your work.

    My issue is that when a static page is set as "Page on front" in WordPress and the translation page for it is created, they have the following URI patterns in the CMS:

    mydomain.com/
    mydomain.com/LOCALE/
    

    In other words, the front page slug or the post name is removed from the URL.

    However, this is not the case when the translated page is retrieved in GraphQL. We have instead:

    /
    /LOCALE/translated-page-slug/
    

    Can this issue be be addressed by this plugin or it should be fixed within a different layer?

    Thanks.

    opened by pshemek 5
  • When WPML extension is active, menuItems query returns ALL menu items throughout the site

    When WPML extension is active, menuItems query returns ALL menu items throughout the site

    So it always worked for me but for some reason menuItems is returning all Menu items from everywhere. My query is

    query getNavItems {
      menuItems(where: {location: PRIMARY}) {
        nodes {
          title
          path
          label
          locations
        }
      }
    }
    

    And my response still is>

    {
      "data": {
        "menuItems": {
          "nodes": [
            {
              "title": null,
              "path": "/register/",
              "label": "Register",
              "locations": null
            },
            {
              "title": null,
              "path": "/",
              "label": "Home",
              "locations": [
                "PRIMARY"
              ]
            },
            {
              "title": null,
              "path": "/support/",
              "label": "Support",
              "locations": null
            },
            {
              "title": null,
              "path": "/blog/",
              "label": "Blog",
              "locations": [
                "PRIMARY"
              ]
            },
            {
              "title": null,
              "path": "/try/",
              "label": "Try",
              "locations": null
            },
            {
              "title": null,
              "path": "/about/",
              "label": "About",
              "locations": [
                "PRIMARY"
              ]
            },
            {
              "title": null,
              "path": "/contact/",
              "label": "Contact",
              "locations": [
                "PRIMARY"
              ]
            },
            {
              "title": null,
              "path": "/pricing/",
              "label": "Pricing",
              "locations": [
                "PRIMARY"
              ]
            },
            {
              "title": null,
              "path": "/try/",
              "label": "Try",
              "locations": [
                "PRIMARY"
              ]
            },
            {
              "title": null,
              "path": "/pricing/",
              "label": "Pricing",
              "locations": [
                "PRIMARY"
              ]
            }
          ]
        }
      },
      "extensions": {
        "debug": [
          {
            "type": "DEBUG_LOGS_INACTIVE",
            "message": "GraphQL Debug logging is not active. To see debug logs, GRAPHQL_DEBUG must be enabled."
          }
        ]
      }
    }
    
    opened by teetlaja 4
  • Fetch last posts return 3 times the same posts

    Fetch last posts return 3 times the same posts

    Hi,

    I am using the last version of WPML and wordpress 5.6.1.

    When I query the posts I get all the post but the translated post are also part of the request. For exemple if the last post is translated in two other languages I get 3 times the same post, one for each language.

    The posts and the translations don't have the same post id so I suppose this is why I get them but is this an expected behavior or do I miss something to only query one language at the time?

    opened by PaulBouisset 4
  • Not working with Next.js and language switch

    Not working with Next.js and language switch

    I'm running into a problem when I query posts for different languages.

    Versions used: WP GraphQL: 1.8.1 WPGraphQL WPML: 1.1.0

    My GQL query looks like so:

    export const getAllPostsForHome = gql`
      query AllPosts($locale: String) {
        posts(
          first: 6
          where: { orderby: { field: DATE, order: DESC }, wpmlLanguage: $locale }
        ) {
          nodes {
            content
            excerpt
            date
            title
            slug
            databaseId
            featuredImage {
              node {
                title
                sourceUrl
              }
            }
          }
        }
      }
    `;
    

    With the variable locale I assumed I can then query the posts like so:

    export async function getStaticProps(context) {
      const { locale } = context;
    
      const posts = await client.query({
        query: getAllPostsForHome,
        variables: {
          wpmlLanguage: locale,
        },
      });
    
      return {
        props: {
          posts: posts.data.posts.nodes,
        },
        revalidate: 1,
      };
     }
    

    Instead it queries all posts, the original including translated posts. I might be missing something here?

    In Next.js I've setup i18n in the config file and works as expected. http://localhost:3000/ and http://localhost:3000/en works as expected except the posts.

    opened by markdost 3
  • Fix bug / Add composer

    Fix bug / Add composer

    Hey @rburgst ,

    Just pushing a fix to a bug on the define for REST_REQUEST.

    Also, added a bare minimum composer.json file in order to be able to add the package by using composer.

    Thanks !

    opened by jphilung 3
  • Gatsby does not create node for regionalized pages

    Gatsby does not create node for regionalized pages

    Hi,

    I can query regionalized pages (like pages under /en-gb) on the WordPress graphQL IDE interface. But when Gatsby creates the nodes locally, those pages do not show on the local graphQL queries (using the same id as in the query above) and they show a 404 when I try to access them on the browser. Besides having the plugin installed, do I need to do anything special during the build process? Thanks,

    opened by wbertolo 3
  • Languages menu missing after Wordpress 6.1.1 update

    Languages menu missing after Wordpress 6.1.1 update

    After we updated to Wordpress 6.1.1, we no longer see the menu in other languages. GraphQL IDE does not retrieve the data either. GraphQL Version 1.13.7 and WPGraphQL WPML Version 1.1.0

    opened by achi-tricentis 0
  • Translation for isPostsPage is set to false

    Translation for isPostsPage is set to false

    When I'm making a query to get the posts page, translated page return false for value isPostsPage.

    Reading settings is configured on the good page.

    Query :

    {
      pages(where: {name: "blog"}) {
        nodes {
          uri
          isPostsPage
        }
      }
    }
    

    Result

    {
    "data": {
        "pages": {
          "nodes": [
            {
              "uri": "/blog/",
              "isPostsPage": true
            },
            {
              "uri": "/fr/blog/",
              "isPostsPage": false
            }
          ]
        }
      }
    }
    
    opened by MKlblangenois 1
  • Adds the language filtering option on taxonomy to post types connections

    Adds the language filtering option on taxonomy to post types connections

    Fixes the issue where language filtering did not work on relationships between taxonomies and post types.

    For example, the following query would return the posts associated to each category in the default language (english in my case), even if the categories are in french:

    categories(where: {wpmlLanguage: "fr"}) {
      nodes {
        id
        name
        posts {
          nodes {
            title
          }
        }
      }
    }
    

    I expected to received the linked posts in the same language as my category.

    My fix allows us to add the same wpmlLanguage filter on the child queries which will return the posts in the same language as the category:

    categories(where: {wpmlLanguage: "fr"}) {
      nodes {
        id
        name
        posts(where: {wpmlLanguage: "fr"}) {
          nodes {
            title
          }
        }
      }
    }
    

    This fix works for the relationship between posts and categories, but il also works with any relationships between custom taxonomies and custom post types.

    In an ideal world, we would not have to do this, but this is the fix I came up with. Feel free to do what you want with it.

    opened by macharest 1
  • Translated categories aren't showing in Graphql

    Translated categories aren't showing in Graphql

    I can't see the translated categories in the GraphQL. The below only shows the 3 categories in the default language - and not the translated categories.

    Similar issue happened with my menus - if you go into a translated menu and then save it, it will then remove all translated menus from the graphql.

    query MyQuery { terms(where: {taxonomies: CATEGORY}) { edges { node { id link name ... on Category { id name } taxonomyName uri } } } }

    opened by aaron-shop12 6
  • Enable taxonomy term translations

    Enable taxonomy term translations

    Overview

    Enables support for taxonomy term translations that return the correct translated IDs and objects for terms in non-default locales.

    get-tags

    Details

    Adds fields to Taxonomy types to be visible on the terms:

    • locale - the locale of the current term
    • translations - list of TermTranslation objects
    • translated - list of the translated Term objects

    Adds two hooks to resolve the issues with WPML term ID adjustment. Basically, WPML adjusts term ids for every request, shifting request terms to the "current language". The WPGraphQL requests don't typically use a current language and that's especially the case with Gatsby. We want to retrieve all of the terms at once and let Gatsby handle the language switching. These two hooks ensure that term IDs are untouched during GraphQL requests allowing retrieval of non-default locale terms.

    Adds a slug field to the term translation response to help in the situation where the same slug is used for terms in different locales. The example in the commit message shows what it would look like for the tech tag in two locales:

    • English

      • slug: tech
      • href: https://.../tag/tech
    • Spanish

      • slug: tech
      • href: https://.../es/tag/tech-2

    Having the slug allows the client to do what it needs - in our case, it was building out tag pages with the correct tag in the route.

    I've also included all of this context and more in the commit messages.

    opened by elskwid 3
Owner
null
Wordpress integrated with Laravel via Composer. Together, but independents.

Wordpress integrated with Laravel via Composer. Atention! The branch master is no longer manteined. Now I'm working on branch light. Not booting Larav

Bruno Barros 20 Nov 29, 2022
WPGraphQL Polylang Extension for WordPress

WPGraphQL Polylang Extension Extend WPGraphQL schema with language data from the Polylang plugin. Features For posts and terms (custom ones too!) Adds

Valu Digital 102 Dec 29, 2022
Wordpress wrapper to expose Carbon Fields to WpGraphQL queries.

WpGraphQLCrb A Wordpress wrapper to expose Carbon Fields to WpGraphQL queries. Important This is just the first version. There is a lot of work to be

Matheus Paiva 16 Aug 19, 2022
Adds Settings to the Custom Post Type UI plugin to show Post Types in WPGraphQL

DEPRECATION NOTICE ?? Custom Post Type UI v1.9.0 introduced formal support for WPGraphQL!!! ?? With that, this plugin is being deprecated and will no

WPGraphQL 77 Aug 3, 2022
This is an extension to the WPGraphQL plugin for Yoast SEO

WPGraphQl Yoast SEO Plugin Please note version 14 of the Yoast Plugin is a major update. If you are stuck on version of Yoast before V14 then use v3 o

Ashley Hitchcock 197 Dec 26, 2022
Authentication for WPGraphQL using JWT (JSON Web Tokens)

WPGraphQL JWT Authentication This plugin extends the WPGraphQL plugin to provide authentication using JWT (JSON Web Tokens) JSON Web Tokens are an ope

WPGraphQL 268 Dec 31, 2022
Enable query locking for WPGraphQL by implementing persisted GraphQL queries.

?? WP GraphQL Lock This plugin enables query locking for WPGraphQL by implementing persisted GraphQL queries. Persisted GraphQL queries allow a GraphQ

Valu Digital 21 Oct 9, 2022
WPGraphQL Extension: Adds "meta_query" support to postObject connection queries using WP_Query

WPGraphQL Meta Query This plugin adds Meta_Query support to the WP GraphQL Plugin for postObject query args. Why is this an extension and not part of

WPGraphQL 42 Nov 10, 2022
[ALPHA] Implementation of persisted queries for WPGraphQL

WPGraphQL Persisted Queries Persisted GraphQL queries allow a GraphQL client to optimistically send a hash of the query instead of the full query; if

Quartz 18 Jun 20, 2022
Send emails via mutation using WpGraphQl

WPGraphQL Send Email Plugin One of the simple things about a traditional WordPress sites is sending emails, this plugin makes it easy to do this via a

Ashley Hitchcock 18 Aug 21, 2022
An WPGraphQL extension that adds SearchWP's query functionality to the GraphQL server

QL Search What is QL Search? An extension that integrates SearchWP into WPGraphQL. Quick Install Install & activate SearchWP v3.1.9+ Install & activat

Funkhaus 11 May 5, 2022
Structured content blocks for WPGraphQL

WPGraphQL Content Blocks (Structured Content) This WPGraphQL plugin returns a WordPress post’s content as a shallow tree of blocks and allows for some

Quartz 72 Oct 3, 2022
WPGraphQL for Advanced Custom Fields

WPGraphQL for Advanced Custom Fields WPGraphQL for Advanced Custom Fields automatically exposes your ACF fields to the WPGraphQL Schema. Install and A

WPGraphQL 558 Jan 8, 2023
WPGraphQL FacetWP integration plguin

WPGraphQL-FacetWP: WPGraphQL provider for FacetWP Quick Install Download and install like any WordPress plugin. Documentation The WPGraphQL documentat

null 31 Dec 11, 2022
WPGraphQL for Meta Box

WPGraphQL-MetaBox: WPGraphQL provider for Meta Box Quick Install Download and install like any WordPress plugin. Documentation The WPGraphQL documenta

null 25 Aug 8, 2022
Add WooCommerce support and functionality to your WPGraphQL server

WPGraphQL WooCommerce (WooGraphQL) Docs • AxisTaylor • Join Slack Quick Install Install & activate WooCommerce Install & activate WPGraphQL Download t

WPGraphQL 546 Jan 2, 2023
The Pronamic WordPress Basecone plugin allows you to connect your WordPress installation to Basecone.

Pronamic WordPress Basecone The Pronamic WordPress Basecone plugin allows you to connect your WordPress installation to Basecone. Table of contents Au

Pronamic 1 Oct 19, 2021
A WordPress plugin to suspend WordPress sites automagically. Simple and lightweight, no annoying ads and fancy settings.

Suspend WP A WordPress plugin to suspend WordPress sites automagically. Simple and lightweight, no annoying ads and fancy settings. ?? Demo (coming so

Waren Gonzaga 3 Nov 15, 2021
WordPress plugin that lets you use Discourse as the community engine for a WordPress blog

WP Discourse Note: the wp-discourse plugin requires >= PHP-5.4.0. The WP Discourse plugin acts as an interface between your WordPress site and your Di

Discourse 497 Dec 10, 2022