WPGraphQL for Meta Box

Overview

WPGraphQL-MetaBox: WPGraphQL provider for Meta Box

Quick Install

Download and install like any WordPress plugin.

Documentation

The WPGraphQL documentation can be found here.

  • Requires PHP 7.3+
  • Requires WordPress 5.4+
  • Requires WPGraphQL 1.1.3+
  • Requires Meta Box 5.3.8+
    • Requires MB User Meta extension for User fields

Overview

This plugin provides an integration for Meta Box and WPGraphQL.

By simply adding an extra graphql_name property to the field registration the field will be exposed in the GraphQL schema.

Usage:

This assume you know how to expose custom post types in WPGraphQL - read their documentation for further info.

Using Meta Box, define a custom field. Copy and paste the generated code to your functions.php (or where ever you store your custom code).

wp-graphql-metabox options

option type effect
graphql_name string adds the field to the GraphQL object(s) identified in post_types
graphql_mutate boolean adds the field to the GraphQL object(s) create and update mutation input

Add in the graphql_name to the field definition:

$meta_boxes[] = [
    'title' => 'Extra Fields',
    'id' => 'extra-fields',
    'post_types' => [
        0 => 'post',
    ],
    'context' => 'after_title',
    'priority' => 'high',
    'autosave' => true,
    'fields' => [
        [
            'id' => 'a_random_number',
            'name' => 'A Random Number',
            'type' => 'number',
            'std' => 5,
            'columns' => 2,
            'size' => 3,
            'graphql_name' => 'randomNumber',
            'graphql_mutate' => true
        ],
    ],
];

That's it. The field randomNumber will be exposed on the type post. This will work for any custom post types you may create.

NB: You must expose custom types by adding show_in_graphql to the configuration of the CPT.

A simple query might look like this:

query {
    posts {
        nodes {
            title
            content
            randomNumber
        }
    }
}

Limitations

Currently the plugin only supports custom fields on post and user types (ie no Settings Pages).

Currently the plugin only supports using the following Meta Box types:

  • taxonomy
  • taxonomy_advanced
  • switch
  • checkbox
  • checkbox_list
  • background
  • color
  • custom_html
  • date
  • heading
  • datetime
  • oembed
  • password
  • radio
  • textarea
  • time
  • select
  • email
  • tel
  • text
  • url
  • wysiwyg
  • fieldset_text
  • select_advanced
  • text_list
  • key_value
  • number
  • range
  • single_image
  • user
  • post
  • group If you require a field which is not supported please feel free to submit an issue (or better yet, a PR!)
