WPGraphQL Fundamentals

One endpoint, one typed schema, and a response in the shape of your query: how WPGraphQL turns WordPress into a GraphQL API.

4 lessons16 interview questions

[video:g01-wpgraphql-what-is-it-shorts.mp4]

One endpoint. One typed schema. A response in the shape of your query. WPGraphQL turns posts, pages, users, terms and media into a schema you can read as documentation. In this module you will learn to read it, go from a post to its author and categories in a single query, and understand when GraphQL is really better than REST.

CourseWPGraphQL Course ยท Module 1 of 5 ยท Stage 1 "Ask"
Learn/graphql, types and fields, edges and connections, node(id) and global IDs, GraphQL vs REST
HowA GraphQL terminal in every lesson, real GraphQL errors, interview questions

Query. Validate. Resolve. Respond.

flowchart LR
  Q["Query<br/>fields you need"] --> E["/graphql<br/>one endpoint"]
  E --> V{"Validate<br/>against schema"}
  V -- "unknown field" --> ERR["error<br/>nothing runs"]
  V -- "ok" --> R["Resolve<br/>loaders batch by ID"]
  R --> J["JSON<br/>same shape"]
  classDef ok fill:#e8f6f0,stroke:#49cc90,color:#1e293b
  classDef err fill:#fdecec,stroke:#f93e3e,color:#1e293b
  class J ok
  class ERR err

Before โ†’ after

BeforeAfter Module 1
"GraphQL is just another REST"one endpoint, a schema instead of a list of routes
Searching for the plugin's docsopening Docs and reading the types
Post, author, categories โ€” three requestsone query, one response
id is the post IDid is a global ID, databaseId is the WordPress ID
GraphQL "because it's trendy"choosing GraphQL or REST by the shape of the page

You'll be able to answer

  • How do id and databaseId differ in WPGraphQL?
  • What happens to a query for a field that isn't in the schema?
  • When is REST a better choice than GraphQL for a headless project?

Lessons in this module 4 lessons