Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue#20 widget queries #485

Conversation

kidunot89
Copy link
Member

@kidunot89 kidunot89 commented Aug 7, 2018

Your checklist for this pull request

Thanks for sending a pull request! Please make sure you click the link above to view the contribution guidelines, then fill out the blanks below.

🚨Please review the guidelines for contributing to this repository.

  • Make sure you are making a pull request against the develop branch (left side). Also you should start your branch off our develop.
  • Make sure you are requesting to pull request from a topic/feature/bugfix branch (right side). Don't pull request from your master!

What does this implement/fix? Explain your changes.

Adds Sidebar/Widget types and connections. As well as InterfaceType wrapper WPGraphQL\Type\WPInterfaceType and abstract class WPGraphQL\TypeRegistry for creating TypeRegistries.

Example TypeRegistry

namespace Namespace;

use WPGraphQL\Data\DataSource;
use WPGraphQL\Type\WPObjectType;
use WPGraphQL\TypeRegistry;
use WPGraphQL\Types;

class TypeRegistryA extends TypeRegistry {

    // Must have so registry can be identified 
    protected static $__CLASS__ = __CLASS__;

    /**
     * Return indexed array of types for identification. This is used primarily to tell schema about types that
     * aren't registered on the root type registry. So this can be a skeleton function on root registry
     *
     * @return array
     */
    protected static function get_types() {
         $types = [
              self::test_enum()
         ];

         // Get type data PS:get_type_data isn't a real function
         $types_data = DataSource::get_types_data()
         
         foreach( $widgets as $type_name => $type_data ) {
             $types[] = self::$type_name( $type_data );
         }

         return $type;
    }

     /**
     * Meant to return default type object for non-local registered types. 
     *
     * @return array
     */
    protected static function _config( $type_name, $type_data = null ) {
         if ( null === $data ) return null

         ...   // Format data

         // initialize type
         return new WPObjectType( [
             'name'        => $type_name,
             'description' => $description,
	     'fields'      => $fields,
	     'interfaces'  => $interfaces,
         ] );
    }

    /**
     * Locally registered type
     */
    public static function test_enum() {
         return self::$type[ $self::registry_name ][ 'test_enum' ] ?: ( self::$type[ $self::registry_name]['test_enum'] = new TestEnum() ); 
    }
}

TypeRegistry::$types can also be extended by the graphql_register_{$registry_name}::{$type_name}

The $registry_name is set in the constructor. The constructor is meant to be called at the end of constructor of whatever type the registry is meant to extend e.g. self::$registry = new TypeRegistry( $registry_name );. I haven't to write test for it yet because it manifested itself as I was cleaning up the WidgetTypes class

Does this close any currently open issues?

#20 #327

Any relevant logs, error output, GraphiQL screenshots, etc?

(If it’s long, please paste to https://ghostbin.com/ and insert the link here.)

Any other comments?

I'm holding off on mutations until the types and connections are reviewed and merged.

Where has this been tested?

Operating System: Ubuntu 18.04

WordPress Version: 4.9.6

@jasonbahl
Copy link
Collaborator

@kidunot89 this is rad. Thanks for working on this.

I will give it a good run through and review this week.

Thanks!

@jasonbahl jasonbahl added Status: In Review Needs to be reviewed by a project maintainer before merge Status: In Progress Type: Feature labels Aug 7, 2018
@kidunot89 kidunot89 force-pushed the issue#20-21-widget-queries-and-mutations branch from 1a6916e to 0a64b0a Compare August 9, 2018 04:35
@kidunot89 kidunot89 force-pushed the issue#20-21-widget-queries-and-mutations branch from 8271735 to 34376ff Compare August 9, 2018 23:18
@kidunot89 kidunot89 closed this Nov 12, 2018
@jrmcdona
Copy link

Is there documentation somewhere about building a Graph QL query to build a side bar widget? I didn't see it on the main site. Thanks

@jrmcdona jrmcdona mentioned this pull request Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: In Progress Status: In Review Needs to be reviewed by a project maintainer before merge Type: Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants