Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (44 sloc) 1.46 KB
title description
GraphQL Fields API Reference
Learn how to register, deregister and filter GraphQL fields

Register Fields to the Schema

@todo: Document the registration API

  • register_graphql_field()
  • deregister_graphql_field()

Register field for custom post

				'type'        => 'String',
				'description' => __( 'Document validity from', 'wp-graphql' ),
				'resolve'     => function( $post ) {
					$document_date = get_post_meta( $post->ID, 'date_from', true );
					return $document_date;

Register field for user

		$hobbies = [
			'type'        => \WPGraphQL\Types::list_of( \WPGraphQL\Types::string() ),
			'description' => __( 'Custom field for user mutations', 'your-textdomain' ),
			'resolve'     => function( $user ) {
				$hobbies = get_user_meta( $user->userId, 'hobbies', true );
				return ! empty( $hobbies ) ? $hobbies : [];

		register_graphql_field( 'User', 'hobbies', $hobbies );
		register_graphql_field( 'CreateUserInput', 'hobbies', $hobbies );
		register_graphql_field( 'UpdateUserInput', 'hobbies', $hobbies );

Filtering Field Definitions

@todo: Document how to filter existing field definitions

Root Fields

@todo: Document that fields on any Type in the Schema are the same, including Root Fields, they're
just fields on the RootQuery Type, so they serve as a root entry into the Schema.
You can’t perform that action at this time.