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:
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.
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:
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:
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 below code registers a field called listOfStrings that returns a list of strings as the result: This field can now be queried:
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 …
This is an example showing how to return a list of keys and values where the keys and values are both strings.
The following adds a field called primaryCat field when using The SEO Framework WordPress Plugin
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