[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.
| Course | WPGraphQL Course ยท Module 1 of 5 ยท Stage 1 "Ask" |
| Learn | /graphql, types and fields, edges and connections, node(id) and global IDs, GraphQL vs REST |
| How | A 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
| Before | After Module 1 |
|---|---|
| "GraphQL is just another REST" | one endpoint, a schema instead of a list of routes |
| Searching for the plugin's docs | opening Docs and reading the types |
| Post, author, categories โ three requests | one query, one response |
id is the post ID | id 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
idanddatabaseIddiffer 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?