Overview
  • Namespace
  • Class

Namespaces

  • WPGraphQL
    • Data
    • Type
      • Avatar
      • Comment
        • Connection
      • CommentAuthor
      • EditLock
      • Enum
      • MediaItem
        • Mutation
      • Plugin
        • Connection
      • PostObject
        • Connection
        • Mutation
      • PostType
      • Setting
      • Taxonomy
      • TermObject
        • Connection
        • Mutation
      • Theme
        • Connection
      • Union
      • User
        • Connection
        • Mutation
    • Utils

Classes

  • Config
  • ConnectionResolver
  • DataSource
  • Loader

Interfaces

  • ConnectionResolverInterface

Class DataSource

Class DataSource

This class serves as a factory for all the resolvers for queries and mutations. This layer of abstraction over the actual resolve functions allows easier, granular control over versioning as we can change big things behind the scenes if/when needed, and we just need to ensure the call to the DataSource method returns the expected data later on. This should make it easy down the road to version resolvers if/when changes to the WordPress API are rolled out.

Namespace: WPGraphQL\Data
Package: WPGraphQL\Data
Since: 0.0.4
Located at Data/DataSource.php

Methods summary

public static WP_Comment
# resolve_comment( integer $id )

Retrieves a WP_Comment object for the id that gets passed

Retrieves a WP_Comment object for the id that gets passed

Parameters

$id
ID of the comment we want to get the object for

Returns

WP_Comment
object

Throws

GraphQL\Error\UserError

Since

0.0.5
public static array
# resolve_comment_author( string $author_email )

Retrieves a WP_Comment object for the ID that gets passed

Retrieves a WP_Comment object for the ID that gets passed

Parameters

$author_email
The ID of the comment the comment author is associated with.

Returns

array

Throws

public static mixed
# resolve_comments_connection( WP_Post $source, array $args, WPGraphQL\AppContext $context, GraphQL\Type\Definition\ResolveInfo $info )

Wrapper for the CommentsConnectionResolver class

Wrapper for the CommentsConnectionResolver class

Parameters

$source
$source
$args
Query args to pass to the connection resolver
$context
The context of the query to pass along
$info
The ResolveInfo object

Returns

mixed

Since

0.0.5
public static null|array
# resolve_plugin( string $name )

Returns an array of data about the plugin you are requesting

Returns an array of data about the plugin you are requesting

Parameters

$name
Name of the plugin you want info for

Returns

null|array

Throws

Exception

Since

0.0.5
public static array
# resolve_plugins_connection( WP_Post $source, array $args, WPGraphQL\AppContext $context, GraphQL\Type\Definition\ResolveInfo $info )

Wrapper for PluginsConnectionResolver::resolve

Wrapper for PluginsConnectionResolver::resolve

Parameters

$source
WP_Post object
$args
Array of arguments to pass to reolve method
$context
AppContext object passed down
$info
The ResolveInfo object

Returns

array

Since

0.0.5
public static WP_Post
# resolve_post_object( integer $id, string $post_type )

Returns the post object for the ID and post type passed

Returns the post object for the ID and post type passed

Parameters

$id
ID of the post you are trying to retrieve
$post_type
Post type the post is attached to

Returns

WP_Post

Throws

GraphQL\Error\UserError

Since

0.0.5
public static mixed
# resolve_post_objects_connection( string $source, array $args, WPGraphQL\AppContext $context, GraphQL\Type\Definition\ResolveInfo $info, GraphQL\Type\Definition\ResolveInfo $post_type )

Wrapper for PostObjectsConnectionResolver

Wrapper for PostObjectsConnectionResolver

Parameters

$source
$post_type Post type of the post we are trying to resolve
$args
$context
$args Arguments to pass to the resolve method
$info
$context AppContext object to pass down
$post_type
$info The ResolveInfo object

Returns

mixed

Since

0.0.5
public static WP_Post_Type
# resolve_post_type( string $post_type )

Gets the post type object from the post type name

Gets the post type object from the post type name

Parameters

$post_type
Name of the post type you want to retrieve the object for

Returns

WP_Post_Type
object

Throws

GraphQL\Error\UserError

Since

0.0.5
public static WP_Taxonomy
# resolve_taxonomy( string $taxonomy )

Retrieves the taxonomy object for the name of the taxonomy passed

Retrieves the taxonomy object for the name of the taxonomy passed

Parameters

$taxonomy
Name of the taxonomy you want to retrieve the taxonomy object for

Returns

WP_Taxonomy
object

Throws

GraphQL\Error\UserError

Since

0.0.5
public static mixed
# resolve_term_object( integer $id, string $taxonomy )

