Introduction to GraphQL Language Schemas and Queries
GraphQL is a query language. It exposes a typed schema to run queries against. The massive benefit of GraphQL is that the client requests what information it needs. This is a direct effect of having a typed schema.
We will add GraphQL to our BFF using
express-graphql, which is compatible with micro. We need to provide our GraphQL endpoint with a schema and resolvers so that it can respond to client requests. Such a server is provided in the Exercise 12 start file (change the working directory to
npm install followed by
npm run Exercise81, and navigate to
http://localhost:3000 to see it in action).
A sample GraphQL query that returns a basket can work within the following GraphQL schema definition. Note how we have three types, that is,
basket contains a list of
basketItems under an
items property. The
query contains the top-level GraphQL query fields, which in this case is just...