Skip to content

Commit

Permalink
Merge pull request #3 from wp-graphql/wpgraphql-v0.1.0-support
Browse files Browse the repository at this point in the history
update to be compatible with WPGraphQL v0.1.0
  • Loading branch information
jasonbahl authored Oct 30, 2018
2 parents e6e3da1 + c30196d commit ddf8141
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions wp-graphql-dad-jokes.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@
* Author URI: http://graphql.com
* Text Domain: wp-graphql-dad-jokes
* Domain Path: /languages
* Version: 0.1.01
* Version: 1.0.0
*
* @package WP_Graphql_Dad_Jokes
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

add_action( 'graphql_root_queries', 'wp_graphql_dad_jokes_root_query' );
add_action( 'graphql_register_types', function() {

function wp_graphql_dad_jokes_root_query( $fields ) {

$fields['dadJoke'] = [
'type' => \WPGraphQL\Types::string(),
register_graphql_field( 'RootQuery', 'dadJoke', [
'type' => 'String',
'description' => __( 'Returns a random Dad joke', 'wp-graphql' ),
'resolve' => function() {
$get_dad_joke = wp_remote_get('https://icanhazdadjoke.com/', [
Expand All @@ -33,8 +31,6 @@ function wp_graphql_dad_jokes_root_query( $fields ) {
$joke = ! empty( $body->joke ) ? $body->joke : null;
return $joke;
},
];

return $fields;
]);

}
} );

0 comments on commit ddf8141

Please sign in to comment.