Get the term object for a term

Get the term object for a term

Parameters

$id
ID of the term you are trying to retrieve the object for
$taxonomy
Name of the taxonomy the term is in

Returns

mixed

Throws

GraphQL\Error\UserError

Since

0.0.5
public static array
# resolve_term_objects_connection( $source, array $args, WPGraphQL\AppContext $context, GraphQL\Type\Definition\ResolveInfo $info, WP_Taxonomy $taxonomy )

Wrapper for TermObjectConnectionResolver::resolve

Wrapper for TermObjectConnectionResolver::resolve

Parameters

$source
$args
Array of args to be passed to the resolve method
$context
The AppContext object to be passed down
$info
The ResolveInfo object
$taxonomy
The WP_Taxonomy object of the taxonomy the term is connected to

Returns

array

Since

0.0.5
public static WP_Theme
# resolve_theme( string $stylesheet )

Retrieves the theme object for the theme you are looking for

Retrieves the theme object for the theme you are looking for

Parameters

$stylesheet
Directory name for the theme.

Returns

WP_Theme
object

Throws

GraphQL\Error\UserError

Since

0.0.5
public static array
# resolve_themes_connection( $source, array $args, WPGraphQL\AppContext $context, GraphQL\Type\Definition\ResolveInfo $info )

Wrapper for the ThemesConnectionResolver::resolve method

Wrapper for the ThemesConnectionResolver::resolve method

Parameters

$source
$args
Passes an array of arguments to the resolve method
$context
The AppContext object to be passed down
$info
The ResolveInfo object

Returns

array

Since

0.0.5
public static GraphQL\Deferred
# resolve_user( integer $id )

Gets the user object for the user ID specified

Gets the user object for the user ID specified

Parameters

$id
ID of the user you want the object for

Returns

GraphQL\Deferred

Since

0.0.5
public static array
# resolve_users_connection( $source, array $args, WPGraphQL\AppContext $context, GraphQL\Type\Definition\ResolveInfo $info )

Wrapper for the UsersConnectionResolver::resolve method

Wrapper for the UsersConnectionResolver::resolve method

Parameters

$source
$args
Array of args to be passed down to the resolve method
$context
The AppContext object to be passed down
$info
The ResolveInfo object

Returns

array

Since

0.0.5
public static array
# get_setting_group_fields( string $group )

Get all of the registered settings in a WP site and return the ones that match the name of the $setting_type

Get all of the registered settings in a WP site and return the ones that match the name of the $setting_type

Parameters

$group

Returns

array
$fields
public static array
# get_allowed_setting_types( )

Get the $allowed_setting_types and filter them so that they can be further whitelisted. This method is used to build out the root query fields for the various setting types

Get the $allowed_setting_types and filter them so that they can be further whitelisted. This method is used to build out the root query fields for the various setting types

Returns

array
$allowed_setting_types
public static array
# get_node_definition( )

We get the node interface and field from the relay library.

We get the node interface and field from the relay library.

The first method is the way we resolve an ID to its object. The second is the way we resolve an object that implements node to its type.

Returns

array

Throws

GraphQL\Error\UserError
public static WP_Post|null
# get_post_object_by_uri( string $uri, string $output = OBJECT, string $post_type = 'post' )

Cached version of get_page_by_path so that we're not making unnecessary SQL all the time

Cached version of get_page_by_path so that we're not making unnecessary SQL all the time

This is a modified version of the cached function from WordPress.com VIP MU Plugins here.

Parameters

$uri
$output
Optional. Output type; OBJECT*, ARRAY_N, or ARRAY_A.
$post_type
Optional. Post type; default is 'post'.

Returns

WP_Post|null
WP_Post on success or null on failure

See

https://github.com/Automattic/vip-go-mu-plugins/blob/52549ae9a392fc1343b7ac9dba4ebcdca46e7d55/vip-helpers/vip-caching.php#L186

Link

Uncached Functions

Properties summary

protected static array $node_definition

Stores an array of node definitions

Stores an array of node definitions

Since

0.0.4
#
protected static array $allowed_setting_types

Stores an array of setting types that exist in get_registered_settings. In order to register a setting with register_setting it must be categorized under one of the whitelisted group names See: https://developer.wordpress.org/reference/functions/register_setting/

Stores an array of setting types that exist in get_registered_settings. In order to register a setting with register_setting it must be categorized under one of the whitelisted group names See: https://developer.wordpress.org/reference/functions/register_setting/

#
protected static array $allowed_setting_groups

Stores an array of allowed setting groups.

Stores an array of allowed setting groups.

#
API documentation generated by ApiGen