Sometimes it can be helpful to deprecate a field in the Schema without removing it altogether. This snippet shows how to deprecate the `Post.excerpt` field. You can use this technique to deprecate other fields. After using this snippet, we can verify in the WPGraphQL Schema Docs that the field is indeed deprecated:
Tag Archives:
Register a basic Mutation
This snippet shows how to register a basic GraphQL Mutation with a single input field, a single output field, and the input is simply returned as the value for the output.
Add Edit Link to All Post Types
The following snippet shows how to add the “Edit” link as a GraphQL field to all post types: This could then be queried like so:
Add field to output URLs for Sitemap
The following code is an example of how you can create a field called allUrls that will output site URLs that could be used to generate a sitemap. The resolver uses mostly hard-coded data, but shows what a potential solution could look like. You can then query this field using:
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 …
Register field as a list of strings
The below code registers a field called listOfStrings that returns a list of strings as the result: This field can now be queried:
Register object and field for custom list of users
The following code creates an object type called StuntPerformer and creates a field on the RootQuery called stuntPerformers that returns a custom list of users. In this case, the list of users are the admins of the website, but custom logic could be added to return a curated list of users. You can now query …
Continue reading “Register object and field for custom list of users”
List of Key Values
This is an example showing how to return a list of keys and values where the keys and values are both strings.
Add Primary Category field for The SEO Framework plugin
The following adds a field called primaryCat field when using The SEO Framework WordPress Plugin
Add field for unencoded content
The following adds a field to the NodeWithContentEditor interface to get the unencoded content for a post: You can query now query for this field: Related Links Github issue: https://github.com/wp-graphql/wp-graphql/issues/1035#issuecomment-691232395