Archives: Functions

  • register_graphql_admin_notice

    Add an admin notice that will display on the plugins page, network plugins page, WPGraphQL Settings page and WPGraphQL IDE page.

    This is helpful for plugin authors and core WPGraphQL maintainers alert users about important information regarding WPGraphQL, such as upcoming breaking changes, important releases, etc.

    register_graphql_admin_notice( string $slug, array $config );

    Parameters

    • $slug (string): A unique slug to identify the admin notice by
    • $config (array): Configuration for the notice
      • $message (string ) (required): The message to display in the admin notice. Sanitized by wp_kses_post before rendering.
      • $type (string): Determines the style of notice to display. Possible values are “error | warning | success | info”
      • $is_dismissable (boolean): Whether the notice should be dismissable or not. Dismissable notices will store the slug in user meta and any dismissed notices will no longer display for the user that dismissed the notice.
      • $conditions (function): Callback function to determine conditions for when the notice should be rendered. Return true to display the notice, false to keep it hidden.
        • Examples include rendering a notice if another plugin is not active, and hiding it if it is active. Or rendering a notice for users with specific capabilities and hiding for other users.

    Source

    File: access-functions.php

    Examples

    Below are some examples of registering a graphql admin notice.

    Register an Admin Notice to inform users about the new WPGraphQL for ACF plugin.

    This example shows an admin notice registered to inform users about the new WPGraphQL for ACF plugin.

    The notice is a dismissable “info” notice and will only be displayed if the following conditions are both met:

    • Advanced Custom Fields (free or pro) is active
    • WPGraphQL for ACF v2.0+ is _not_ active

    For users that do not use ACF or already have the latest WPGraphQL for ACF active, the notice will not display. Further, any user that dismisses the notice will not see it again.

    register_graphql_admin_notice(
        'wpgraphql-acf-announcement',
        [
            'type'           => 'info',
            'message'        => __( 'You are using WPGraphQL and Advanced Custom Fields. Have you seen the new WPGraphQL for ACF?', 'wp-graphql' ),
            'is_dismissable' => true,
            'conditions'     => static function () {
                if ( ! class_exists( 'ACF' ) ) {
                    return false;
                }
    
                // Bail if new version of WPGraphQL for ACF is active.
                if ( class_exists( 'WPGraphQLAcf' ) ) {
                    return false;
                }
    
                return true;
            },
        ]
    );
  • register_graphql_union_type

    Given a Type Name and a `$config` array, this adds an UnionType to the TypeRegistry

    register_graphql_union_type( string $type_name, array $config );

    Parameters

    • $type_name (string): The unique name of the Type in the Schema. This must be unique amongst the entire Schema.
    • $config (array): Configuration for the field
      • $description (string): Description of the Union type.
      • $types (array): An array of Types that the union could return
      • $resolveType (function): A function that takes the resolving data and determines what GraphQL Type should be returned.

    Source

    File: access-functions.php

    Example

    Unions are useful when a field needs to return different Types that don’t implement a common interface.

    An example of when using a Union might be good would be adding search functionality that could search across. For example, if you had a Movie Database site, you might want to have a search query return Genres (a custom taxonomy for example sake) or Movies (a custom post type for example sake) in the same list.

    To do this, you would need to register a Union that could return a `Genre` or a `Movie`.

    We’re going to assume that we already have a Genre Taxonomy registered to show in GraphQL, and a Movie Post Type registered to Show in GraphQL, so we can make use of the Genre and Movie Types in our Schema.

    Below, is a snippet showing how to register a Union that could return a Genre or a Movie.

    add_action( 'graphql_register_types', 'register_pet_union', 10, 1 );
    
    function register_pet_union( $type_registry ) {
      register_graphql_union_type( 'GenreOrMovieUnion', [
        'typeNames'       => [ 'Genre', 'Movie' ],
        'resolveType' => function( $search_result ) use ( $type_registry ) {
          // Here we receive the object or array that's being resolved by the field
          // and we can determine what Type to return
          $type = null;
    
          if ( $search_result instanceof \WPGraphQL\Model\Term && $search_result->taxonomy === 'genre' ) {
            $type = 'Genre';
          } else if ( $search_result instanceof \WPGraphQL\Model\Post && $search_result->post_type === 'movie' ) {
            $type = 'Movie;
          }
          return $type;
        }
      ] );
    }

    This registers a Union type named GenreOrMovieUnion.

    The typeNames field defines what Types from the Schema are possible to be returned. In this case, the Genre or Movie Type.

    Then resolveType is the function that runs during execution to determine what Type should be returned. It accepts the resolving data, and you can use that data to determine what Type to return.

    In our case, either a Post or Term would be returned to the Union, so we can check which Type it is and determine whether it’s a Taxonomy or a Post and set the return type appropriately.

    Now, we can use the Union in a field.

    add_action( 'graphql_register_types', function() {
    
     register_graphql_field( 'RootQuery', 'searchMoviesAndGenres', [
        'description' => __( 'Search across Movies and Genres', 'your-textdomain' ),
        'type' => [ 'list_of' => 'GenreOrMovieUnion' ],
        'resolve' => function() {
    
            // There's no easy way out of the box to search across Terms and Posts
            // So I'll leave that up to you. 
            // But, let's say you return the following payload: 
    
            $data = [
               new \WPGraphQL\Model\Term( get_term( $term_id ) ),
               new \WPGraphQL\Model\Post( get_post( $post_id ) ),
            ];
    
            return $data;
        }
     ] );
    });

    Now we have a searchMoviesAndGenres field on our RootQuery that returns a list of items, containing both Posts and Terms, we could now search like so:

    Now, we can query like so:

    {
    	searchMoviesAndGenres {
    		__typename
    		... on Movie {
    			title
    			releaseDate
    		}
    		... on Genre {
    			name
    			description
    		}
    	}
    }

    And we’ll receive the following data:

    {
    	"data": {
    		"searchMoviesAndGenres": [
    			{
    				"__typename": "Movie",
    				"title": "Gone With the Wind",
    				"releaseDate": "2020-11-5",
    			},
    			{
    				"__typename": "Genre",
    				"name": "Classic",
    				"description": "Example genre description"
    			}
    		]
    	}
    }
  • register_graphql_field

    Add a field to a Type in the GraphQL Schema

    register_graphql_field( string $type_name, string $field_name, array $config );

    Parameters

    • $type_name (string): The name of the GraphQL Type in the Schema to register the field to
    • $field_name (string): The name of the field. Should be unique to the Type the field is being registered to.
    • $config (array): Configuration for the field
      • $type (string | array): The name of the GraphQL Type the field will return. The resolve function must return this type.
        • For non-null fields: 'type' => [ 'non_null' => 'TypeName' ]
        • For listOf fields: 'type' => [ 'list_of' => 'TypeName' ]
      • $description (string): Description of the field. This will be used to self-document the schema and should describe to clients how the field should be used.
      • $resolve (function): Function that will execute when the field is asked for in a query.

    Source

    File: access-functions.php

    Examples

    Below are some examples of using the function to extend the GraphQL Schema.

    Register a Root Field

    This example adds a field to the root of the GraphQL Schema.

    add_action( 'graphql_register_types', function() {
      register_graphql_field( 'RootQuery', 'testField', [
        'type' => 'String',
        'description' => __( 'Example field added to the RootQuery Type', 'replace-with-your-textdomain' ),
        'resolve' => function( $root, $args, $context, $info ) {
          return 'Example string.';
        }
      ] );
    });

    Example Query

    {
      testField
    }
    Screenshot of the example query for testField
    Screenshot of the example query for testField

    Register a Post Field

    This example shows how to register a field to the Post type.

    add_action( 'graphql_register_types', function() {
      register_graphql_field( 'Post', 'testPostField', [
        'type' => 'String',
        'description' => __( 'Example field added to the Post Type', 'replace-with-your-textdomain' ),
        'resolve' => function( \WPGraphQL\Model\Post $post, $args, $context, $info ) {
          return 'Example string with the title of the post: ' . $post->titleRendered;
        }
      ] );
    });

    Example Query

    {
      posts(first: 1) {
        nodes {
          title
          testPostField
        }
      }
    }
    Screenshot of an example query for the "testPostField" registered to the "Post" Type
    Screenshot of an example query for the “testPostField” registered to the “Post” Type

    Register a field to an Interface

    This example shows how to register a field to an Interface. In this example, a field is registered to the “ContentNode” Interface. This means any Type (any WordPress Post Type) in the Schema that implements the “ContentNode” interface will have the field.

    add_action( 'graphql_register_types', function() {
      register_graphql_field( 'ContentNode', 'testContentNodeField', [
        'type' => 'String',
        'description' => __( 'Example field added to the ContentNode Interface', 'replace-with-your-textdomain' ),
        'resolve' => function( \WPGraphQL\Model\Post $post_model, $args, $context, $info ) {
          return 'Example string with the title of the post: ' . $post->titleRendered;
        }
      ] );
    });

    Example Query:

    {
      contentNodes(first: 2, where: {contentTypes: [PAGE, POST]}) {
        nodes {
          __typename
          id
          testContentNodeField
        }
      }
    }
    Screenshot of a query for contentNodes of multiple content types asking for the "testContentNodeField" field
    Screenshot of a query for contentNodes of multiple content types asking for the “testContentNodeField” field
  • register_graphql_fields

    Add one or more fields to a Type in the GraphQL Schema

    register_graphql_fields( string $type_name, array $fields );

    Parameters

    • $fields (array): Associative array of key/value pairs where the key is the name of the field and the value is a config array for the field.
      • $name (string): The name of the field to add to the Type. “camelCase” recommended.
      • $config (array): The config for the field being registered
        • $type (string | array): The name of the GraphQL Type the field will return. The resolve function must return this type.
          • For non-null fields: 'type' => [ 'non_null' => 'TypeName' ]
          • For listOf fields: 'type' => [ 'list_of' => 'TypeName' ]
        • $description (string): Description of the field. This will be used to self-document the schema and should describe to clients how the field should be used.
        • $resolve (function): Function that will execute when the field is asked for in a query.

    Source

    File: access-functions.php

    Examples

    Below are some examples of using the function to extend the GraphQL Schema.

    Register Root Fields

    This example adds multiple fields to the root of the GraphQL Schema.

    add_action( 'graphql_register_types', function() {
      register_graphql_fields( 'RootQuery', [
        'fieldOne' => [
          'type' => 'String',
          'description' => __( 'Example field added to the RootQuery Type', 'replace-with-your-textdomain' ),
          'resolve' => function( $root, $args, $context, $info ) {
            return 'Field one value...';
          }
        ],
        'fieldTwo' => [
          'type' => 'Boolean',
          'description' => __( 'Another example field added to the RootQuery Type', 'replace-with-your-textdomain' ),
          'resolve' => function( $root, $args, $context, $info ) {
            return 2;
          }
        ],
      ]);
    });

    Example Query:

    {
      fieldOne
      fieldTwo
    }
    Screenshot of the example query and results for fieldOne and fieldTwo
    Screenshot of the example query and results for fieldOne and fieldTwo

    Register Post Fields

    This example shows how to register fields to the “Post” type.

    add_action( 'graphql_register_types', function() {
    	register_graphql_fields( 'Post', [
    		'testFieldOne' => [
    			'type'        => 'String',
    			'description' => __( 'Example string field added to the Post Type', 'replace-with-your-textdomain' ),
    			'resolve'     => function( \WPGraphQL\Model\Post $post, $args, $context, $info ) {
    				return 'Example string with the title of the post: ' . $post->titleRendered;
    			}
    		],
    		'testFieldTwo' => [
    			'type'        => 'Boolean',
    			'description' => __( 'Example boolean field added to the Post Type', 'replace-with-your-textdomain' ),
    			'resolve'     => function() {
    				return false;
    			}
    		]
    	] );
    } );

    Example Query

    {
      posts(first: 1) {
        nodes {
          title
          testFieldOne
          testFieldTwo
        }
      }
    }
    Screenshot of example query for multiple test fields registered to the "Post" type
    Screenshot of example query for multiple test fields registered to the “Post” type
  • register_graphql_object_type

    Add an Object Type to the GraphQL Schema

    register_graphql_object_type( string $type_name, array $config );

    Parameters

    • $type_name (string): The name of the Type. This must be unique across all Types of any kind in the GraphQL Schema.
    • $config (array):
      • $description (string): Description of the Object Type. What does it represent? This will be used in Introspection for for self-documenting the Type in the Schema.
      • $fields (array): Associative array of key/value pairs. The key being the field name and the value being the field config.
        • $name (string): The name of the field
        • $config (array): Config for the field to add to the Type
          • $type: (string): The name of the GraphQL Type the field should return.
          • $description (string): Description of the field. What does the field represent? This will be used in Introspection to self-document the Schema.
          • $resolve (function): The function that will execute when the field is asked for in a query.

    Source

    File: access-functions.php

    Examples

    Below are some examples of using the function to extend the GraphQL Schema.

    Register a new Type with a single field

    This example shows how to register a new type called MyNewType which contains a String field.

    add_action( 'graphql_register_types', function() { 
    
      register_graphql_object_type( 'MyNewType', [
        'description' => __( 'Describe the Type and what it represents', 'replace-me' ),
        'fields' => [
          'testField' => [
            'type' => 'String', 
            'description' => __( 'Describe what this field should be used for', 'replace-me' ),
          ],
        ],
      ] );
    
    } );

    You can view this type in the documentation section of GraphiQL:

    Documentation for a single field object type called MyNewType

    Register a new type with multiple fields

    This example shows how to register a new type called MyMultifieldType which contains a String and an Int field.

    register_graphql_object_type( 'MyMultifieldType', [
    	'description' => __( 'Describe what MyMultifieldType is', 'replace-me' ),
    	'fields' => [
    		'testField' => [
    			'type' => 'String',
    			'description' => __( 'Describe what testField should be used for', 'replace-me' ),
    		],
    		'count' => [
    			'type' => 'Int',
    			'description' => __( 'Describe what the count field should be used for', 'replace-me' ),
    		],
    	],
    ] );

    You can view this type in the documentation section of GraphiQL:

    Documentation in GraphiQL for a new type called MyMultifieldType
  • register_graphql_input_type

    Given a Type Name and a $config array, this adds an InputType to the TypeRegistry

    register_graphql_input_type( string $type_name, array $config );

    Parameters

    • $type_name (string): The unique name of the InputType
    • $config (array): Configuration for the input type
      • $description (string): Description of the input type. This will be used to self-document the schema and should describe to clients how the input type should be used.
      • $fields (array): The fields that are part of the input type.
        • $type (string): The field type
        • $description (string): The field description

    Source

    File: access-functions.php

    Examples

    @todo

    Additional Resources

  • register_graphql_enum_type

    Given a Type Name and a $config array, this adds an EnumType to the TypeRegistry

    register_graphql_enum_type( string $type_name, array $config );

    Parameters

    • $type_name (string): The unique name of the EnumType
    • $config (array): Configuration for the EnumType
      • $description (string): Description of the enum type. This will be used to self-document the schema and should describe to clients how the enum type should be used.
      • $values (array): The possible values of the enum.

    Source

    File: access-functions.php

    Examples

    In GraphQL, Enum Types are used to provide a predefined set of values.

    An example of an Enum in WPGraphQL is the AvatarRatingEnum. Avatars in GraphQL can have a rating that is one of a predefined list of values: GPGR, and X. Since we know all the options before hand, we can expose fields to resolve to the AvatarRatingEnum type and ensure that it’s always one of those predefined values.

    Let’s say we wanted to be able to query for the current weather, and the responses should always be one of the following: SunnyCloudyRainy

    register_graphql_enum_type( 'WeatherEnum', [
    	'description' => __( 'Condition of weather', 'your-textdomain' ),
    	'values' => [
    		'SUNNY' => [
    			'value' => 'sunny'
    		],
    		'CLOUDY' => [
    			'value' => 'cloudy'
    		],
    		'RAINY' => [
    			'value' => 'rainy'
    		],
    	],
    ] );

    This would add an Enum to our Type registry, but it wouldn’t be in use yet. We could add a field that resolves to this Type:

    register_graphql_field( 'RootQuery', 'currentWeather', [
    	'type' => 'WeatherEnum',
    	'description' => __( 'Get the weather', 'your-textdomain' ),
    	'resolve' => function() {
    		// Here you could fetch data from a database, an external API, or whatever you like.
    		// In this case, we'll just return static data. It has to return one of the values
    		// defined by the enum to fulfill the contract of the Schema.
    		return 'rainy'; //sunny, cloudy
    	},
    ] );

    Now we could query:

    {
    	currentWeather
    }

    And get a response like:

    {
    	"data": {
    		"currentWeather": "RAINY"
    	}
    }
  • register_graphql_interface_type

    Given a Type Name and a $config array, this adds an Interface Type to the TypeRegistry

    register_graphql_interface_type( string $type_name, array $config );

    Parameters

    • $type_name (string): The unique name of the Interface Type
    • $config (array): Configuration for the field
      • $description (string): Description of the interface type.
      • $fields (array): The fields that are part of the interface type.
        • $type (string): The field type
        • $description (string): The field description
      • $resolveType (function): A function that takes the resolving data and determines what GraphQL Type should be returned

    Source

    File: access-functions.php

    Examples

    Below are some examples of using the function to add Interface types to the GraphQL Schema.

    Register a custom interface type

    This example adds an Interface Type called MyInterface to the GraphQL Schema with a test field called myTestField.

    register_graphql_interface_type( 'MyInterface', [
    	'fields' => [
    		'myTestField' => [
    			'type' => 'String',
    			'resolve' => function() {
    				return 'myTestField is working';
    			},
    		],
    	],
    ]);

    The above snippet registers the Interface to the Schema, but it’s not used anywhere, yet.

    Using the Interface

    In order to use this interface, it needs to be registered to an Object Type in the Schema.

    This can be done by registering a new object type that implements the interface, or by registering the interface to an existing object type.

    In this example, we use the register_graphql_interfaces_to_types function to apply the interface to the existing Post type.

    register_graphql_interfaces_to_types( ['MyInterface'], ['Post'] );

    You can now query the interface:

    {
      posts {
        nodes {
          myTestField
          id
        }
      }
    }

    And get results containing the value resolved for myTestField

    {
      "data": {
        "posts": {
          "nodes": [
            {
              "myTestField": "myTestField is working",
              "id": "cG9zdDo1"
            },
            {
              "myTestField": "myTestField is working",
              "id": "cG9zdDox"
            }
          ]
        }
      }
    }

    Here is how this looks inside GraphiQL:

    MyInterface GraphiQL Documentation
  • register_graphql_interfaces_to_types

    Given a type name and interface name, this applies the interface to the Type.

    register_graphql_interfaces_to_types( array $interface_names, array $type_names );

    Parameters

    • $interface_names (array): An array of interface names to register the types to
    • $type_names (array): An array of type names to register the interfaces to

    Source

    File: access-functions.php

    Examples

    First an interface needs to be registered. This example adds an Interface Type called ExampleInterface to the GraphQL Schema with a test field called exampleField.

    register_graphql_interface_type( 'ExampleInterface', [
    	'fields' => [
    		'exampleField' => [
    			'type' => 'String',
    			'resolve' => function() {
    				return 'This is an example';
    			},
    		],
    	],
    ]);

    Now the ExampleInterface can be registered to a GraphQL Type. In this example, it is registered to the User object.

    register_graphql_interfaces_to_types( ['ExampleInterface'], ['User'] );

    You can now write a query:

    {
      users {
        nodes {
          exampleField
        }
      }
    }

    Which will return results similar to the following:

    {
      "data": {
        "users": {
          "nodes": [
            {
              "exampleField": "This is an example"
            }
          ]
        }
      }
    }

    Here is how this looks inside GraphiQL:

    Register an interface inside GraphiQL
  • register_graphql_connection

    Given a config array for a connection, this registers a connection by creating all appropriate fields and types for the connection.

    register_graphql_connection( array $config );

    Parameters

    • $config (array): Configuration for the connection
      • $fromType (string): The name of the Type the connection is coming from
      • $toType (string): The name of the type the connection is going to
      • $fromFieldName (string): The name of the field on the from Type that should resolve to the connection
      • $connectionTypeName (string): The name of the Connection Type. If not provided, the Type name will be derived from the fromType and toType names
      • $resolve (function): The function that is used to resolve the connection
      • $connectionArgs (array): Array of GraphQL input fields that will be added to the connection’s “where” args
      • $connectionFields (array): Array of GraphQL fields to expose as a field of the connection

    Source

    File: access-functions.php

    Examples

    The use of register_graphql_connection( $config ) should be happen within the graphql_register_types action, as that’s when GraphQL builds the Schema. Since Connections require a fromType and toType, the connection must be registered after those types have been registered. A lower priority (such as 99) will allow for other Types to be registered before the connection references them.

    The below snippet will add a connection to the WPGraphQL Schema, and will use the built-in Post Object Connection Resolver, so it will return data, but it won’t be limited to “the last week” as the connection name implies.

    Register the connection

    In this example, we define the following:

    • fromType => ‘RootQuery’: This tells GraphQL the connection will be coming from the RootQuery, which means we can query this connection at the root of the graph. This from Type could be any existing Type, and that Type is where the connection can be entered when querying.
    • toType => ‘Post’: This tells GraphQL the connection will resolve to nodes of the Post type. This can be configured to any existing Type in the Schema, but you have to hold up your end of the contract and resolve the connection to the Type promised.
    • fromFieldName => ‘postsFromThisWeek’: This is the field name that is added to the “fromType”. In this case, the RootQuery type gets a field postsFromThisWeek added to it which resolves to the connection.
    • connectionTypeName => ‘PostsFromThisWeekConnection’: If this field is blank, the connection name would be derived from the fromType and toType. In this case, there’s already a RootQueryToPostConnection in the Schema, which we could resolve to, but it’s probably safer to resolve to our own Connection Type so we could customize in a more isolated way down the road. You will now see (by browsing GraphiQL or similar) that our Schema includes a PostsFromThisWeekConnection Type
    • resolve: This is set to a function, like all resolve fields in the Schema. This function is what is executed when the connection is queried. In our case, we return the results of WPGraphQLDataDataSource::resolve_post_objects_connection. (we’ll look at customizing the resolver below).
    add_action( 'graphql_register_types', 'register_my_custom_graphql_connection', 99 );
    
    function register_my_custom_graphql_connection() {
      $config = [
        'fromType' => 'RootQuery',
        'toType' => 'Post',
        'fromFieldName' => 'postsFromThisWeek',
        'connectionTypeName' => 'PostsFromThisWeekConnection',
        'resolve' => function( $id, $args, $context, $info ) {
          $resolver   = new \WPGraphQL\Data\Connection\PostObjectConnectionResolver( $source, $args, $context, $info, $post_type );
          $connection = $resolver->get_connection();
    
          return $connection;
        },
      ];
      register_graphql_connection( $config );
    };

    Query the connection

    Now that we have a connection registered to our Schema, we can query the following:

    {
    	postsFromThisWeek(first: 3) {
    		nodes {
    			id
    			title
    			date
    			link
    		}
    	}
    }

    Connection Query Results

    And get a result like so (of course, the data is relative to the content in your database):

    {
    	"data": {
    		"postsFromThisWeek": {
    			"nodes": [
    				{
    					"id": "cG9zdDoxMzYz",
    					"title": "New Post From This Week",
    					"date": "2019-04-04 19:24:22",
    					"link": "https://demowpgraphql.local/new-post/"
    				},
    				{
    					"id": "cG9zdDox",
    					"title": "Hello world!",
    					"date": "2019-01-28 23:50:02",
    					"link": "https://demowpgraphql.local/hello-world/"
    				},
    				{
    					"id": "cG9zdDoxMDMx",
    					"title": "Tiled Gallery",
    					"date": "2013-03-15 17:23:27",
    					"link": "https://demowpgraphql.local/tiled-gallery/"
    				}
    			]
    		}
    	}
    }

    The problem with this is that we want to limit our connection to just posts from this week, because the connection is called postsFromThisWeek.

    So, let’s look at overriding the connection resolver.

    Custom Connection Resolvers

    The resolver for the connection above instantiates a new instance of PostObjectConnectionResolver, and asks for the get_connection in response.

    We want to modify the args of the underlying WP_Query to limit posts to the last 7 days.

    We can do so by using the set_query_arg method on the $resolver, like so:

    'resolve' => function( $id, $args, $context, $info ) {
        $resolver   = new WPGraphQLDataConnectionPostObjectConnectionResolver( $id, $args, $context, $info, 'post' );
        $resolver->set_query_arg( 'date_query', [
            'after' => '1 week ago',
        ] );
        $connection = $resolver->get_connection();
        return $connection;
    }

    Using set_query_arg pass an argument to the underlying WP_Query, with a custom date_query query arg, limiting posts to just the last week.

    Now, we can execute the same query:

    {
    	postsFromThisWeek(first: 3) {
    		nodes {
    			id
    			title
    			date
    			link
    		}
    	}
    }

    And we get results limited to the last 7 days!

    {
    	"data": {
    		"postsFromThisWeek": {
    			"nodes": [
    				{
    					"id": "cG9zdDoxMzYz",
    					"title": "New Post From This Week",
    					"date": "2019-04-04 19:24:22",
    					"link": "https://demowpgraphql.local/new-post/"
    				}
    			]
    		}
    	}
    }