Comments
  • Support for text_list with clone option

    Support for text_list with clone option

    If you define a text_list with the option 'clone' => true the graphql model should be an array of string arrays otherwise you will get an graphql error when quering the custom fields.

    function ingredients_register_meta_boxes( $meta_boxes ) {
    	$meta_boxes[] = [
    		'title'      => esc_html__( 'Ingredients' ),
    		'id'         => 'zutaten',
    		'post_types' => ['ingredients'],
    		'context'    => 'normal',
    		'priority'   => 'high',
    		'fields'     => [
    			[
    				'type'    => 'text_list',
    				'id'      => 'ingredients',
    				'name'    => esc_html__( 'Ingredients' ),
    				'desc'    => esc_html__( 'Specify the ingredients' ),
    				'clone'   => true,
    				'options' => [
    					'100'    => 'Amount',
                                            'ml'     => 'Unit',
                                            'Water' => 'Name',
    				],
    				'graphql_name' => 'ingredients',
    			],
    		],
    	];
    
    	return $meta_boxes;
    }
    
    add_filter( 'rwmb_meta_boxes', 'ingredients_register_meta_boxes' );
    

    I also provided a fix with this PR: #28

    opened by NilsEngelbach 8
  • Add connection registration

    Add connection registration

    This needs some investigation. Complex type fields (ie post, user) could be handled in different ways;

    • single field (eg Instructor (user) for a Tutorial (post) can be resolved by looking up the type and getting the graphql_single_name. No edge data.
    • multiple fields (eg Questions (post) on a Quiz (post) can be resolved by registering a graphql connection between the two types. Edge data.
    opened by hsimah 2
  • Upgrade deprecated code

    Upgrade deprecated code

    Users can be resolved by using the context:

    'patient' => [
    	'type'        => 'User',
    	'resolve'        => function ($payload, $args, $context, $info){
    		$userId = $payload['user_id'];
    		return $context->get_loader( 'user' )->load_deferred( $userId )
    	},
    ],
    
    opened by hsimah 1
  • Add the email type fields

    Add the email type fields

    Hi,

    I just added the email type fields. They are probably not in the Meta Box documentation because they behave exactly the same as the text fields with the difference that the input validation is added.

    opened by rodrigo-arias 1
  • Mutations

    Mutations

    Now that my PR has been merged into MB we can look into working on mutations.

    From memory it used to be difficult to hook into WPGraphQL generated mutations. Previously I registered a new mutation to deal with custom fields.

    What this needs:

    • mutation input args; the mutation needs to be aware there are new fields as input
    • hook into this action to run rwmb_set_meta
    enhancement 
    opened by hsimah 1
  • Refactor plugin structure

    Refactor plugin structure

    This plugin will be much larger than previous WordPress plugins I have written. I will need to have a few helper/resolver classes.

    • User resolver
    • Post resolver
    • Settings resolver
    • Meta Box type utility function
    opened by hsimah 1
  • Feature/mutations

    Feature/mutations

    Give generating mutations inputs a go.

    Some things to note:

    • taxonomy fields are already added as inputs to mutations -> no work necessary
    • this uses rwmb_set_meta function to set the meta data -> this should work with both custom tables and wp_meta fields
    • untested with users, posts etc
    • add graphql_mutate to your field config to generate
    opened by hsimah 0
  • Add support for metabox text_list with clone option

    Add support for metabox text_list with clone option

    If you define a text_list with the option 'clone' => true the graphql model should be an array of string arrays.

    function ingredients_register_meta_boxes( $meta_boxes ) {
    	$meta_boxes[] = [
    		'title'      => esc_html__( 'Ingredients' ),
    		'id'         => 'zutaten',
    		'post_types' => ['ingredients'],
    		'context'    => 'normal',
    		'priority'   => 'high',
    		'fields'     => [
    			[
    				'type'    => 'text_list',
    				'id'      => 'ingredients',
    				'name'    => esc_html__( 'Ingredients' ),
    				'desc'    => esc_html__( 'Specify the ingredients' ),
    				'clone'   => true,
    				'options' => [
    					'100'    => 'Amount',
                                            'ml'     => 'Unit',
                                            'Water' => 'Name',
    				],
    				'graphql_name' => 'ingredients',
    			],
    		],
    	];
    
    	return $meta_boxes;
    }
    
    add_filter( 'rwmb_meta_boxes', 'ingredients_register_meta_boxes' );
    
    opened by NilsEngelbach 0
  • Feature/resolve posts

    Feature/resolve posts

    • resolve linked post types from fields
    • update some other types to respect the multiple === true setting
    • fixed bad dependency check on MB Relationship not MB core
    opened by hsimah 0
  • Support fields with multiple = true

    Support fields with multiple = true

    Check out fields that can be multiple (eg users) and handle their graphql types:

    If type is text and multiple = false should be String If type is text and multiple = true should be ['list_of' => 'String']

    opened by hsimah 0
  • GraphQL\Type\Schema::resolveType() must be an instance of GraphQL\Type\Definition\Type

    GraphQL\Type\Schema::resolveType() must be an instance of GraphQL\Type\Definition\Type

    It seems that v1.6 introduced Lazy Type Loading https://github.com/wp-graphql/wp-graphql/issues/2049

    So, I'm getting the following error while using your extension

    ERROR

    gatsby-source-wordpress Error category: undefined

    Error: Internal server error

    Debug message: Return value of GraphQL\Type\Schema::resolveType() must be an instance of GraphQL\Type\Definition\Type, array returned

    Error path: __schema.types

    ERROR #gatsby-source-wordpress_111002

    Any chance for an update or a clue of what needs to be updated?

    opened by chicharitomagnetico 2
  • Init hooks

    Init hooks

    I'm not adept enough with WP to ensure I have correctly hooked into the request lifecycle. The code works, but is it efficient? Not sure. Hopefully someone can provide some insight and refactor the loading code.

    opened by hsimah 0
  • Autoloading

    Autoloading

    I've seen nice autoloading code in Meta Box plugins, but I never bothered to implement it in this plugin. Maybe someone could submit a PR cleaning up the loading of source files.

    opened by hsimah 0
  • Unit testing

    Unit testing

    I have not written tests as I'm not skilled with writing tests for WordPress/PHP. This should have some level of sanity testing to ensure no regressions from version to version.

    If I could get some test scaffolding done I can fill in the necessary tests from the GraphQL standpoint.

    opened by hsimah 0
  • metabox settings pages

    metabox settings pages

    Have you looked into supporting metabox settings pages at all? I'm just getting started with wp-graphql, and I see that settings registered via register_settings() are natively supported, but I'm not quite sure where to get started if I would want some of my metabox.io created settings pages registered for graphql?

    enhancement help wanted 
    opened by wkoehn 4
Releases(0.4.0)
  • 0.4.0(Jan 4, 2021)

    Enabled group fields!

    Groups will generate a new type for the group config. A sample config may look like:

    [
      'id' => 'my_group',
      'type' => 'group',
      'name' => 'My Group',
      'graphql_name' => 'MyGroup', // <-- this is the _type_ name and must be unique
      'fields' => [
        [
          'id' => 'group_text_field',
          'type' => 'text',
          'name' => 'Text Field',
         'graphql_name' => 'textField', // <-- this is the _field_ name and must be unique for the group
        ],
        [
          'id' => 'nested_group',
          'type' => 'group',
          'name' => 'Nested Group',
          'graphql_name' => 'MyGroup', // <-- this is the _type_ name and must be unique
          'fields' => [
            [
              'id' => 'nested_text',
              'type' => 'text',
              'name' => 'Nested Text',,
              'graphql_name' => 'textField', // <-- this is the _field_ name and must be unique for the group
            ],
            [
              // this field will not be exposed to the schema
              'id' => 'nexted_checkbox',
              'type' => 'checkbox',
              'desc' => 'Is Active',
            ],
          ],
          'clone' => 1,
          'default_state' => 'expanded',
          'add_button' => 'Add Choice',
        ],
      ],
      'clone' => 1,
      'default_state' => 'expanded',
      'add_button' => 'Add group',
    ];
    
    Source code(tar.gz)
    Source code(zip)
  • 0.3.1(Jan 4, 2021)

  • 0.3.0(Jan 2, 2021)

  • 0.2.3(Nov 9, 2020)

  • 0.2.2(May 3, 2020)

  • 0.2.1(Apr 20, 2020)

  • 0.2.0(Apr 19, 2020)

Owner
null
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 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
a wordpress plugin that improves wpgraphql usage together with wpml

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.

null 42 Dec 15, 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
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
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
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
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
Adds meta data registered via register_meta() to the GraphQL output.

WP GraphQL Meta This plugin is an add-on for the awesome WP GraphQL It builds on top of both WP GraphQL and the REST API. Any meta data you register u

Robert O'Rourke 18 Aug 4, 2021
A tool box of integrations for Cardano & WordPress all packaged into a neat plugin.

CardanoPress A tool box of integrations for Cardano & WordPress all packaged into a neat plugin. This plugin allows you to integrate various Cardano b

Peter Bui 38 Oct 4, 2022
Arc meta - Textpattern plugin for meta tags to improve site SEO and social marketing.

arc_meta A Textpattern plugin for meta tags to improve site SEO and social marketing. arc_meta adds meta fields to your article, section and category

Andy Carter 3 Jan 20, 2017
Hi Im L, I found a box that I believe it's contain Kira's real ID. for open that box we need to find three keys. let's start looking for them

DeathNote ctf Description are you smart enaugh to help me capturing the three keys for open the box that contain the real ID of kira? Let's start solv

Hamza Elansari 4 Nov 28, 2022
Scotch Box is a preconfigured Vagrant Box with a full array of LAMP Stack features to get you up and running with Vagrant in no time.

Scotch Box is a preconfigured Vagrant Box with a full array of LAMP Stack features to get you up and running with Vagrant in no time.

scotch 2.7k Jan 8, 2023
EXPERIMENTAL plugin extending WPGraphQL to support querying (Gutenberg) Blocks as data, using Server Side Block registries to map Blocks to the GraphQL Schema.

WPGraphQL Block Editor This is an experimental plugin to work toward compatiblity between the WordPress Gutenberg Block Editor and WPGraphQL, based on

WPGraphQL 29 Nov 18, 2022