Last active
May 31, 2018 15:00
-
-
Save izzygld/dd04dd65297bf1bce32d577a5d7a6326 to your computer and use it in GitHub Desktop.
Add: Group Object to WP-Grapql shema
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use GraphQL\Type\Definition\ObjectType; | |
use GraphQL\Type\Definition\Type; | |
add_action('graphql_page_fields', function($fields) { | |
$impactType = new ObjectType([ | |
'name' => 'Impact', | |
'description' => __( 'The description of your process type', 'your-textdomain' ), | |
'fields' => [ | |
'fp_metabox_impact__icon' => [ | |
'type' => WPGraphQL\Types::string(), | |
], | |
'fp_metabox_impact__number' => [ | |
'type' => WPGraphQL\Types::string(), | |
], | |
'fp_metabox_impact__name' => [ | |
'type' => WPGraphQL\Types::string(), | |
] | |
] | |
]); | |
$fields[ 'impactFp' ] = [ | |
'type' => Type::listOf($impactType), | |
'description' => __( 'Your processes repeater field in GraphQL', 'your-textdomain' ), | |
'resolve' => function( \WP_Post $post ) { | |
$fp_metabox_impact_group = get_post_meta( $post->ID, 'fp_metabox_impact_group', true ); | |
return ! empty( $fp_metabox_impact_group ) ? $fp_metabox_impact_group : null; | |
}, | |
]; | |
return $fields; | |
},99 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment