Homepage
Link to WPGraphQL on Github
Link to WPGraphQL on WordPress.org

Register GraphQL Field with Argument

This is an example of registering a field with an argument showing how to use the argument in a resolver.

This will register a new field (myNewField ) to the RootQuery, and adds an argument to the field (myArg). The resolve function checks to see if that arg is set, and if so, it returns the value, if not it returns test.

We can query this like so:

And the results will be:

Now, we can pass a value to the argument like so:

and the results will be:

Now, you can introduce variables like so:

And then you can pass variables to the request. Here’s an example of using a variable in GraphiQL:

Custom field with an argument and variable in GraphiQL